我正在使用核心音频在一个频道播放音调。当我使用耳机在iPhone上进行测试时,您可以听到非常低的声音,也可能听错了。所以假设我在mBuffers [0](LEFT)上播放,当我在这个频道中放置0.0时,你仍会听到mBuffers [1](右)的音调非常低。
以下是我的代码的样子:
// configuring the unit
AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = SAMPLE_RATE;
streamFormat.mFormatID = kAudioFormatLinearPCM;
kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked;
streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerPacket = FOUR_BYTES_PER_FLOAT;
streamFormat.mBytesPerFrame = FOUR_BYTES_PER_FLOAT;
streamFormat.mChannelsPerFrame = 2;
streamFormat.mBitsPerChannel = FOUR_BYTES_PER_FLOAT * EIGHT_BITS_PER_BYTE;
err = AudioUnitSetProperty (_outputUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&streamFormat,
sizeof(AudioStreamBasicDescription));
//这是渲染回调 ToneGen toneGen =(__bridge ToneGen )inRefCon;
// first clean the buffers
for (int iBuffer=0; iBuffer < ioData->mNumberBuffers; ++iBuffer) {
memset(ioData->mBuffers[iBuffer].mData, 0, ioData->mBuffers[iBuffer].mDataByteSize);
}
for (int frame = 0; frame < inNumberFrames; frame++) {
Float32 *dataLeft = (Float32*)ioData->mBuffers[0].mData;
Float32 *dataRight = (Float32*)ioData->mBuffers[1].mData;
Float32 leftFrame = (Float32)[toneGen renderNextFrameLeft:YES];
Float32 rightFrame = 0.0;
dataLeft[frame] = leftFrame;
dataRight[frame] = rightFrame;
}
return noErr;
它在两个频道播放的原因是什么?任何方向都会有所帮助