annotate src/portaudio_20140130/test/patest_ringmix.c @ 124:e3d5853d5918

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