2
* $Id: debug_multi_out.c,v 1.2 2006/09/23 18:42:51 llucius Exp $
4
* Play a different sine wave on each channels,
5
* using the Portable Audio api.
7
* Author: Phil Burk http://www.softsynth.com
9
* This program uses the PortAudio Portable Audio Library.
10
* For more information see: http://www.portaudio.com
11
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files
15
* (the "Software"), to deal in the Software without restriction,
16
* including without limitation the rights to use, copy, modify, merge,
17
* publish, distribute, sublicense, and/or sell copies of the Software,
18
* and to permit persons to whom the Software is furnished to do so,
19
* subject to the following conditions:
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
28
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
* The text above constitutes the entire PortAudio license; however,
35
* the PortAudio community also makes the following non-binding requests:
37
* Any person wishing to distribute modifications to the Software is
38
* requested to send the modifications to the original developer so that
39
* they can be incorporated into the canonical version. It is also
40
* requested that these non-binding requests be included along with the
46
#include "portaudio.h"
48
#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID())
49
#define SAMPLE_RATE (44100)
50
#define FRAMES_PER_BUFFER (256)
51
#define FREQ_INCR (300.0 / SAMPLE_RATE)
52
#define MAX_CHANNELS (64)
55
#define M_PI (3.14159265)
61
double phases[MAX_CHANNELS];
65
/* This routine will be called by the PortAudio engine when audio is needed.
66
** It may called at interrupt level on some machines so don't do anything
67
** that could mess up the system like calling malloc() or free().
69
static int patestCallback( void *inputBuffer, void *outputBuffer,
70
unsigned long framesPerBuffer,
71
PaTimestamp outTime, void *userData )
73
paTestData *data = (paTestData*)userData;
74
float *out = (float*)outputBuffer;
75
int frameIndex, channelIndex;
77
(void) outTime; /* Prevent unused variable warnings. */
80
for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ )
82
for( channelIndex=0; channelIndex<data->numChannels; channelIndex++ )
84
/* Output sine wave on every channel. */
85
*out++ = (float) sin(data->phases[channelIndex]);
87
/* Play each channel at a higher frequency. */
88
data->phases[channelIndex] += FREQ_INCR * (4 + channelIndex);
89
if( data->phases[channelIndex] >= (2.0 * M_PI) ) data->phases[channelIndex] -= (2.0 * M_PI);
95
/*******************************************************************/
99
PortAudioStream *stream;
101
const PaDeviceInfo *pdi;
102
paTestData data = {0};
103
printf("PortAudio Test: output sine wave on each channel.\n" );
105
err = Pa_Initialize();
106
if( err != paNoError ) goto error;
108
pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE );
109
data.numChannels = pdi->maxOutputChannels;
110
if( data.numChannels > MAX_CHANNELS ) data.numChannels = MAX_CHANNELS;
111
printf("Number of Channels = %d\n", data.numChannels );
115
paNoDevice, /* default input device */
117
paFloat32, /* 32 bit floating point input */
121
paFloat32, /* 32 bit floating point output */
124
FRAMES_PER_BUFFER, /* frames per buffer */
125
0, /* number of buffers, if zero then use default minimum */
126
paClipOff, /* we won't output out of range samples so don't bother clipping them */
129
if( err != paNoError ) goto error;
131
err = Pa_StartStream( stream );
132
if( err != paNoError ) goto error;
134
printf("Hit ENTER to stop sound.\n");
138
err = Pa_StopStream( stream );
139
if( err != paNoError ) goto error;
141
Pa_CloseStream( stream );
143
printf("Test finished.\n");
147
fprintf( stderr, "An error occured while using the portaudio stream\n" );
148
fprintf( stderr, "Error number: %d\n", err );
149
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );