Debian Codegraph @

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

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * $Id: patest_two_rates.c,v 1.1 2006/06/10 21:30:57 dmazzoni Exp $
3 * patest_two_rates.c
4 * Play two streams at different rates to make sure they don't interfere.
5 *
6 * Author: Phil Burk http://www.softsynth.com
7 *
8 * This program uses the PortAudio Portable Audio Library.
9 * For more information see: http://www.portaudio.com
10 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining
13 * a copy of this software and associated documentation files
14 * (the "Software"), to deal in the Software without restriction,
15 * including without limitation the rights to use, copy, modify, merge,
16 * publish, distribute, sublicense, and/or sell copies of the Software,
17 * and to permit persons to whom the Software is furnished to do so,
18 * subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be
21 * included in all copies or substantial portions of the Software.
22 *
23 * Any person wishing to distribute modifications to the Software is
24 * requested to send the modifications to the original developer so that
25 * they can be incorporated into the canonical version.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
30 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
31 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 *
35 */
36 #include <stdio.h>
37 #include <math.h>
38 #include "portaudio.h"
39
40 #define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID())
41 #define SAMPLE_RATE_1 (44100)
42 #define SAMPLE_RATE_2 (44100)
43 #define FRAMES_PER_BUFFER (256)
44 #define FREQ_INCR (0.1)
45
46 #ifndef M_PI
47 #define M_PI (3.14159265)
48 #endif
49
50 typedef struct
51 {
52 double phase;
53 double numFrames;
54 } paTestData;
55
56 /* This routine will be called by the PortAudio engine when audio is needed.
57 ** It may called at interrupt level on some machines so don't do anything
58 ** that could mess up the system like calling malloc() or free().
59 */
60 static int patestCallback( void *inputBuffer, void *outputBuffer,
61 unsigned long framesPerBuffer,
62 PaTimestamp outTime, void *userData )
63 {
64 paTestData *data = (paTestData*)userData;
65 float *out = (float*)outputBuffer;
66 int frameIndex, channelIndex;
67 int finished = 0;
68 (void) outTime; /* Prevent unused variable warnings. */
69 (void) inputBuffer;
70
71 for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ )
72 {
73 /* Generate sine wave. */
74 float value = (float) 0.3 * sin(data->phase);
75 /* Stereo - two channels. */
76 *out++ = value;
77 *out++ = value;
78
79 data->phase += FREQ_INCR;
80 if( data->phase >= (2.0 * M_PI) ) data->phase -= (2.0 * M_PI);
81 }
82
83 return 0;
84 }
85
86 /*******************************************************************/
87 int main(void);
88 int main(void)
89 {
90 PaError err;
91 PortAudioStream *stream1;
92 PortAudioStream *stream2;
93 paTestData data1 = {0};
94 paTestData data2 = {0};
95 printf("PortAudio Test: two rates.\n" );
96
97 err = Pa_Initialize();
98 if( err != paNoError ) goto error;
99
100 /* Start first stream. **********************/
101 err = Pa_OpenStream(
102 &stream1,
103 paNoDevice, /* default input device */
104 0, /* no input */
105 paFloat32, /* 32 bit floating point input */
106 NULL,
107 OUTPUT_DEVICE,
108 2, /* Stereo */
109 paFloat32, /* 32 bit floating point output */
110 NULL,
111 SAMPLE_RATE_1,
112 FRAMES_PER_BUFFER, /* frames per buffer */
113 0, /* number of buffers, if zero then use default minimum */
114 paClipOff, /* we won't output out of range samples so don't bother clipping them */
115 patestCallback,
116 &data1 );
117 if( err != paNoError ) goto error;
118
119 err = Pa_StartStream( stream1 );
120 if( err != paNoError ) goto error;
121
122 Pa_Sleep( 3 * 1000 );
123
124 /* Start second stream. **********************/
125 err = Pa_OpenStream(
126 &stream2,
127 paNoDevice, /* default input device */
128 0, /* no input */
129 paFloat32, /* 32 bit floating point input */
130 NULL,
131 OUTPUT_DEVICE,
132 2, /* Stereo */
133 paFloat32, /* 32 bit floating point output */
134 NULL,
135 SAMPLE_RATE_2,
136 FRAMES_PER_BUFFER, /* frames per buffer */
137 0, /* number of buffers, if zero then use default minimum */
138 paClipOff, /* we won't output out of range samples so don't bother clipping them */
139 patestCallback,
140 &data2 );
141 if( err != paNoError ) goto error;
142
143 err = Pa_StartStream( stream2 );
144 if( err != paNoError ) goto error;
145
146 Pa_Sleep( 3 * 1000 );
147
148 err = Pa_StopStream( stream2 );
149 if( err != paNoError ) goto error;
150
151 Pa_Sleep( 3 * 1000 );
152
153 err = Pa_StopStream( stream1 );
154 if( err != paNoError ) goto error;
155
156 Pa_CloseStream( stream2 );
157 Pa_CloseStream( stream1 );
158
159 Pa_Terminate();
160 printf("Test finished.\n");
161 return err;
162 error:
163 Pa_Terminate();
164 fprintf( stderr, "An error occured while using the portaudio stream\n" );
165 fprintf( stderr, "Error number: %d\n", err );
166 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
167 return err;
168 }