修改aurioTouch以将录制内容保存为wav或caf文件

时间:2011-08-13 04:59:52

标签: audio core-audio avaudioplayer

我正在寻找修改aurioTouch以将通过麦克风录制的录音保存为以后可以使用AVAudioPlayer播放的文件格式。但我对如何使用来自数据缓冲区的PCM数据创建此文件感到有点迷茫。例如,在PerformThru中,我也保存到保存缓冲区:

SInt8 *data_ptr = (SInt8 *)(ioData->mBuffers[0].mData);
NSString * s = [NSString stringWithFormat:@"%d", data_ptr[2]];
    for (i=0; i<inNumberFrames; i++)
    {
        if ((i+drawBufferIdx) >= drawBufferLen)
        {
            //cycleOscilloscopeLines();
            drawBufferIdx = -i;
        }
        drawBuffers[0][i + drawBufferIdx] = data_ptr[2];

        if ( saveBuffer ) { saveBuffer[ saveBufferIdx++ ] = ( data_ptr[ 2 ] ); }
        data_ptr += 4;
    }

稍后我将saveBuffer写入文件

std::ofstream bufferOut;
bufferOut.open( "myaudio.wav" );
for ( UInt64 i = 0; i < saveBufferIdx; i++ )
{
    bufferOut << saveBuffer[ i ];
}
bufferOut.close();
free( saveBuffer );

这肯定是错误的(不玩)。有谁知道如何捕获PCM并正确保存到文件中?

0 个答案:

没有答案