+++ /dev/null
-//============================================================
-// AudioStream.h
-//
-//
-//============================================================
-#include "audiostream.h"\r
-
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=\r
-// Class AudioStream constructor
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=\r
-AudioStream::AudioStream(int tableSize) : tableSize_(tableSize), leftPhase_(0), rightPhase_(0)
-{
- const double PI = 3.14159265;
- table_ = new float[tableSize];
- for (int i = 0; i < tableSize; ++i)
- {
- table_[i] = 0.125f * (float)sin(((double)i/(double)tableSize)*PI*2.);
- }
-}
-
-//------------------------------------------------------------
-// Class AudioStream destructor
-//------------------------------------------------------------
-AudioStream::~AudioStream()
-{
- delete[] table_;
-}
-
-//------------------------------------------------------------
-// generate()
-//------------------------------------------------------------
-int AudioStream::generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
-{
- assert(outputBuffer != NULL);
-
- float **out = static_cast<float **>(outputBuffer);
-
- for (unsigned int i = 0; i < framesPerBuffer; ++i)
- {
- out[0][i] = table_[leftPhase_];
- out[1][i] = table_[rightPhase_];
-
- leftPhase_ += 1;
- if (leftPhase_ >= tableSize_)
- leftPhase_ -= tableSize_;
-
- rightPhase_ += 3;
- if (rightPhase_ >= tableSize_)
- rightPhase_ -= tableSize_;
- }
-
- return paContinue;
-}
-\r
-//------------------------------------------------------------
-// Open()
-//------------------------------------------------------------
-void AudioStream::Open()
-{
- wxString estr;\r
- try\r
- {\r
- // Create a SineGenerator object:\r
- AudioStream AudioStream(TABLE_SIZE);\r
-\r
- // Set up the System:\r
- portaudio::AutoSystem autoSys;\r
- portaudio::System &sys = portaudio::System::instance();\r
- // Set up the parameters required to open a (Callback)Stream:\r
- portaudio::DirectionSpecificStreamParameters outParams(sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false, sys.defaultOutputDevice().defaultLowOutputLatency(), NULL);\r
- portaudio::StreamParameters params(portaudio::DirectionSpecificStreamParameters::null(), outParams, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff);\r
-\r
- wxMessageBox(wxT("Opening stereo output stream..."), wxT("Info"), wxOK);\r
- // Create (and open) a new Stream, using the SineGenerator::generate function as a callback:\r
- portaudio::MemFunCallbackStream<AudioStream> stream(params, AudioStream, &AudioStream::generate);\r
- wxMessageBox(wxT("Starting playback for %i seconds."), wxT("Info"), wxOK);\r
- // Start the Stream (audio playback starts):\r
-// stream.start();\r
- // Wait for 5 seconds:\r
- sys.sleep(NUM_SECONDS * 1000);\r
- wxMessageBox(wxT("Closing stream..."), wxT("Info"), wxOK);\r
- // Stop the Stream (not strictly needed as termintating the System will also stop all open Streams):\r
-// stream.stop();\r
- // Close the Stream (not strictly needed as terminating the System will also close all open Streams):\r
-// stream.close();\r
- // Terminate the System (not strictly needed as the AutoSystem will also take care of this when it\r
- // goes out of scope):\r
- sys.terminate();\r
- wxMessageBox(wxT("Test finished."), wxT(""), wxOK);\r
- }\r
- catch (const portaudio::PaException &e)\r
- {\r
- estr.Format(wxT("A PortAudio error occured: %s"), e.paErrorText());\r
- wxMessageBox(estr, wxT("Error"), wxOK);\r
- }\r
- catch (const portaudio::PaCppException &e)\r
- {\r
- estr.Format(wxT("A PortAudioCpp error occured: %s"), e.what());\r
- wxMessageBox(estr, wxT("Error"), wxOK);\r
- }\r
- catch (const std::exception &e)\r
- {\r
- estr.Format(wxT("A generic exception occured: %s"), e.what());\r
- wxMessageBox(estr, wxT("Error"), wxOK);\r
- }\r
- catch (...)\r
- {\r
- wxMessageBox(wxT("An unknown exception occured."), wxT("Error"), wxOK);\r
- }\r
-}\r