git-svn-id: https://svn.code.sf.net/p/freetel/code@465 01035d8c-6547-0410-b346-abe4f9...
authorwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 15 May 2012 13:44:23 +0000 (13:44 +0000)
committerwittend99 <wittend99@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 15 May 2012 13:44:23 +0000 (13:44 +0000)
fdmdv2/thread_audio.cpp [new file with mode: 0644]

diff --git a/fdmdv2/thread_audio.cpp b/fdmdv2/thread_audio.cpp
new file mode 100644 (file)
index 0000000..889bf73
--- /dev/null
@@ -0,0 +1,56 @@
+//==========================================================================\r
+// Name:            thread_audio.cpp\r
+//\r
+// Purpose:         Implements simple wxWidgets application with GUI.\r
+// Created:         May 11, 2012
+// Initial author:  David Witten\r
+// License:         BSD License (other licenses may apply to other\r
+//                  components of this project)\r
+//==========================================================================\r
+#include "thread_audio.h"\r
+\r
+// declare a new type of event, to be used by our MyThread class:\r
+wxDECLARE_EVENT(wxEVT_COMMAND_AUDIOTHREAD_COMPLETED, wxThreadEvent);\r
+wxDECLARE_EVENT(wxEVT_COMMAND_AUDIOTHREAD_UPDATE, wxThreadEvent);\r
+\r
+#include "stdio.h"\r
+#include "portaudio.h"\r
+\r
+/* This will be called asynchronously by the PortAudio engine. */\r
+static int audioCallback( void *inputBuffer, void *outputBuffer,\r
+\r
+unsigned long framesPerBuffer, PaTimestamp outTime, void *userData )\r
+{\r
+    float *out = (float *) outputBuffer;\r
+    float *in = (float *) inputBuffer;\r
+    float leftInput, rightInput;\r
+    unsigned int i;\r
+\r
+    if( inputBuffer == NULL )\r
+    {\r
+        return 0;\r
+    }\r
+    /* Read input buffer, process data, and fill output buffer. */\r
+    for(i = 0; i < framesPerBuffer; i++)\r
+    {\r
+        leftInput = *in++;                          /* Get interleaved samples from input buffer. */\r
+        rightInput = *in++;\r
+        *out++ = leftInput * rightInput;            /* ring modulation */\r
+        *out++ = 0.5f * (leftInput + rightInput);   /* mixing */\r
+    }\r
+    return 0;\r
+}\r
+/* Use a PortAudioStream to process audio data. */\r
+int main(void)\r
+{\r
+    PortAudioStream *stream;\r
+    Pa_Initialize();\r
+    //Pa_OpenDefaultStream(&stream, 2, 2, /* stereo input and output */ paFloat32, 44100.0, 64, 0, /* 64 frames per buffer, let PA determine numBuffers */audioCallback, NULL );\r
+    Pa_OpenDefaultStream(&stream, 2, 2, paFloat32, 44100.0, 64, 0, audioCallback, NULL );\r
+    Pa_StartStream( stream );\r
+    Pa_Sleep( 10000 );                              /* Sleep for 10 seconds while processing. */\r
+    Pa_StopStream( stream );\r
+    Pa_CloseStream( stream );\r
+    Pa_Terminate();\r
+    return 0;\r
+}\r