Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获得音频单元的音量_Ios_Volume_Audiounit - Fatal编程技术网

Ios 如何获得音频单元的音量

Ios 如何获得音频单元的音量,ios,volume,audiounit,Ios,Volume,Audiounit,我正在使用AudioUnit播放从麦克风到耳机的输入。 它工作得很好。现在我需要增加弱声音的音量,减少强声音的音量 我找到了一种增加声音的方法: static OSStatus performRender (void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const A

我正在使用AudioUnit播放从麦克风到耳机的输入。 它工作得很好。现在我需要增加弱声音的音量,减少强声音的音量

我找到了一种增加声音的方法:

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;
}

我的问题是如何得到当前的数量,这样我就知道要获得多少,反之亦然


谢谢

获取音量取决于音频单元的类型。某些音频单元具有输入电平、输出电平和全局音量电平

// 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);

你是说像这样吗?不这是总卷。我说的是具体的缓冲容量。例如,如果我在安静地说话或大声喊叫。看看Nope。。。我还需要它,你找到了吗?