我已经根据苹果的aurio Touch编写了呼吸检测器
示例应用程序。但是我不知道如何设置音频单元或音频
session 不播放来自音频输入的声音。现在,当吹入麦克风时,
我可以从iPhone扬声器听到呼吸。如何预防呢?
这是苹果的音频 session 初始化代码:
XThrowIfError(AudioSessionInitialize(NULL, NULL, rioInterruptionListener, self), "couldn't initialize audio session");
XThrowIfError(AudioSessionSetActive(true), "couldn't set audio session active\n");
UInt32 audioCategory = kAudioSessionCategory_RecordAudio;
XThrowIfError(AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory), "couldn't set audio category");
XThrowIfError(AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self), "couldn't set property listener");
Float32 preferredBufferSize = .005;
XThrowIfError(AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize), "couldn't set i/o buffer duration");
UInt32 size = sizeof(hwSampleRate);
XThrowIfError(AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &size, &hwSampleRate), "couldn't get hw sample rate");
XThrowIfError(SetupRemoteIO(rioUnit, inputProc, thruFormat), "couldn't setup remote i/o unit");
dcFilter = new DCRejectionFilter[thruFormat.NumberChannels()];
UInt32 maxFPS;
size = sizeof(maxFPS);
XThrowIfError(AudioUnitGetProperty(rioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFPS, &size), "couldn't get the remote I/O unit's max frames per slice");
fftBufferManager = new FFTBufferManager(maxFPS);
l_fftData = new int32_t[maxFPS/2];
XThrowIfError(AudioOutputUnitStart(rioUnit), "couldn't start remote i/o unit");
size = sizeof(thruFormat);
XThrowIfError(AudioUnitGetProperty(rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &thruFormat, &size), "couldn't get the remote I/O unit's output client format");
最佳答案
非常感谢Tim Bolstad
他的回答:
AURIOTouch使用单个回调将音频从输入传递到输出。所以最简单的事情是零
进行呼吸检测后,请清除ioData结构。
就像是:
for (UInt32 i=0; i < inData->mNumberBuffers; i++)
memset(inData->mBuffers[i].mData, 0, inData->mBuffers[i].mDataByteSize);
或者,您可以看一下CAPlayThrough示例,该示例具有用于输入和输出的单独回调。
关于iphone - 如何在Apple Aurio Touch( Audio Session 示例)应用程序中使输出静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4177685/