Pa_RefreshDevice functionality

This commit is contained in:
Andrew Gundersen 2021-08-20 11:09:19 -05:00
commit 1f01a3ddc0
8 changed files with 337 additions and 2 deletions

View file

@ -258,7 +258,6 @@ static int recordCallback( const void *inputBuffer, void *outputBuffer,
data->frameIndex += PaUtil_WriteRingBuffer(&data->ringBuffer, rptr, elementsToWrite);
return paContinue;
}
/* This routine will be called by the PortAudio engine when audio is needed.
@ -272,8 +271,11 @@ static int playCallback( const void *inputBuffer, void *outputBuffer,
void *userData )
{
paTestData *data = (paTestData*)userData;
ring_buffer_size_t elementsToPlay = PaUtil_GetRingBufferReadAvailable(&data->ringBuffer);
ring_buffer_size_t elementsToRead = rbs_min(elementsToPlay, (ring_buffer_size_t)(framesPerBuffer * NUM_CHANNELS));
ring_buffer_size_t elementsToRead = rbs_min( elementsToPlay,
(ring_buffer_size_t)(framesPerBuffer * NUM_CHANNELS) );
SAMPLE* wptr = (SAMPLE*)outputBuffer;
(void) inputBuffer; /* Prevent unused variable warnings. */

View file

@ -0,0 +1,46 @@
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include "portaudio.h"
int main()
{
PaError err = paNoError;
PaDeviceIndex defaultOutputDevice;
PaDeviceIndex defaultInputDevice;
err = Pa_Initialize();
if( err != paNoError )
{
printf( "ERROR: Pa_Initialize returned 0x%x\n", err );
goto error;
}
printf( "PortAudio version: 0x%08X\n", Pa_GetVersion());
// printf( "Version text: '%s'\n", Pa_GetVersionInfo()->versionText );
const int count = 20;
for (int i = 0; i < count; ++i)
{
defaultInputDevice = Pa_GetDefaultInputDevice();
defaultOutputDevice = Pa_GetDefaultOutputDevice();
printf("Input: %i, Output: %i\n", defaultInputDevice, defaultOutputDevice);
err = Pa_RefreshDevices();
if( err != paNoError )
{
printf( "ERROR: Pa_RefreshDevices returned 0x%x\n", err );
goto error;
}
sleep(2);
}
Pa_Terminate();
printf("----------------------------------------------\n");
return 0;
error:
return 1;
}

View file

@ -154,6 +154,7 @@ int main(void)
if( err != paNoError ) goto error;
printf("Play for %d seconds.\n", NUM_SECONDS );
Pa_Sleep( NUM_SECONDS * 1000 );
err = Pa_StopStream( stream );