gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

patest_ringmix.c (3317B)


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