/*
* $Id$
* patest_longsine.c
- * Play a sine wave using the Portable Audio api forever.
+ * Play a sine wave using the Portable Audio api until ENTER hit.
*
* Author: Phil Burk http://www.softsynth.com
*
#include <stdio.h>
#include <math.h>
#include "portaudio.h"
+
#define SAMPLE_RATE (44100)
+
#ifndef M_PI
#define M_PI (3.14159265)
#endif
+
#define TABLE_SIZE (200)
typedef struct
{
int right_phase;
}
paTestData;
+
/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
}
return 0;
}
+
/*******************************************************************/
int main(void);
int main(void)
paTestData data;
int i;
printf("PortAudio Test: output sine wave.\n");
+
/* initialise sinusoidal wavetable */
for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
}
data.left_phase = data.right_phase = 0;
+
err = Pa_Initialize();
if( err != paNoError ) goto error;
+
err = Pa_OpenStream(
&stream,
paNoDevice,/* default input device */
patestCallback,
&data );
if( err != paNoError ) goto error;
+
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
+
printf("Hit ENTER to stop program.\n");
getchar();
+
err = Pa_CloseStream( stream );
if( err != paNoError ) goto error;
Pa_Terminate();
+
printf("Test finished.\n");
return err;
+
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );