annotate src/portaudio/test/patest_ringmix.c @ 46:efe5b9f38b13

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