annotate src/portaudio_20161030/test/patest_ringmix.c @ 169:223a55898ab9 tip default

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