diff options
Diffstat (limited to 'record.c')
| -rw-r--r-- | record.c | 96 |
1 files changed, 49 insertions, 47 deletions
@@ -27,7 +27,8 @@ static int recordCallback( const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, - void *userData ){ + void *userData ){ + paTestData *data = (paTestData*)userData; const SAMPLE *rptr = (const SAMPLE*)inputBuffer; SAMPLE *wptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; @@ -35,7 +36,7 @@ static int recordCallback( const void *inputBuffer, void *outputBuffer, long i; int finished; unsigned long framesLeft = data->maxFrameIndex - data->frameIndex; - + (void) outputBuffer; /* Prevent unused variable warnings. */ (void) timeInfo; (void) statusFlags; @@ -71,52 +72,53 @@ static int recordCallback( const void *inputBuffer, void *outputBuffer, data->frameIndex += framesToCalc; return finished; } + static int playCallback( const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ) - { - paTestData *data = (paTestData*)userData; - SAMPLE *rptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; - SAMPLE *wptr = (SAMPLE*)outputBuffer; - unsigned int i; - int finished; - unsigned int framesLeft = data->maxFrameIndex - data->frameIndex; - - (void) inputBuffer; /* Prevent unused variable warnings. */ - (void) timeInfo; - (void) statusFlags; - (void) userData; - - if( framesLeft < framesPerBuffer ) - { - /* final buffer... */ - for( i=0; i<framesLeft; i++ ) - { - *wptr++ = *rptr++; /* left */ - if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ - } - for( ; i<framesPerBuffer; i++ ) - { - *wptr++ = 0; /* left */ - if( NUM_CHANNELS == 2 ) *wptr++ = 0; /* right */ - } - data->frameIndex += framesLeft; - finished = paComplete; - } - else - { - for( i=0; i<framesPerBuffer; i++ ) - { - *wptr++ = *rptr++; /* left */ - if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ - } - data->frameIndex += framesPerBuffer; - finished = paContinue; - } - return finished; - } + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; + SAMPLE *wptr = (SAMPLE*)outputBuffer; + unsigned int i; + int finished; + unsigned int framesLeft = data->maxFrameIndex - data->frameIndex; + + (void) inputBuffer; /* Prevent unused variable warnings. */ + (void) timeInfo; + (void) statusFlags; + (void) userData; + + if( framesLeft < framesPerBuffer ) + { + /* final buffer... */ + for( i=0; i<framesLeft; i++ ) + { + *wptr++ = *rptr++; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ + } + for( ; i<framesPerBuffer; i++ ) + { + *wptr++ = 0; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = 0; /* right */ + } + data->frameIndex += framesLeft; + finished = paComplete; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *wptr++ = *rptr++; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ + } + data->frameIndex += framesPerBuffer; + finished = paContinue; + } + return finished; +} int record(int NUM_SECONDS){ PaStream* stream; |
