annotate src/portaudio_20140130/test/patest_ringmix.c @ 81:7029a4916348

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