Debian Codegraph @

3rdparty/iaxclient/lib/portaudio/test/debug_multi_out.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * $Id: debug_multi_out.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
3 * debug_multi_out.c
4 * Play a different sine wave on each channels,
5 * using the Portable Audio api.
6 *
7 * Author: Phil Burk http://www.softsynth.com
8 *
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
12 *
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:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * Any person wishing to distribute modifications to the Software is
25 * requested to send the modifications to the original developer so that
26 * they can be incorporated into the canonical version.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
32 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
33 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37 #include <stdio.h>
38 #include <math.h>
39 #include "portaudio.h"
40
41 #define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID())
42 #define SAMPLE_RATE (44100)
43 #define FRAMES_PER_BUFFER (256)
44 #define FREQ_INCR (300.0 / SAMPLE_RATE)
45 #define MAX_CHANNELS (64)
46
47 #ifndef M_PI
48 #define M_PI (3.14159265)
49 #endif
50
51 typedef struct
52 {
53 int numChannels;
54 double phases[MAX_CHANNELS];
55 }
56 paTestData;
57
58 /* This routine will be called by the PortAudio engine when audio is needed.
59 ** It may called at interrupt level on some machines so don't do anything
60 ** that could mess up the system like calling malloc() or free().
61 */
62 static int patestCallback( void *inputBuffer, void *outputBuffer,
63 unsigned long framesPerBuffer,
64 PaTimestamp outTime, void *userData )
65 {
66 paTestData *data = (paTestData*)userData;
67 float *out = (float*)outputBuffer;
68 int frameIndex, channelIndex;
69 int finished = 0;
70 (void) outTime; /* Prevent unused variable warnings. */
71 (void) inputBuffer;
72
73 for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ )
74 {
75 for( channelIndex=0; channelIndex<data->numChannels; channelIndex++ )
76 {
77 /* Output sine wave on every channel. */
78 *out++ = (float) sin(data->phases[channelIndex]);
79
80 /* Play each channel at a higher frequency. */
81 data->phases[channelIndex] += FREQ_INCR * (4 + channelIndex);
82 if( data->phases[channelIndex] >= (2.0 * M_PI) ) data->phases[channelIndex] -= (2.0 * M_PI);
83 }
84 }
85
86 return 0;
87 }
88 /*******************************************************************/
89 int main(void);
90 int main(void)
91 {
92 PortAudioStream *stream;
93 PaError err;
94 const PaDeviceInfo *pdi;
95 paTestData data = {0};
96 printf("PortAudio Test: output sine wave on each channel.\n" );
97
98 err = Pa_Initialize();
99 if( err != paNoError ) goto error;
100
101 pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE );
102 data.numChannels = pdi->maxOutputChannels;
103 if( data.numChannels > MAX_CHANNELS ) data.numChannels = MAX_CHANNELS;
104 printf("Number of Channels = %d\n", data.numChannels );
105
106 err = Pa_OpenStream(
107 &stream,
108 paNoDevice, /* default input device */
109 0, /* no input */
110 paFloat32, /* 32 bit floating point input */
111 NULL,
112 OUTPUT_DEVICE,
113 data.numChannels,
114 paFloat32, /* 32 bit floating point output */
115 NULL,
116 SAMPLE_RATE,
117 FRAMES_PER_BUFFER, /* frames per buffer */
118 0, /* number of buffers, if zero then use default minimum */
119 paClipOff, /* we won't output out of range samples so don't bother clipping them */
120 patestCallback,
121 &data );
122 if( err != paNoError ) goto error;
123
124 err = Pa_StartStream( stream );
125 if( err != paNoError ) goto error;
126
127 printf("Hit ENTER to stop sound.\n");
128 fflush(stdout);
129 getchar();
130
131 err = Pa_StopStream( stream );
132 if( err != paNoError ) goto error;
133
134 Pa_CloseStream( stream );
135 Pa_Terminate();
136 printf("Test finished.\n");
137 return err;
138 error:
139 Pa_Terminate();
•140 fprintf( stderr, "An error occurred while using the portaudio stream\n" );
141 fprintf( stderr, "Error number: %d\n", err );
142 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
143 return err;
144 }