Debian Codegraph @

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

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * $Id: debug_multi_in.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
3 * debug_multi_in.c
4 * Pass output from each of multiple channels
5 * to a stereo output using the Portable Audio api.
6 * Hacked test for debugging PA.
7 *
8 * Author: Phil Burk http://www.softsynth.com
9 *
10 * This program uses the PortAudio Portable Audio Library.
11 * For more information see: http://www.portaudio.com
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 <string.h>
41 #include "portaudio.h"
42 //#define INPUT_DEVICE_NAME ("EWS88 MT Interleaved Rec")
43 #define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID())
44 //#define OUTPUT_DEVICE (18)
45 #define SAMPLE_RATE (22050)
46 #define FRAMES_PER_BUFFER (256)
47 #define MIN_LATENCY_MSEC (400)
48 #define NUM_BUFFERS ((MIN_LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000))
49 #ifndef M_PI
50 #define M_PI (3.14159265)
51 #endif
52 typedef struct
53 {
54 int liveChannel;
55 int numChannels;
56 }
57 paTestData;
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 float *in = (float*)inputBuffer;
69 int i;
70 int finished = 0;
71 (void) outTime; /* Prevent unused variable warnings. */
72 (void) inputBuffer;
73
74 if( in == NULL ) return 0;
75 for( i=0; i<(int)framesPerBuffer; i++ )
76 {
77 /* Copy one channel of input to output. */
78 *out++ = in[data->liveChannel];
79 *out++ = in[data->liveChannel];
80 in += data->numChannels;
81 }
82 return 0;
83 }
84 /*******************************************************************/
85 int PaFindDeviceByName( const char *name )
86 {
87 int i;
88 int numDevices;
89 const PaDeviceInfo *pdi;
90 int len = strlen( name );
91 PaDeviceID result = paNoDevice;
92 numDevices = Pa_CountDevices();
93 for( i=0; i<numDevices; i++ )
94 {
95 pdi = Pa_GetDeviceInfo( i );
96 if( strncmp( name, pdi->name, len ) == 0 )
97 {
98 result = i;
99 break;
100 }
101 }
102 return result;
103 }
104 /*******************************************************************/
105 int main(void);
106 int main(void)
107 {
108 PortAudioStream *stream;
109 PaError err;
110 paTestData data;
111 int i;
112 PaDeviceID inputDevice;
113 const PaDeviceInfo *pdi;
114 printf("PortAudio Test: input signal from each channel. %d buffers\n", NUM_BUFFERS );
115 data.liveChannel = 0;
116 err = Pa_Initialize();
117 if( err != paNoError ) goto error;
118 #ifdef INPUT_DEVICE_NAME
119 printf("Try to use device: %s\n", INPUT_DEVICE_NAME );
120 inputDevice = PaFindDeviceByName(INPUT_DEVICE_NAME);
121 if( inputDevice == paNoDevice )
122 {
123 printf("Could not find %s. Using default instead.\n", INPUT_DEVICE_NAME );
124 inputDevice = Pa_GetDefaultInputDeviceID();
125 }
126 #else
127 printf("Using default input device.\n");
128 inputDevice = Pa_GetDefaultInputDeviceID();
129 #endif
130 pdi = Pa_GetDeviceInfo( inputDevice );
131 if( pdi == NULL )
132 {
133 printf("Could not get device info!\n");
134 goto error;
135 }
136 data.numChannels = pdi->maxInputChannels;
137 printf("Input Device name is %s\n", pdi->name );
138 printf("Input Device has %d channels.\n", pdi->maxInputChannels);
139 err = Pa_OpenStream(
140 &stream,
141 inputDevice,
142 pdi->maxInputChannels,
143 paFloat32, /* 32 bit floating point input */
144 NULL,
145 OUTPUT_DEVICE,
146 2,
147 paFloat32, /* 32 bit floating point output */
148 NULL,
149 SAMPLE_RATE,
150 FRAMES_PER_BUFFER, /* frames per buffer */
151 NUM_BUFFERS, /* number of buffers, if zero then use default minimum */
152 paClipOff, /* we won't output out of range samples so don't bother clipping them */
153 patestCallback,
154 &data );
155 if( err != paNoError ) goto error;
156 data.liveChannel = 0;
157 err = Pa_StartStream( stream );
158 if( err != paNoError ) goto error;
159 for( i=0; i<data.numChannels; i++ )
160 {
161 data.liveChannel = i;
162 printf("Channel %d being sent to output. Hit ENTER for next channel.", i );
163 fflush(stdout);
164 getchar();
165 }
166 err = Pa_StopStream( stream );
167 if( err != paNoError ) goto error;
168
169 err = Pa_CloseStream( stream );
170 Pa_Terminate();
171 printf("Test finished.\n");
172 return err;
173 error:
174 Pa_Terminate();
•175 fprintf( stderr, "An error occurred while using the portaudio stream\n" );
176 fprintf( stderr, "Error number: %d\n", err );
177 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
178 return err;
179 }