I need to create a slider that will adjust the gain of the current input 
device. I’ve been studying Core Audio for clues or sample code on how to do 
this, but haven’t found anything. I suspect I may need to create a mixer, but 
am not sure (I’ve gotten about halfway through "Learning Core Audio”  and that 
reading so far, leads me to that conclusion). Here is some code that I’ve been 
using to adjust the gain to a given level. If I want to set the gain to say, 
75, the code works just fine to do that.  I then wired it up to a slider to see 
if it would work to continuously update the gain level as the slider knob is 
moved, but what actually happens is that the gain is adjusted to 100 on the 
first movement of the slider, and remains there until the slider is moved to 
zero, at which point, the sound is muted. So here is the code, any help is most 
appreciated.

 AudioObjectPropertyAddress      address;
        AudioDeviceID                   deviceID;
        OSStatus                        err;
        UInt32                          size;
        UInt32                          channels[ 2 ];
        Float32                         level;
        
        SSAudioDevice * targetDevice = [self getTargetInputDevice];
        
       
        address.mSelector = kAudioHardwarePropertyDefaultInputDevice;
        address.mScope = kAudioObjectPropertyScopeGlobal;
        address.mElement = kAudioObjectPropertyElementMaster;
        deviceID = targetDevice.deviceID;
        
        
        if(!targetDevice.ioLevel){
                level = 0.5;
        }
        else{
                level = targetDevice.ioLevel.floatValue / 100.0;
        }
        
        
        size = sizeof(deviceID);
        err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &address, 
0, nil, &size, &deviceID );
        
       
        if ( ! err ) {
                address.mSelector = 
kAudioDevicePropertyPreferredChannelsForStereo;
                address.mScope = kAudioDevicePropertyScopeInput;
                address.mElement = kAudioObjectPropertyElementWildcard;
                size = sizeof(channels);
                err = AudioObjectGetPropertyData( deviceID, &address, 0, nil, 
&size, &channels );
        }
        
      
        if ( ! err ) {
                Boolean hasProperty;
                
                address.mSelector = kAudioDevicePropertyVolumeScalar;
                address.mScope = kAudioDevicePropertyScopeInput;
                
               
                
                address.mElement = kAudioObjectPropertyElementMaster;
              
                hasProperty = AudioObjectHasProperty( deviceID, &address );
                if(!hasProperty){
                        
                }
                address.mElement = channels[ 0 ];
              
                hasProperty = AudioObjectHasProperty( deviceID, &address );
                if(!hasProperty){
                        
                }
                address.mElement = channels[ 1 ];
                
                hasProperty = AudioObjectHasProperty( deviceID, &address );
                if(!hasProperty){
                        
                }
                
        }
        
       
        if ( ! err ) {
                address.mSelector = kAudioDevicePropertyVolumeScalar;
                address.mScope = kAudioDevicePropertyScopeInput;
                
                size = sizeof(level);
                
                
                address.mElement = kAudioObjectPropertyElementMaster;
               
                err = AudioObjectSetPropertyData( deviceID, &address, 0, nil, 
size, &level );
                
                if(err){
                        address.mElement = channels[ 0 ];
                      
                        err = AudioObjectSetPropertyData( deviceID, &address, 
0, nil, size, &level );
                        
                        address.mElement = channels[ 1 ];
                       
                        err = AudioObjectSetPropertyData( deviceID, &address, 
0, nil, size, &level );
                }
        }


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to