From: wittend99 Date: Tue, 15 May 2012 13:44:23 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@465 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=5ef0d64ce4010efe7ebb650f946b376675257b3b;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@465 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/thread_audio.cpp b/fdmdv2/thread_audio.cpp new file mode 100644 index 00000000..889bf732 --- /dev/null +++ b/fdmdv2/thread_audio.cpp @@ -0,0 +1,56 @@ +//========================================================================== +// Name: thread_audio.cpp +// +// Purpose: Implements simple wxWidgets application with GUI. +// Created: May 11, 2012 +// Initial author: David Witten +// License: BSD License (other licenses may apply to other +// components of this project) +//========================================================================== +#include "thread_audio.h" + +// declare a new type of event, to be used by our MyThread class: +wxDECLARE_EVENT(wxEVT_COMMAND_AUDIOTHREAD_COMPLETED, wxThreadEvent); +wxDECLARE_EVENT(wxEVT_COMMAND_AUDIOTHREAD_UPDATE, wxThreadEvent); + +#include "stdio.h" +#include "portaudio.h" + +/* This will be called asynchronously by the PortAudio engine. */ +static int audioCallback( void *inputBuffer, void *outputBuffer, + +unsigned long framesPerBuffer, PaTimestamp outTime, void *userData ) +{ + float *out = (float *) outputBuffer; + float *in = (float *) inputBuffer; + float leftInput, rightInput; + unsigned int i; + + if( inputBuffer == NULL ) + { + return 0; + } + /* Read input buffer, process data, and fill output buffer. */ + for(i = 0; i < framesPerBuffer; i++) + { + leftInput = *in++; /* Get interleaved samples from input buffer. */ + rightInput = *in++; + *out++ = leftInput * rightInput; /* ring modulation */ + *out++ = 0.5f * (leftInput + rightInput); /* mixing */ + } + return 0; +} +/* Use a PortAudioStream to process audio data. */ +int main(void) +{ + PortAudioStream *stream; + Pa_Initialize(); + //Pa_OpenDefaultStream(&stream, 2, 2, /* stereo input and output */ paFloat32, 44100.0, 64, 0, /* 64 frames per buffer, let PA determine numBuffers */audioCallback, NULL ); + Pa_OpenDefaultStream(&stream, 2, 2, paFloat32, 44100.0, 64, 0, audioCallback, NULL ); + Pa_StartStream( stream ); + Pa_Sleep( 10000 ); /* Sleep for 10 seconds while processing. */ + Pa_StopStream( stream ); + Pa_CloseStream( stream ); + Pa_Terminate(); + return 0; +}