fixed some warnings and minor bugs in patest_suggested_vs_streaminfo_latency.c

This commit is contained in:
rossb 2011-08-25 14:40:00 +00:00
commit 59b9cf7180

View file

@ -48,11 +48,12 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "portaudio.h"
#define SAMPLE_RATE (44100)
#define FRAMES_PER_BUFFER (128)
#define FRAMES_PER_BUFFER 2//(128)
#define NUM_CHANNELS (2)
#define SUGGESTED_LATENCY_START_SECONDS (0.0)
@ -67,6 +68,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
PaStreamCallbackFlags statusFlags,
void *userData )
{
return paContinue;
}
/*******************************************************************/
@ -97,12 +99,12 @@ static void usage()
int main( int argc, const char* argv[] );
int main( int argc, const char* argv[] )
{
PaStreamParameters outputParameters, inputParameters;
PaStreamParameters inputParameters, outputParameters;
PaStream *stream;
PaError err;
PaTime suggestedLatency;
PaStreamInfo *streamInfo;
PaDeviceInfo *deviceInfo;
const PaStreamInfo *streamInfo;
const PaDeviceInfo *deviceInfo;
float sampleRate = SAMPLE_RATE;
int framesPerBuffer = FRAMES_PER_BUFFER;
err = Pa_Initialize();
@ -121,9 +123,38 @@ int main( int argc, const char* argv[] )
printf("# sample rate=%f, frames per buffer=%d\n", (float)sampleRate, framesPerBuffer );
outputParameters.device = -1;
inputParameters.device = -1;
if( argc > 1 )
outputParameters.device = atoi(argv[1]);
inputParameters.device = atoi(argv[1]);
if( inputParameters.device == -1 ){
inputParameters.device = Pa_GetDefaultInputDevice();
if (inputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default input device available.\n");
goto error;
}
}else{
deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
if( !deviceInfo ){
fprintf(stderr,"Error: Invalid input device index.\n");
usage();
}
if( deviceInfo->maxInputChannels == 0 ){
fprintf(stderr,"Error: Specified input device has no input channels (an output only device?).\n");
usage();
}
}
inputParameters.channelCount = NUM_CHANNELS;
inputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
inputParameters.hostApiSpecificStreamInfo = NULL;
deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
printf( "# using input device id %d (%s, %s)\n", inputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );
outputParameters.device = -1;
if( argc > 2 )
outputParameters.device = atoi(argv[2]);
if( outputParameters.device == -1 ){
outputParameters.device = Pa_GetDefaultOutputDevice();
if (outputParameters.device == paNoDevice) {
@ -150,37 +181,7 @@ int main( int argc, const char* argv[] )
printf( "# using output device id %d (%s, %s)\n", outputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );
inputParameters.device = -1;
if( argc > 2 )
inputParameters.device = atoi(argv[1]);
if( inputParameters.device == -1 ){
inputParameters.device = Pa_GetDefaultInputDevice();
if (inputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default input device available.\n");
goto error;
}
}else{
deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
if( !deviceInfo ){
fprintf(stderr,"Error: Invalid input device index.\n");
usage();
}
if( deviceInfo->maxInputChannels == 0 ){
fprintf(stderr,"Error: Specified input device has no input channels (an output only device?).\n");
usage();
}
}
inputParameters.channelCount = NUM_CHANNELS;
inputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
inputParameters.hostApiSpecificStreamInfo = NULL;
deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
printf( "# using input device id %d (%s, %s)\n", inputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );
printf( "# suggested latency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency\n" );
printf( "# suggested latency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency, full duplex PaStreamInfo::outputLatency, full duplex PaStreamInfo::inputLatency\n" );
suggestedLatency = SUGGESTED_LATENCY_START_SECONDS;
while( suggestedLatency <= SUGGESTED_LATENCY_END_SECONDS ){