开发者

Modifying aurioTouch to save recording as wav or caf file

I'm looking to modify aurioTouch to save the recording coming through the microphone to a file format that can be played back by the iphone later, using AVAudioPlayer. But I'm a bit lost on how to create this file using the PCM data coming 开发者_Python百科from the data buffers. For example in the PerformThru, I'm also saving to a save buffer:

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;
    }

later I write the saveBuffer to a file

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

It's definitely coming out wrong (not playing). Does anyone know how to capture PCM and save to a file properly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜