核心音频:使用渲染回调传递的奇怪问题
我正在使用 RemoteIO 音频单元实现音频直通,方法是将渲染回调附加到输出总线的输入范围(即扬声器)。
一切都很顺利,......
OSStatus RenderTone(
void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData)
{
SoundEngine * soundEngine = (SoundEngine *) inRefCon;
// grab data from the MIC (ie fill up ioData)
AudioUnit thisUnit = soundEngine->remoteIOUnit->audioUnit;
OSStatus err = AudioUnitRender(thisUnit,
ioActionFlags,
inTimeStamp,
1,
inNumberFrames,
ioData);
if (result)
{
printf("Error pulling mic data");
}
assert(ioData->mNumberBuffers > 0);
// only need the first buffer
const int channel = 0;
Float32 * buff = (Float32 *) ioData->mBuffers[channel].mData;
}
直到我添加最后一行。
Float32 * buff = (Float32 *) ioData->mBuffers[channel].mData;
这条线就位后,没有错误,只是沉默。如果没有它,我可以在麦克风前点击手指并在耳机中听到它。
编辑: AudioBuffer buf0 = ioData->mBuffers[0]; // 足以导致失败
发生了什么?
这不是由编译器优化未使用的变量引起的错误。如果我设置 buff++;在下一行,行为是相同的。尽管编译器可能仍然可以检测到该变量实际上未被使用。
I am implementing an audio passthrough using the RemoteIO audio unit, by attaching a render callback to the input scope of the output bus (ie the speakers).
Everything works swimmingly, ...
OSStatus RenderTone(
void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData)
{
SoundEngine * soundEngine = (SoundEngine *) inRefCon;
// grab data from the MIC (ie fill up ioData)
AudioUnit thisUnit = soundEngine->remoteIOUnit->audioUnit;
OSStatus err = AudioUnitRender(thisUnit,
ioActionFlags,
inTimeStamp,
1,
inNumberFrames,
ioData);
if (result)
{
printf("Error pulling mic data");
}
assert(ioData->mNumberBuffers > 0);
// only need the first buffer
const int channel = 0;
Float32 * buff = (Float32 *) ioData->mBuffers[channel].mData;
}
until I add that last line.
Float32 * buff = (Float32 *) ioData->mBuffers[channel].mData;
With this line in place, no errors, simply silence. Without it, I can click my fingers in front of the microphone and hear it in my headset.
EDIT:
AudioBuffer buf0 = ioData->mBuffers[0]; // Is sufficient to cause failure
What is going on?
It is not an error caused by the compiler optimising out an unused variable. If I set buff++; on the next line, behaviour is the same. although maybe the compiler can still detect the variable is effectively unused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是第一次触发此回调时,从麦克风请求数据失败。
我应该做的是检查返回值,如果不成功则返回它(即退出回调)
可能发生的情况是我正在访问无效数据
这仍然很奇怪,但无需深入探讨它。
Problem was the request for data from the microphone was failing the very first time this callback fires.
And what I should have been doing was examining the return value, and returning it (ie quitting the callback) if it was not success
What was probably happening was that I was accessing invalid data
It is still rather bizarre, but no need to go into it.