annotate src/portaudio/test/patest_ringmix.c @ 105:c83a7e2af39c

Ranlib
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 25 Mar 2013 16:28:19 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 /** @file patest_ringmix.c
cannam@89 2 @ingroup test_src
cannam@89 3 @brief Ring modulate inputs to left output, mix inputs to right output.
cannam@89 4 */
cannam@89 5 /*
cannam@89 6 * $Id: patest_ringmix.c 1097 2006-08-26 08:27:53Z rossb $
cannam@89 7 *
cannam@89 8 * This program uses the PortAudio Portable Audio Library.
cannam@89 9 * For more information see: http://www.portaudio.com
cannam@89 10 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
cannam@89 11 *
cannam@89 12 * Permission is hereby granted, free of charge, to any person obtaining
cannam@89 13 * a copy of this software and associated documentation files
cannam@89 14 * (the "Software"), to deal in the Software without restriction,
cannam@89 15 * including without limitation the rights to use, copy, modify, merge,
cannam@89 16 * publish, distribute, sublicense, and/or sell copies of the Software,
cannam@89 17 * and to permit persons to whom the Software is furnished to do so,
cannam@89 18 * subject to the following conditions:
cannam@89 19 *
cannam@89 20 * The above copyright notice and this permission notice shall be
cannam@89 21 * included in all copies or substantial portions of the Software.
cannam@89 22 *
cannam@89 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@89 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@89 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
cannam@89 26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
cannam@89 27 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@89 28 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@89 29 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@89 30 */
cannam@89 31
cannam@89 32 /*
cannam@89 33 * The text above constitutes the entire PortAudio license; however,
cannam@89 34 * the PortAudio community also makes the following non-binding requests:
cannam@89 35 *
cannam@89 36 * Any person wishing to distribute modifications to the Software is
cannam@89 37 * requested to send the modifications to the original developer so that
cannam@89 38 * they can be incorporated into the canonical version. It is also
cannam@89 39 * requested that these non-binding requests be included along with the
cannam@89 40 * license above.
cannam@89 41 */
cannam@89 42
cannam@89 43
cannam@89 44 #include "stdio.h"
cannam@89 45 #include "portaudio.h"
cannam@89 46 /* This will be called asynchronously by the PortAudio engine. */
cannam@89 47 static int myCallback( const void *inputBuffer, void *outputBuffer,
cannam@89 48 unsigned long framesPerBuffer,
cannam@89 49 const PaStreamCallbackTimeInfo* timeInfo,
cannam@89 50 PaStreamCallbackFlags statusFlags,
cannam@89 51 void *userData )
cannam@89 52 {
cannam@89 53 const float *in = (const float *) inputBuffer;
cannam@89 54 float *out = (float *) outputBuffer;
cannam@89 55 float leftInput, rightInput;
cannam@89 56 unsigned int i;
cannam@89 57
cannam@89 58 /* Read input buffer, process data, and fill output buffer. */
cannam@89 59 for( i=0; i<framesPerBuffer; i++ )
cannam@89 60 {
cannam@89 61 leftInput = *in++; /* Get interleaved samples from input buffer. */
cannam@89 62 rightInput = *in++;
cannam@89 63 *out++ = leftInput * rightInput; /* ring modulation */
cannam@89 64 *out++ = 0.5f * (leftInput + rightInput); /* mix */
cannam@89 65 }
cannam@89 66 return 0;
cannam@89 67 }
cannam@89 68
cannam@89 69 /* Open a PortAudioStream to input and output audio data. */
cannam@89 70 int main(void)
cannam@89 71 {
cannam@89 72 PaStream *stream;
cannam@89 73 Pa_Initialize();
cannam@89 74 Pa_OpenDefaultStream(
cannam@89 75 &stream,
cannam@89 76 2, 2, /* stereo input and output */
cannam@89 77 paFloat32, 44100.0,
cannam@89 78 64, /* 64 frames per buffer */
cannam@89 79 myCallback, NULL );
cannam@89 80 Pa_StartStream( stream );
cannam@89 81 Pa_Sleep( 10000 ); /* Sleep for 10 seconds while processing. */
cannam@89 82 Pa_StopStream( stream );
cannam@89 83 Pa_CloseStream( stream );
cannam@89 84 Pa_Terminate();
cannam@89 85 return 0;
cannam@89 86 }