Debian Codegraph @

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

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * $Id: patest_mono_asio_channel_select.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
3 * patest_sine.c
4 * Play a monophonic sine wave using the Portable Audio api for several seconds.
5 *
6 * Authors:
7 * Ross Bencina <[email protected]>
8 * Phil Burk <[email protected]>
9 *
10 * This program uses the PortAudio Portable Audio Library.
11 * For more information see: http://www.audiomulch.com/portaudio/
12 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files
16 * (the "Software"), to deal in the Software without restriction,
17 * including without limitation the rights to use, copy, modify, merge,
18 * publish, distribute, sublicense, and/or sell copies of the Software,
19 * and to permit persons to whom the Software is furnished to do so,
20 * subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
24 *
25 * Any person wishing to distribute modifications to the Software is
26 * requested to send the modifications to the original developer so that
27 * they can be incorporated into the canonical version.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
33 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
34 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 *
37 */
38 #include <stdio.h>
39 #include <math.h>
40 #include "portaudio.h"
41 #include "pa_asio.h"
42
43 #define NUM_SECONDS (10)
44 #define SAMPLE_RATE (44100)
45 #define AMPLITUDE (0.8)
46 #define FRAMES_PER_BUFFER (64)
47 #define OUTPUT_DEVICE Pa_GetDefaultOutputDevice()
48
49 #ifndef M_PI
50 #define M_PI (3.14159265)
51 #endif
52
53 #define TABLE_SIZE (200)
54 typedef struct
55 {
56 float sine[TABLE_SIZE];
57 int phase;
58 }
59 paTestData;
60
61 /* This routine will be called by the PortAudio engine when audio is needed.
62 ** It may called at interrupt level on some machines so don't do anything
63 ** that could mess up the system like calling malloc() or free().
64 */
65 static int patestCallback( const void *inputBuffer, void *outputBuffer,
66 unsigned long framesPerBuffer,
67 const PaStreamCallbackTimeInfo* timeInfo,
68 PaStreamCallbackFlags statusFlags,
69 void *userData )
70 {
71 paTestData *data = (paTestData*)userData;
72 float *out = (float*)outputBuffer;
73 unsigned long i;
74 int finished = 0;
75 /* avoid unused variable warnings */
76 (void) inputBuffer;
77 (void) timeInfo;
78 (void) statusFlags;
79 for( i=0; i<framesPerBuffer; i++ )
80 {
81 *out++ = data->sine[data->phase]; /* left */
82 data->phase += 1;
83 if( data->phase >= TABLE_SIZE ) data->phase -= TABLE_SIZE;
84 }
85 return finished;
86 }
87
88 /*******************************************************************/
89 int main(void);
90 int main(void)
91 {
92 PaStreamParameters outputParameters;
93 PaAsioStreamInfo asioOutputInfo;
94 PaStream *stream;
95 PaError err;
96 paTestData data;
97 int outputChannelSelectors[1];
98 int i;
99 printf("PortAudio Test: output MONO sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
100 /* initialise sinusoidal wavetable */
101 for( i=0; i<TABLE_SIZE; i++ )
102 {
103 data.sine[i] = (float) (AMPLITUDE * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ));
104 }
105 data.phase = 0;
106
107 err = Pa_Initialize();
108 if( err != paNoError ) goto error;
109
110 outputParameters.device = OUTPUT_DEVICE;
111 outputParameters.channelCount = 1; /* MONO output */
112 outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
113 outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
114
115 asioOutputInfo.size = sizeof(PaAsioStreamInfo);
116 asioOutputInfo.hostApiType = paASIO;
117 asioOutputInfo.version = 1;
118 asioOutputInfo.flags = paAsioUseChannelSelectors;
119 outputChannelSelectors[0] = 1; /* select the second (right) ASIO device channel */
120 asioOutputInfo.channelSelectors = outputChannelSelectors;
121 outputParameters.hostApiSpecificStreamInfo = &asioOutputInfo;
122
123 err = Pa_OpenStream(
124 &stream,
125 NULL, /* no input */
126 &outputParameters,
127 SAMPLE_RATE,
128 FRAMES_PER_BUFFER,
129 paClipOff, /* we won't output out of range samples so don't bother clipping them */
130 patestCallback,
131 &data );
132 if( err != paNoError ) goto error;
133
134 err = Pa_StartStream( stream );
135 if( err != paNoError ) goto error;
136
137 printf("Play for %d seconds.\n", NUM_SECONDS ); fflush(stdout);
138 Pa_Sleep( NUM_SECONDS * 1000 );
139
140 err = Pa_StopStream( stream );
141 if( err != paNoError ) goto error;
142
143 err = Pa_CloseStream( stream );
144 if( err != paNoError ) goto error;
145
146 Pa_Terminate();
147 printf("Test finished.\n");
148 return err;
149 error:
150 Pa_Terminate();
•151 fprintf( stderr, "An error occurred while using the portaudio stream\n" );
152 fprintf( stderr, "Error number: %d\n", err );
153 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
154 return err;
155 }