As an exercise, I am trying to change aurioTouch so that it saves the first 60 seconds of PCM that came in through the microphone. I avoid higher level libs because I want to create some low latency processing in real time. I did this by simply creating a large saveBuffer file, and then simply adding the data_ptr [2] value stored in drawBuffers [] for each of the “inNumberFrames” for each PerformThru call ... Then, after 60 seconds, I flush the buffer to disk one shot.
I tried this code, giving a single click. The problem is that when I visualize saveBuffer data in gnuplot, I get peaks in uneven time, 30-40% of steady click, which means that some peaks are close to each other and others are far from each other. I see that the input press .wav and that it is very, but the saveBuffer graph has strange peaks. This makes me wonder if I am saving pcm data correctly? Perhaps I somehow linger and lose data as a result?
Changes to PerformThru () I have:
{// buffer allocation static int * saveBuffer = (int *) malloc (10000000 * sizeof (int)); ,,.
SInt8 *data_ptr = (SInt8 *)(ioData->mBuffers[0].mData);
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;
}
if ( saveBuffer && ( CAHostTimeBase::HostDeltaToNanos( initialHostTime, inTimeStamp->mHostTime ) / 1000000000 ) > 60 )
{
std::ofstream bufferOut;
bufferOut.open( "pcmBuffer.txt" );
for ( UInt64 i = 0; i < saveBufferIdx; i++ )
{
bufferOut << saveBuffer[ i ] << std::endl;
}
bufferOut.close();
free( saveBuffer );
saveBuffer = 0;
}
drawBufferIdx += inNumberFrames;
}
source
share