【发布时间】:2012-04-20 07:32:37
【问题描述】:
我有一个应用程序,允许用户使用音频单元记录节拍。为了实现这一点,我从 Apple 的 MixerHost 示例代码中修改了 Mixer 类。
目前我的声音文件循环播放,我想停止它。我希望用户能够在声音文件通过后保存混音。
循环的原因是inputrendercallback函数的以下部分的最后一行中的for loop:
for (UInt32 frameNumber = 0; frameNumber < inNumberFrames; ++frameNumber) {
outSamplesChannelLeft[frameNumber] = dataInLeft[sampleNumber];
if (isStereo) outSamplesChannelRight[frameNumber] = dataInRight[sampleNumber];
sampleNumber++;
// After reaching the end of the sound stored in memory--that is, after
// (frameTotalForSound / inNumberFrames) invocations of this callback--loop back to the
// start of the sound so playback resumes from there.
if (sampleNumber >= frameTotalForSound) sampleNumber = 0;
}
我意识到我需要更改 if (sampleNumber >= frameTotalForSound) sampleNumber = 0; 以便在样本用完后告诉回调停止请求样本,但我会更舒服地调用目标 C 中的方法而不是操纵这个 C-结构。
有人对如何做到这一点有任何想法吗?
谢谢。
【问题讨论】:
标签: iphone c core-audio