Debian Codegraph @

3rdparty/iaxclient/lib/portaudio/test/debug_convert.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: debug_convert.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
3 * Convert tagged values.
4 *
5 * Author: Phil Burk <[email protected]>
6 *
7 * This program uses the PortAudio Portable Audio Library.
8 * For more information see: http://www.portaudio.com
9 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * a copy of this software and associated documentation files
13 * (the "Software"), to deal in the Software without restriction,
14 * including without limitation the rights to use, copy, modify, merge,
15 * publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so,
17 * subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
21 *
22 * Any person wishing to distribute modifications to the Software is
23 * requested to send the modifications to the original developer so that
24 * they can be incorporated into the canonical version.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
31 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35 #include <stdio.h>
36 #include <math.h>
37 #include "portaudio.h"
38 #define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID())
39 //#define OUTPUT_DEVICE (11)
40 #define NUM_SECONDS (8)
41 #define SLEEP_DUR (800)
42 #define SAMPLE_RATE (44100)
43 #define FRAMES_PER_BUFFER (256)
44
45 #define NUM_BUFFERS (0)
46
47 typedef struct
48 {
49 unsigned int framesToGo;
50 }
51 paTestData;
52 /* This routine will be called by the PortAudio engine when audio is needed.
53 ** It may called at interrupt level on some machines so don't do anything
54 ** that could mess up the system like calling malloc() or free().
55 */
56 static int patestCallback( void *inputBuffer, void *outputBuffer,
57 unsigned long framesPerBuffer,
58 PaTimestamp outTime, void *userData )
59 {
60 paTestData *data = (paTestData*)userData;
61 short *out = (short*)outputBuffer;
62 int i;
63 int finished = 0;
64 (void) outTime; /* Prevent unused variable warnings. */
65 (void) inputBuffer;
66
67 if( data->framesToGo < framesPerBuffer ) finished = 1;
68
69 for( i=0; i<framesPerBuffer; i++ )
70 {
71 *out++ = 0x0000 + i; /* left */
72 *out++ = 0x1000 + i; /* right */
73 }
74 return finished;
75 }
76 /*******************************************************************/
77 int main(void);
78 int main(void)
79 {
80 PortAudioStream *stream;
81 PaError err;
82 paTestData data;
83 int i;
84 int totalSamps;
85 printf("PortAudio Test: output debug values\n" );
86 data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */
87 printf("totalSamps = %d\n", totalSamps );
88 err = Pa_Initialize();
89 if( err != paNoError ) goto error;
90 printf("PortAudio Test: output device = %d\n", OUTPUT_DEVICE );
91
92 err = Pa_OpenStream(
93 &stream,
94 paNoDevice,
95 0, /* no input */
96 paFloat32, /* 32 bit floating point input */
97 NULL,
98 OUTPUT_DEVICE,
99 2, /* stereo output */
100 paInt16, /* 32 bit floating point output */
101 NULL,
102 SAMPLE_RATE,
103 FRAMES_PER_BUFFER,
104 NUM_BUFFERS, /* number of buffers, if zero then use default minimum */
105 paClipOff|paDitherOff, /* we won't output out of range samples so don't bother clipping them */
106 patestCallback,
107 &data );
108 if( err != paNoError ) goto error;
109
110 err = Pa_StartStream( stream );
111 if( err != paNoError ) goto error;
112 printf("Is callback being called?\n");
113 for( i=0; i<((NUM_SECONDS+1)*1000); i+=SLEEP_DUR )
114 {
115 printf("data.framesToGo = %d\n", data.framesToGo ); fflush(stdout);
116 Pa_Sleep( SLEEP_DUR );
117 }
118 /* Stop sound until ENTER hit. */
119 printf("Call Pa_StopStream()\n");
120 err = Pa_StopStream( stream );
121 if( err != paNoError ) goto error;
122 Pa_Terminate();
123 printf("Test finished.\n");
124 return err;
125 error:
126 Pa_Terminate();
127 fprintf( stderr, "An error occured while using the portaudio stream\n" );
128 fprintf( stderr, "Error number: %d\n", err );
129 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
130 return err;
131 }