fixed some warnings and minor bugs in patest_suggested_vs_streaminfo_latency.c
This commit is contained in:
parent
b3eeb36d05
commit
59b9cf7180
1 changed files with 37 additions and 36 deletions
|
|
@ -48,11 +48,12 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "portaudio.h"
|
#include "portaudio.h"
|
||||||
|
|
||||||
#define SAMPLE_RATE (44100)
|
#define SAMPLE_RATE (44100)
|
||||||
#define FRAMES_PER_BUFFER (128)
|
#define FRAMES_PER_BUFFER 2//(128)
|
||||||
#define NUM_CHANNELS (2)
|
#define NUM_CHANNELS (2)
|
||||||
|
|
||||||
#define SUGGESTED_LATENCY_START_SECONDS (0.0)
|
#define SUGGESTED_LATENCY_START_SECONDS (0.0)
|
||||||
|
|
@ -67,6 +68,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
PaStreamCallbackFlags statusFlags,
|
PaStreamCallbackFlags statusFlags,
|
||||||
void *userData )
|
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[] );
|
||||||
int main( int argc, const char* argv[] )
|
int main( int argc, const char* argv[] )
|
||||||
{
|
{
|
||||||
PaStreamParameters outputParameters, inputParameters;
|
PaStreamParameters inputParameters, outputParameters;
|
||||||
PaStream *stream;
|
PaStream *stream;
|
||||||
PaError err;
|
PaError err;
|
||||||
PaTime suggestedLatency;
|
PaTime suggestedLatency;
|
||||||
PaStreamInfo *streamInfo;
|
const PaStreamInfo *streamInfo;
|
||||||
PaDeviceInfo *deviceInfo;
|
const PaDeviceInfo *deviceInfo;
|
||||||
float sampleRate = SAMPLE_RATE;
|
float sampleRate = SAMPLE_RATE;
|
||||||
int framesPerBuffer = FRAMES_PER_BUFFER;
|
int framesPerBuffer = FRAMES_PER_BUFFER;
|
||||||
err = Pa_Initialize();
|
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 );
|
printf("# sample rate=%f, frames per buffer=%d\n", (float)sampleRate, framesPerBuffer );
|
||||||
|
|
||||||
outputParameters.device = -1;
|
inputParameters.device = -1;
|
||||||
if( argc > 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 ){
|
if( outputParameters.device == -1 ){
|
||||||
outputParameters.device = Pa_GetDefaultOutputDevice();
|
outputParameters.device = Pa_GetDefaultOutputDevice();
|
||||||
if (outputParameters.device == paNoDevice) {
|
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 );
|
printf( "# using output device id %d (%s, %s)\n", outputParameters.device, deviceInfo->name, Pa_GetHostApiInfo(deviceInfo->hostApi)->name );
|
||||||
|
|
||||||
|
|
||||||
inputParameters.device = -1;
|
printf( "# suggested latency, half duplex PaStreamInfo::outputLatency, half duplex PaStreamInfo::inputLatency, full duplex PaStreamInfo::outputLatency, full duplex PaStreamInfo::inputLatency\n" );
|
||||||
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" );
|
|
||||||
suggestedLatency = SUGGESTED_LATENCY_START_SECONDS;
|
suggestedLatency = SUGGESTED_LATENCY_START_SECONDS;
|
||||||
while( suggestedLatency <= SUGGESTED_LATENCY_END_SECONDS ){
|
while( suggestedLatency <= SUGGESTED_LATENCY_END_SECONDS ){
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue