1

使用 iphone 上的回调函数,我正在尝试获取麦克风输入信号。经过这么多问题,我发现了这一点:当我向缓冲区输入一个纯正弦波(到 mac 模拟器)时,我可以看到信号,但随后,它变得越来越低,直到零。

我在想这与苹果的错误有关,mac上缓冲区的样本数是 471 而不是 1024 。我能以某种方式解决这个错误吗???

这是我的回调:

static OSStatus recordingCallback(void *inRefCon,
                                  AudioUnitRenderActionFlags *ioActionFlags,
                                  const AudioTimeStamp *inTimeStamp,
                                  UInt32 inBusNumber,
                                  UInt32 inNumberFrames,
                                  AudioBufferList *ioData)
{


    AudioBuffer buffer;
    buffer.mNumberChannels = 1;
    buffer.mDataByteSize = inNumberFrames * 2; //* sizeof(SInt16) ?
    buffer.mData = NULL; 

    AudioBufferList bufferList;
    bufferList.mNumberBuffers = 1;
    bufferList.mBuffers[0] = buffer;
    OSStatus status;
    status = AudioUnitRender(audioUnit,
                             ioActionFlags,
                             inTimeStamp,
                             inBusNumber,
                             inNumberFrames,
                             &bufferList);


    int16_t *q = (int16_t *)(&bufferList)->mBuffers[0].mData;


    //here i print q,which is good for 4 seconds-when i can see the pure sin, than it goes down to zero-while sin wave is still in the air

编辑:

这不会在设备上发生,仅在 mac 上发生!我很确定它与mac在缓冲区中看到417个样本的错误有关!

4

0 回答 0