1

I am developing a karaoke software.and intend to mix the audio by using audiounit,but I don't know how to set the scope and element?for example:

UInt32 busCount = 2;
OSStatus result = AudioUnitSetProperty (
    mixerUnit,
    kAudioUnitProperty_ElementCount
    kAudioUnitScope_Input,
    0,
    &busCount,
    sizeof (busCount
);

why the scope is 'kAudioUnitScope_Input' and element is '0',what's the meaning of this?

Tan
  • 179
  • 3
  • 16

2 Answers2

6

This illustration from Apple Docs make it pretty clear:

A scope is a programmatic context within an audio unit. Although the name global scope might suggest otherwise, these contexts are never nested. You specify the scope you are targeting by using a constant from the Audio Unit Scopes enumeration.

The 0 refers to "output bus".

An element is a programmatic context nested within an audio unit scope. When an element is part of an input or output scope, it is analogous to a signal bus in a physical audio device—and for that reason is sometimes called a bus. These two terms—element and bus—refer to exactly the same thing in audio unit programming. This document uses “bus” when emphasizing signal flow and uses “element” when emphasizing a specific functional aspect of an audio unit, such the input and output elements of an I/O unit (see “Essential Characteristics of I/O Units”).

It's best to use defines to give the bus values semantics:

// put this in header file
#define kOutputBus 0
#define kInputBus 1
maroux
  • 3,764
  • 3
  • 23
  • 32
1

The AudioUnitSetProperty is defined as

OSStatus AudioUnitSetProperty (
   AudioUnit            inUnit,
   AudioUnitPropertyID  inID,
   AudioUnitScope       inScope,
   AudioUnitElement     inElement,
   const void           *inData,
   UInt32               inDataSize
);

where the 0, in your code, correspond to the AudioUnitElement and the kAudioUnitScope_Input is your defined AudioUnitScope, which is explained as

Scope - the programmatic context, within an audio unit, that the property applies to. A property applies to one or more scopes, as described in this document. The audio unit scopes in iOS are Input, Output, and Global. In OS X, audio units have additional, MIDI-related scopes: Group, Part, and Note.

Take a look at the documentation of AudioUnitSetProperty as well as Audio Unit Properties Reference

Groot
  • 13,943
  • 6
  • 61
  • 72