| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <stdio.h> |
| 36 |
#include <math.h> |
| 37 |
#include "portaudio.h" |
| 38 |
#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) |
| 39 |
|
| 40 |
#define NUM_SECONDS (8) |
| 41 |
#define SLEEP_DUR (800) |
| 42 |
#define SAMPLE_RATE (44100) |
| 43 |
#define FRAMES_PER_BUFFER (256) |
| 44 |
|
| 45 |
#define NUM_BUFFERS (0) |
| 46 |
|
| 47 |
typedef struct |
| 48 |
{ |
| 49 |
unsigned int framesToGo; |
| 50 |
} |
| 51 |
paTestData; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
static int patestCallback( void *inputBuffer, void *outputBuffer, |
| 57 |
unsigned long framesPerBuffer, |
| 58 |
PaTimestamp outTime, void *userData ) |
| 59 |
{ |
| 60 |
paTestData *data = (paTestData*)userData; |
| 61 |
short *out = (short*)outputBuffer; |
| 62 |
int i; |
| 63 |
int finished = 0; |
| 64 |
(void) outTime; |
| 65 |
(void) inputBuffer; |
| 66 |
|
| 67 |
if( data->framesToGo < framesPerBuffer ) finished = 1; |
| 68 |
|
| 69 |
for( i=0; i<framesPerBuffer; i++ ) |
| 70 |
{ |
| 71 |
*out++ = 0x0000 + i; |
| 72 |
*out++ = 0x1000 + i; |
| 73 |
} |
| 74 |
return finished; |
| 75 |
} |
| 76 |
|
| 77 |
int main(void); |
| 78 |
int main(void) |
| 79 |
{ |
| 80 |
PortAudioStream *stream; |
| 81 |
PaError err; |
| 82 |
paTestData data; |
| 83 |
int i; |
| 84 |
int totalSamps; |
| 85 |
printf("PortAudio Test: output debug values\n" ); |
| 86 |
data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; |
| 87 |
printf("totalSamps = %d\n", totalSamps ); |
| 88 |
err = Pa_Initialize(); |
| 89 |
if( err != paNoError ) goto error; |
| 90 |
printf("PortAudio Test: output device = %d\n", OUTPUT_DEVICE ); |
| 91 |
|
| 92 |
err = Pa_OpenStream( |
| 93 |
&stream, |
| 94 |
paNoDevice, |
| 95 |
0, |
| 96 |
paFloat32, |
| 97 |
NULL, |
| 98 |
OUTPUT_DEVICE, |
| 99 |
2, |
| 100 |
paInt16, |
| 101 |
NULL, |
| 102 |
SAMPLE_RATE, |
| 103 |
FRAMES_PER_BUFFER, |
| 104 |
NUM_BUFFERS, |
| 105 |
paClipOff|paDitherOff, |
| 106 |
patestCallback, |
| 107 |
&data ); |
| 108 |
if( err != paNoError ) goto error; |
| 109 |
|
| 110 |
err = Pa_StartStream( stream ); |
| 111 |
if( err != paNoError ) goto error; |
| 112 |
printf("Is callback being called?\n"); |
| 113 |
for( i=0; i<((NUM_SECONDS+1)*1000); i+=SLEEP_DUR ) |
| 114 |
{ |
| 115 |
printf("data.framesToGo = %d\n", data.framesToGo ); fflush(stdout); |
| 116 |
Pa_Sleep( SLEEP_DUR ); |
| 117 |
} |
| 118 |
|
| 119 |
printf("Call Pa_StopStream()\n"); |
| 120 |
err = Pa_StopStream( stream ); |
| 121 |
if( err != paNoError ) goto error; |
| 122 |
Pa_Terminate(); |
| 123 |
printf("Test finished.\n"); |
| 124 |
return err; |
| 125 |
error: |
| 126 |
Pa_Terminate(); |
| •127 |
fprintf( stderr, "An error occurred while using the portaudio stream\n" ); |
| 128 |
fprintf( stderr, "Error number: %d\n", err ); |
| 129 |
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); |
| 130 |
return err; |
| 131 |
} |