| 1 | /* |
| 2 | * patest_sine_channelmaps.c |
| 3 | * |
| 4 | * This program uses the PortAudio Portable Audio Library. |
| 5 | * For more information see: http://www.portaudio.com/ |
| 6 | * Copyright (c) 1999-2000 Ross Bencina and Phil Burk |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining |
| 9 | * a copy of this software and associated documentation files |
| 10 | * (the "Software"), to deal in the Software without restriction, |
| 11 | * including without limitation the rights to use, copy, modify, merge, |
| 12 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 13 | * and to permit persons to whom the Software is furnished to do so, |
| 14 | * subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be |
| 17 | * included in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 22 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 24 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 25 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * The text above constitutes the entire PortAudio license; however, |
| 30 | * the PortAudio community also makes the following non-binding requests: |
| 31 | * |
| 32 | * Any person wishing to distribute modifications to the Software is |
| 33 | * requested to send the modifications to the original developer so that |
| 34 | * they can be incorporated into the canonical version. It is also |
| 35 | * requested that these non-binding requests be included along with the |
| 36 | * license above. |
| 37 | */ |
| 38 | |
| 39 | /** @file patest_sine_channelmaps.c |
| 40 | @ingroup test_src |
| 41 | @brief Plays sine waves using sme simple channel maps. |
| 42 | Designed for use with CoreAudio, but should made to work with other APIs |
| 43 | @author Bjorn Roche <[email protected]> |
| 44 | @author Ross Bencina <[email protected]> |
| 45 | @author Phil Burk <[email protected]> |
| 46 | */ |
| 47 | |
| 48 | #include <stdio.h> |
| 49 | #include <math.h> |
| 50 | #include "portaudio.h"cxx . . $ `<file>/include/portaudio.h`/ |
| 51 | |
| 52 | #ifdef __APPLE__ |
| 53 | #include "pa_mac_core.h" |
| 54 | #endif |
| 55 | |
| 56 | #define NUM_SECONDScxx . . $ `test/patest_sine_channelmaps.c:56:9`! (5) |
| 57 | #define SAMPLE_RATEcxx . . $ `test/patest_sine_channelmaps.c:57:9`! (44100) |
| 58 | #define FRAMES_PER_BUFFERcxx . . $ `test/patest_sine_channelmaps.c:58:9`! (64) |
| 59 | |
| 60 | #ifndef M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! |
| 61 | #define M_PI (3.14159265) |
| 62 | #endif |
| 63 | |
| 64 | #define TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`! (200) |
| 65 | typedef structcxx . . $ $anonymous_type_e00d8f582de48c4b_0# |
| 66 | { |
| 67 | float sinecxx . . $ $anonymous_type_e00d8f582de48c4b_0#sine.[TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`!]; |
| 68 | int left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase.; |
| 69 | int right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase.; |
| 70 | } |
| 71 | paTestDatacxx . . $ paTestData#; |
| 72 | |
| 73 | /* This routine will be called by the PortAudio engine when audio is needed. |
| 74 | ** It may called at interrupt level on some machines so don't do anything |
| 75 | ** that could mess up the system like calling malloc() or free(). |
| 76 | */ |
| 77 | static int patestCallbackcxx . . $ patestCallback(fb4a53f6a51faeed).( const void *inputBuffer, void *outputBuffer, |
| 78 | unsigned long framesPerBuffer, |
| 79 | const PaStreamCallbackTimeInfocxx . . $ PaStreamCallbackTimeInfo#* timeInfo, |
| 80 | PaStreamCallbackFlagscxx . . $ PaStreamCallbackFlags# statusFlags, |
| 81 | void *userData ) |
| 82 | { |
| 83 | paTestDatacxx . . $ paTestData# *data = (paTestDatacxx . . $ paTestData#*)userData; |
| 84 | float *out = (float*)outputBuffer; |
| 85 | unsigned long i; |
| 86 | |
| 87 | (void) timeInfo; /* Prevent unused variable warnings. */ |
| 88 | (void) statusFlags; |
| 89 | (void) inputBuffer; |
| 90 | |
| 91 | for( i=0; i<framesPerBuffer; i++ ) |
| 92 | { |
| 93 | *out++ = data->sinecxx . . $ $anonymous_type_e00d8f582de48c4b_0#sine.[data->left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase.]; /* left */ |
| 94 | *out++ = data->sinecxx . . $ $anonymous_type_e00d8f582de48c4b_0#sine.[data->right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase.]; /* right */ |
| 95 | data->left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase. += 1; |
| 96 | if( data->left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase. >= TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`! ) data->left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase. -= TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`!; |
| 97 | data->right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase. += 3; /* higher pitch so we can distinguish left and right. */ |
| 98 | if( data->right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase. >= TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`! ) data->right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase. -= TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`!; |
| 99 | } |
| 100 | |
| 101 | return paContinuecxx . . $ paContinue.; |
| 102 | } |
| 103 | |
| 104 | /*******************************************************************/ |
| 105 | int maincxx . . $ main(b126dc7c1de90089).(void); |
| 106 | int maincxx . . $ main(b126dc7c1de90089).(void) |
| 107 | { |
| 108 | PaStreamParameterscxx . . $ PaStreamParameters# outputParameters; |
| 109 | PaStreamcxx . . $ PaStream# *stream; |
| 110 | PaErrorcxx . . $ PaError# err; |
| 111 | paTestDatacxx . . $ paTestData# data; |
| 112 | #ifdef __APPLE__ |
| 113 | PaMacCoreStreamInfo macInfo; |
| 114 | const SInt32 channelMap[4] = { -1, -1, 0, 1 }; |
| 115 | #endif |
| 116 | int i; |
| 117 | |
| 118 | |
| 119 | printfcxx . . $ printf(581fddd72a8db8fc).("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATEcxx . . $ `test/patest_sine_channelmaps.c:57:9`!, FRAMES_PER_BUFFERcxx . . $ `test/patest_sine_channelmaps.c:58:9`!); |
| 120 | printfcxx . . $ printf(581fddd72a8db8fc).("Output will be mapped to channels 2 and 3 instead of 0 and 1.\n"); |
| 121 | |
| 122 | /* initialise sinusoidal wavetable */ |
| 123 | for( i=0; i<TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`!; i++ ) |
| 124 | { |
| 125 | data.sinecxx . . $ $anonymous_type_e00d8f582de48c4b_0#sine.[i] = (float) sin( ((double)i/(double)TABLE_SIZEcxx . . $ `test/patest_sine_channelmaps.c:64:9`!) * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! * 2. ); |
| 126 | } |
| 127 | data.left_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#left_phase. = data.right_phasecxx . . $ $anonymous_type_e00d8f582de48c4b_0#right_phase. = 0; |
| 128 | |
| 129 | err = Pa_Initializecxx . . $ Pa_Initialize(b126dc7c1de90089).(); |
| 130 | if( err != paNoErrorcxx . . $ paNoError. ) goto error; |
| 131 | |
| 132 | /** setup host specific info */ |
| 133 | #ifdef __APPLE__ |
| 134 | PaMacCore_SetupStreamInfo( &macInfo, paMacCorePlayNice ); |
| 135 | PaMacCore_SetupChannelMap( &macInfo, channelMap, 4 ); |
| 136 | |
| 137 | for( i=0; i<4; ++i ) |
| 138 | printf( "channel %d name: %s\n", i, PaMacCore_GetChannelName( Pa_GetDefaultOutputDevice(), i, false ) ); |
| 139 | #else |
| 140 | printfcxx . . $ printf(581fddd72a8db8fc).( "Channel mapping not supported on this platform. Reverting to normal sine test.\n" ); |
| 141 | #endif |
| 142 | |
| 143 | outputParameters.devicecxx . . $ PaStreamParameters#device. = Pa_GetDefaultOutputDevicecxx . . $ Pa_GetDefaultOutputDevice(b126dc7c1de90089).(); /* default output device */ |
| 144 | if (outputParameters.devicecxx . . $ PaStreamParameters#device. == paNoDevicecxx . . $ `include/portaudio.h:220:9`!) { |
| 145 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: No default output device.\n"); |
| 146 | goto error; |
| 147 | } |
| 148 | outputParameters.channelCountcxx . . $ PaStreamParameters#channelCount. = 2; /* stereo output */ |
| 149 | outputParameters.sampleFormatcxx . . $ PaStreamParameters#sampleFormat. = paFloat32cxx . . $ `include/portaudio.h:487:9`!; /* 32 bit floating point output */ |
| 150 | outputParameters.suggestedLatencycxx . . $ PaStreamParameters#suggestedLatency. = Pa_GetDeviceInfocxx . . $ Pa_GetDeviceInfo(28aab36fd6bfe1f2).( outputParameters.devicecxx . . $ PaStreamParameters#device. )->defaultLowOutputLatencycxx . . $ PaDeviceInfo#defaultLowOutputLatency.; |
| 151 | #ifdef __APPLE__ |
| 152 | outputParameters.hostApiSpecificStreamInfo = &macInfo; |
| 153 | #else |
| 154 | outputParameters.hostApiSpecificStreamInfocxx . . $ PaStreamParameters#hostApiSpecificStreamInfo. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 155 | #endif |
| 156 | |
| 157 | err = Pa_OpenStreamcxx . . $ Pa_OpenStream(5ffaac200393836e).( |
| 158 | &stream, |
| 159 | NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, /* no input */ |
| 160 | &outputParameters, |
| 161 | SAMPLE_RATEcxx . . $ `test/patest_sine_channelmaps.c:57:9`!, |
| 162 | FRAMES_PER_BUFFERcxx . . $ `test/patest_sine_channelmaps.c:58:9`!, |
| 163 | paClipOffcxx . . $ `include/portaudio.h:661:11`!, /* we won't output out of range samples so don't bother clipping them */ |
| 164 | patestCallbackcxx . . $ patestCallback(fb4a53f6a51faeed)., |
| 165 | &data ); |
| 166 | if( err != paNoErrorcxx . . $ paNoError. ) goto error; |
| 167 | |
| 168 | err = Pa_StartStreamcxx . . $ Pa_StartStream(dedf1e9b1c614a07).( stream ); |
| 169 | if( err != paNoErrorcxx . . $ paNoError. ) goto error; |
| 170 | |
| 171 | printfcxx . . $ printf(581fddd72a8db8fc).("Play for %d seconds.\n", NUM_SECONDScxx . . $ `test/patest_sine_channelmaps.c:56:9`! ); |
| 172 | Pa_Sleepcxx . . $ Pa_Sleep(1624ee8275b10bda).( NUM_SECONDScxx . . $ `test/patest_sine_channelmaps.c:56:9`! * 1000 ); |
| 173 | |
| 174 | err = Pa_StopStreamcxx . . $ Pa_StopStream(dedf1e9b1c614a07).( stream ); |
| 175 | if( err != paNoErrorcxx . . $ paNoError. ) goto error; |
| 176 | |
| 177 | err = Pa_CloseStreamcxx . . $ Pa_CloseStream(dedf1e9b1c614a07).( stream ); |
| 178 | if( err != paNoErrorcxx . . $ paNoError. ) goto error; |
| 179 | |
| 180 | Pa_Terminatecxx . . $ Pa_Terminate(b126dc7c1de90089).(); |
| 181 | printfcxx . . $ printf(581fddd72a8db8fc).("Test finished.\n"); |
| 182 | |
| 183 | return err; |
| 184 | error: |
| 185 | Pa_Terminatecxx . . $ Pa_Terminate(b126dc7c1de90089).(); |
| 186 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "An error occurred while using the portaudio stream\n" ); |
| 187 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error number: %d\n", err ); |
| 188 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error message: %s\n", Pa_GetErrorTextcxx . . $ Pa_GetErrorText(f7ae7e56280f18ae).( err ) ); |
| 189 | return err; |
| 190 | } |