0

I am using AudioUnit to play input from the microphone to the earphones. It's working great. Now I need to increase the volume of weak sounds and decrease strong ones.

I found a way to increase the sound:

static OSStatus performRender (void                         *inRefCon,
                           AudioUnitRenderActionFlags   *ioActionFlags,
                           const AudioTimeStamp         *inTimeStamp,
                           UInt32                       inBusNumber,
                           UInt32                       inNumberFrames,
                           AudioBufferList              *ioData)

{
OSStatus err = noErr;
if (*cd.audioChainIsBeingReconstructed == NO)
{
    // we are calling AudioUnitRender on the input bus of AURemoteIO
    // this will store the audio data captured by the microphone in ioData
    err = AudioUnitRender(cd.rioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);

    // filter out the DC component of the signal
    cd.dcRejectionFilter->ProcessInplace((Float32*) ioData->mBuffers[0].mData, inNumberFrames);

    //Add Volume
    float desiredGain = 2.0f;
    for(UInt32 bufferIndex = 0; bufferIndex < ioData->mNumberBuffers; ++bufferIndex) {
        float *rawBuffer = (float *)ioData->mBuffers[bufferIndex].mData;
        vDSP_vsmul(rawBuffer, 1, &desiredGain, rawBuffer, 1, inNumberFrames);
    }


    // mute audio if needed
    if (*cd.muteAudio)
    {
        for (UInt32 i=0; i<ioData->mNumberBuffers; ++i)
            memset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);
    }
}

return err;

}

My question is how to I get what is the current volume so I would know how much to gain it and vice versa

Thanks!

Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
roiberg
  • 13,629
  • 12
  • 60
  • 91

1 Answers1

0

Getting the "volume" depends on the type of AudioUnit. Some audio units have input levels, output levels, and "global" volume levels.

// MatrixMixer
Float32 volume = 0;
OSStatus result = AudioUnitGetParameter(mxmx_unit, kMatrixMixerParam_Volume, kAudioUnitScope_Global, 0, &volume);

// MultiChannelMixer
Float32 volume = 0;
OSStatus result = AudioUnitGetParameter(mcmx_unit, kMultiChannelMixerParam_Volume, kAudioUnitScope_Global, 0, &volume);
Matt H
  • 6,422
  • 2
  • 28
  • 32