From: wittend99 Date: Fri, 15 Jun 2012 14:26:24 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@551 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=78c784be05f87026488c8419273906207b4ec0f8;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@551 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/.clang/.gitignore b/fdmdv2/.clang/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/fdmdv2/audiostream.cpp b/fdmdv2/audiostream.cpp new file mode 100644 index 00000000..afb66d59 --- /dev/null +++ b/fdmdv2/audiostream.cpp @@ -0,0 +1,110 @@ +//============================================================ +// AudioStream.h +// +// +//============================================================ +#include "audiostream.h" + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// Class AudioStream constructor +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +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(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; +} + +//------------------------------------------------------------ +// Open() +//------------------------------------------------------------ +void AudioStream::Open() +{ + wxString estr; + try + { + // Create a SineGenerator object: + AudioStream AudioStream(TABLE_SIZE); + + // Set up the System: + portaudio::AutoSystem autoSys; + portaudio::System &sys = portaudio::System::instance(); + // Set up the parameters required to open a (Callback)Stream: + portaudio::DirectionSpecificStreamParameters outParams(sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false, sys.defaultOutputDevice().defaultLowOutputLatency(), NULL); + portaudio::StreamParameters params(portaudio::DirectionSpecificStreamParameters::null(), outParams, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff); + + wxMessageBox(wxT("Opening stereo output stream..."), wxT("Info"), wxOK); + // Create (and open) a new Stream, using the SineGenerator::generate function as a callback: + portaudio::MemFunCallbackStream stream(params, AudioStream, &AudioStream::generate); + wxMessageBox(wxT("Starting playback for %i seconds."), wxT("Info"), wxOK); + // Start the Stream (audio playback starts): +// stream.start(); + // Wait for 5 seconds: + sys.sleep(NUM_SECONDS * 1000); + wxMessageBox(wxT("Closing stream..."), wxT("Info"), wxOK); + // Stop the Stream (not strictly needed as termintating the System will also stop all open Streams): +// stream.stop(); + // Close the Stream (not strictly needed as terminating the System will also close all open Streams): +// stream.close(); + // Terminate the System (not strictly needed as the AutoSystem will also take care of this when it + // goes out of scope): + sys.terminate(); + wxMessageBox(wxT("Test finished."), wxT(""), wxOK); + } + catch (const portaudio::PaException &e) + { + estr.Format(wxT("A PortAudio error occured: %s"), e.paErrorText()); + wxMessageBox(estr, wxT("Error"), wxOK); + } + catch (const portaudio::PaCppException &e) + { + estr.Format(wxT("A PortAudioCpp error occured: %s"), e.what()); + wxMessageBox(estr, wxT("Error"), wxOK); + } + catch (const std::exception &e) + { + estr.Format(wxT("A generic exception occured: %s"), e.what()); + wxMessageBox(estr, wxT("Error"), wxOK); + } + catch (...) + { + wxMessageBox(wxT("An unknown exception occured."), wxT("Error"), wxOK); + } +} diff --git a/fdmdv2/audiostream.h b/fdmdv2/audiostream.h new file mode 100644 index 00000000..f3562de9 --- /dev/null +++ b/fdmdv2/audiostream.h @@ -0,0 +1,46 @@ +//============================================================ +// AudioStream.h +// +// +//============================================================ +#include +#include +#include +#include "portaudiocpp/PortAudioCpp.hxx" +#include +#include +#include "libsndfile/include/sndfile.h" +#include "extern/include/portaudio.h" +#include "extern/include/portaudiocpp/PortAudioCpp.hxx" + +#ifndef __AudioStream__ +#define __AudioStream__ + +const int NUM_SECONDS = 5; +const double SAMPLE_RATE = 44100.0; +const int FRAMES_PER_BUFFER = 64; +const int TABLE_SIZE = 200; + +class AudioStream +{ +public: +// AudioStream(int tableSize) : tableSize_(tableSize), leftPhase_(0), rightPhase_(0); + AudioStream(int tableSize); + ~AudioStream(); + + int generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags); + +private: + float *table_; + int tableSize_; + int leftPhase_; + int rightPhase_; + + void Open(); + +protected: + +private: +}; + +#endif // __AudioStream__ diff --git a/fdmdv2/fdmdv2.mk b/fdmdv2/fdmdv2.mk index 7e6365db..5350737d 100644 --- a/fdmdv2/fdmdv2.mk +++ b/fdmdv2/fdmdv2.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=wittend -Date :=6/12/2012 +Date :=6/15/2012 CodeLitePath :="C:\Program Files\CodeLite" LinkerName :=g++ ArchiveTool :=ar rcus @@ -52,7 +52,7 @@ LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)./libsndfile ## User defined environment variables ## CodeLiteDir:=C:\Program Files\CodeLite -WXWIN:=C:\bin\wxWidgets-2.9.2 +WXWIN:=C:\bin\wxWidgets-2.9.4 PATH:=$(WXWIN)\lib\gcc_dll;$(PATH) WXCFG:=gcc_dll\mswu UNIT_TEST_PP_SRC_DIR:=C:\bin\UnitTest++-1.3 diff --git a/fdmdv2/fdmdv2_main.cpp b/fdmdv2/fdmdv2_main.cpp index ae28ff61..b707ed16 100644 --- a/fdmdv2/fdmdv2_main.cpp +++ b/fdmdv2/fdmdv2_main.cpp @@ -44,16 +44,18 @@ bool MainApp::OnInit() } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -// Class MainFrame(wxFrame* parent) : TopFrame(parent) +// Class MainFrame(wxFrame* pa->ent) : TopFrame(pa->ent) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) { m_radioRunning = false; -// m_bitmap = bitmap; - m_sound = NULL; - m_zoom = 1.; - m_SquelchActive = false; - + m_sound = NULL; + m_zoom = 1.; + m_SquelchActive = false; + if(Pa_Initialize()) + { + wxMessageBox(wxT("Port Audio failed to initialize"), wxT("Pa_Initialize"), wxOK); + } } //------------------------------------------------------------------------- @@ -68,6 +70,7 @@ MainFrame::~MainFrame() //------------------------------------------------------------------------- void MainFrame::OnCloseFrame(wxCloseEvent& event) { + Pa_Terminate(); Destroy(); } @@ -80,7 +83,7 @@ void MainFrame::OnExitClick(wxCommandEvent& event) } //------------------------------------------------------------------------- -// OnPaint() +// Onpa->nt() //------------------------------------------------------------------------- void MainFrame::OnPaint(wxPaintEvent& WXUNUSED(event)) { @@ -160,7 +163,7 @@ void MainFrame::OnTogBtnTXClick(wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnRxID(wxCommandEvent& event) { - wxMessageBox("Got Click!", "OnTogBtnRxID", wxOK); + wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnRxID"), wxOK); event.Skip(); } @@ -169,7 +172,7 @@ void MainFrame::OnTogBtnRxID(wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnTxID(wxCommandEvent& event) { - wxMessageBox("Got Click!", "OnTogBtnTxID", wxOK); + wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnTxID"), wxOK); event.Skip(); } @@ -178,7 +181,7 @@ void MainFrame::OnTogBtnTxID(wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnSplitClick(wxCommandEvent& event) { - wxMessageBox("Got Click!", "OnTogBtnSplitClick", wxOK); + wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnSplitClick"), wxOK); event.Skip(); } @@ -187,7 +190,7 @@ void MainFrame::OnTogBtnSplitClick(wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnAnalogClick (wxCommandEvent& event) { - wxMessageBox("Got Click!", "OnTogBtnAnalogClick", wxOK); + wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnAnalogClick"), wxOK); event.Skip(); } @@ -196,38 +199,71 @@ void MainFrame::OnTogBtnAnalogClick (wxCommandEvent& event) //------------------------------------------------------------------------- void MainFrame::OnTogBtnALCClick(wxCommandEvent& event) { - wxMessageBox("Got Click!", "OnTogBtnALCClick", wxOK); + wxMessageBox(wxT("Got Click!"), wxT("OnTogBtnALCClick"), wxOK); event.Skip(); } +//------------------------------------------------------------------------- +// codec2Callback() +//------------------------------------------------------------------------- +static int codec2Callback( + const void *inBuffer, + void *outBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo *outTime, + PaStreamCallbackFlags statusFlags, + void *userData + ) +{ + float *out = (float *) outBuffer; + float *in = (float *) inBuffer; + float leftIn; + float rightIn; + unsigned int i; + + if(inBuffer == NULL) + { + return 0; + } + // Read input buffer, process data, and fill output buffer. + for(i = 0; i < framesPerBuffer; i++) + { + leftIn = *in++; // Get interleaved samples from input buffer. + rightIn = *in++; + *out++ = leftIn * rightIn; // ring modulation + *out++ = 0.5f * (leftIn + rightIn); // mixing + } + return paContinue; // 0; +} + //------------------------------------------------------------------------- // audioCallback() //------------------------------------------------------------------------- -static int audioCallback( const void *inputBuffer, - void *outputBuffer, +static int audioCallback( const void *inBuffer, + void *outBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags statusFlags, void *userData ) { - float *out = (float *) outputBuffer; - float *in = (float *) inputBuffer; - float leftInput; - float rightInput; + float *out = (float *) outBuffer; + float *in = (float *) inBuffer; + float leftIn; + float rightIn; unsigned int i; - if(inputBuffer == NULL) + if(inBuffer == 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 + leftIn = *in++; // Get interleaved samples from input buffer. + rightIn = *in++; + *out++ = leftIn * rightIn; // ring modulation + *out++ = 0.5f * (leftIn + rightIn); // mixing } return paContinue; // 0; } @@ -241,8 +277,8 @@ static int gNumNoInputs = 0; static int fuzzCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, + const pa->treamCallbackTimeInfo* timeInfo, + pa->treamCallbackFlags statusFlags, void *userData) { SAMPLE *out = (SAMPLE*)outputBuffer; @@ -269,7 +305,7 @@ static int fuzzCallback(const void *inputBuffer, *out++ = *in++; // right - clean } } - return paContinue; + return pa->ontinue; } */ @@ -278,53 +314,52 @@ static int fuzzCallback(const void *inputBuffer, //------------------------------------------------------------------------- void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) { - PortAudioWrap pa; if(!m_radioRunning) { m_radioRunning = true; - pa = PortAudioWrap(); - err = pa.init(); + pa = new PortAudioWrap(); +// err = pa->init(); - inputDevice = pa.getDefaultInputDevice(); // default input device + inputDevice = pa->getDefaultInputDevice(); // default input device if(inputDevice == paNoDevice) { - wxMessageBox("Error: No default input device.", "Error", wxOK); + wxMessageBox(wxT("Error: No default input device."), wxT("Error"), wxOK); return; } - err = pa.setInputDevice(inputDevice); - err = pa.setInputChannelCount(2); // stereo input - err = pa.setInputSampleFormat(PA_SAMPLE_TYPE); - err = pa.setInputLatency(pa.getInputDefaultLowLatency()); - pa.setInputHostApiStreamInfo(NULL); + err = pa->setInputDevice(inputDevice); + err = pa->setInputChannelCount(2); // stereo input + err = pa->setInputSampleFormat(PA_SAMPLE_TYPE); + err = pa->setInputLatency(pa->getInputDefaultLowLatency()); + pa->setInputHostApiStreamInfo(NULL); - outputDevice = pa.getDefaultOutputDevice(); // default output device + outputDevice = pa->getDefaultOutputDevice(); // default output device if (outputDevice == paNoDevice) { - wxMessageBox("Error: No default output device.", "Error", wxOK); + wxMessageBox(wxT("Error: No default output device."), wxT("Error"), wxOK); return; } - err = pa.setOutputDevice(outputDevice); - err = pa.setOutputChannelCount(2); // stereo input - err = pa.setOutputSampleFormat(PA_SAMPLE_TYPE); + err = pa->setOutputDevice(outputDevice); + err = pa->setOutputChannelCount(2); // stereo input + err = pa->setOutputSampleFormat(PA_SAMPLE_TYPE); - err = pa.setOutputLatency(pa.getOutputDefaultLowLatency()); - pa.setOutputHostApiStreamInfo(NULL); + err = pa->setOutputLatency(pa->getOutputDefaultLowLatency()); + pa->setOutputHostApiStreamInfo(NULL); - err = pa.setFramesPerBuffer(FRAMES_PER_BUFFER); - err = pa.setSampleRate(SAMPLE_RATE); - err = pa.setStreamFlags(0); - err = pa.setCallback(audioCallback); - err = pa.streamOpen(); + err = pa->setFramesPerBuffer(FRAMES_PER_BUFFER); + err = pa->setSampleRate(SAMPLE_RATE); + err = pa->setStreamFlags(0); + err = pa->setCallback(audioCallback); + err = pa->streamOpen(); if(err != paNoError) { - wxMessageBox("Open/Setup error.", "Error", wxOK); + wxMessageBox(wxT("Open/Setup error."), wxT("Error"), wxOK); return; } - err = pa.streamStart(); + err = pa->streamStart(); if(err != paNoError) { - wxMessageBox("Stream Start Error.", "Error", wxOK); + wxMessageBox(wxT("Stream Start Error."), wxT("Error"), wxOK); return; } m_togBtnOnOff->SetLabel(wxT("Stop")); @@ -332,7 +367,10 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) else { m_radioRunning = false; - pa.terminate(); + pa->stop(); +// pa->abort(); +// delete pa; + //pa->terminate(); m_togBtnOnOff->SetLabel(wxT("Start")); } } @@ -367,10 +405,10 @@ void MainFrame::OnOpen( wxCommandEvent& event ) m_sound->Play(openFileDialog.GetPath()); /* // this can be done with e.g. wxWidgets input streams: - wxFileInputStream input_stream(openFileDialog.GetPath()); + wxFileInputStream input_stream(openFileDialog.Getpa->h()); if (!input_stream.IsOk()) { - wxLogError("Cannot open file '%s'.", openFileDialog.GetPath()); + wxLogError("Cannot open file '%s'.", openFileDialog.Getpa->h()); return; } */ @@ -464,7 +502,7 @@ void MainFrame::OnCutUpdateUI( wxUpdateUIEvent& event ) //------------------------------------------------------------------------- void MainFrame::OnPaste( wxCommandEvent& event ) { - wxMessageBox("Got Click!", "OnPaste", wxOK); + wxMessageBox("Got Click!", "Onpa->te", wxOK); event.Skip(); } @@ -541,7 +579,7 @@ void MainFrame::OnHelpCheckUpdatesUI( wxUpdateUIEvent& event ) } //------------------------------------------------------------------------- -// OnHelpAbout() +//OnHelpAbout() //------------------------------------------------------------------------- void MainFrame::OnHelpAbout( wxCommandEvent& event ) { @@ -616,7 +654,7 @@ void MainFrame::OnSave(wxCommandEvent& WXUNUSED(event)) wxT("8 bpp color"), wxT("8 bpp greyscale"), wxT("8 bpp red"), - wxT("8 bpp own palette"), + wxT("8 bpp own pa->ette"), wxT("24 bpp") }; diff --git a/fdmdv2/fdmdv2_main.h b/fdmdv2/fdmdv2_main.h index 097914e4..edcf8c52 100644 --- a/fdmdv2/fdmdv2_main.h +++ b/fdmdv2/fdmdv2_main.h @@ -29,7 +29,8 @@ //#include "extern/include/portaudiocpp/PortAudioCpp.hxx" #include "topFrame.h" -#include "codec2.h" +#include "C:\Users\wittend\Projects\Radio\codec2-dev\src\codec2.h" +#include "C:\Users\wittend\Projects\Radio\codec2-dev\src\fdmdv.h" #include "dlg_about.h" #include "dlg_audio.h" #include "dlg_options.h" @@ -84,6 +85,7 @@ class MainFrame : public TopFrame bool m_SquelchActive; CODEC2 *m_RXCodec2; CODEC2 *m_TXCodec2; + PortAudioWrap *pa; PaError err; PaDeviceIndex inputDevice; PaDeviceIndex outputDevice; diff --git a/fdmdv2/fdmdv2_thread_audio.cpp b/fdmdv2/fdmdv2_thread_audio.cpp deleted file mode 100644 index 4d17ea41..00000000 --- a/fdmdv2/fdmdv2_thread_audio.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "fdmdv2_thread_audio.h" - -//namespace NSfdmdv2Audio -//{ - - Fdmdv2ThreadAudio::Fdmdv2ThreadAudio() - { - } - - Fdmdv2ThreadAudio::~Fdmdv2ThreadAudio() - { - } - - void* Fdmdv2ThreadAudio::Entry() - { - return NULL; - } - void Fdmdv2ThreadAudio::OnDelete() - { - } - void Fdmdv2ThreadAudio::OnExit() - { - } - void Fdmdv2ThreadAudio::OnKill() - { - } -// bool Fdmdv2ThreadAudio::TestDestroy() -// { -// } -//} diff --git a/fdmdv2/fdmdv2_wsp.mk b/fdmdv2/fdmdv2_wsp.mk index b319cb16..dd8060fa 100644 --- a/fdmdv2/fdmdv2_wsp.mk +++ b/fdmdv2/fdmdv2_wsp.mk @@ -1,8 +1,8 @@ .PHONY: clean All All: - @echo ----------Building project:[ test_sndfile - Debug ]---------- - @cd "libsndfile\Projects\w32-mingw" && "mingw32-make.exe" -j 2 -f "test_sndfile.mk" + @echo ----------Building project:[ fdmdv2 - Debug ]---------- + @"mingw32-make.exe" -j 2 -f "fdmdv2.mk" clean: - @echo ----------Cleaning project:[ test_sndfile - Debug ]---------- - @cd "libsndfile\Projects\w32-mingw" && "mingw32-make.exe" -j 2 -f "test_sndfile.mk" clean + @echo ----------Cleaning project:[ fdmdv2 - Debug ]---------- + @"mingw32-make.exe" -j 2 -f "fdmdv2.mk" clean diff --git a/fdmdv2/paclass.cpp b/fdmdv2/paclass.cpp index bac2f6dc..ba731ebf 100644 --- a/fdmdv2/paclass.cpp +++ b/fdmdv2/paclass.cpp @@ -2,24 +2,24 @@ PortAudioWrap::PortAudioWrap() { - stream = NULL; - userData = NULL; - samplerate = 0; - framesPerBuffer = 0; - statusFlags = 0; - streamCallback = NULL; - streamFinishedCallback = NULL; - timeInfo = 0; + stream = NULL; + userData = NULL; + samplerate = 0; + framesPerBuffer = 0; + statusFlags = 0; + streamCallback = NULL; + streamFinishedCallback = NULL; + timeInfo = 0; } PortAudioWrap::~PortAudioWrap() { } -PaError PortAudioWrap::init() -{ - return Pa_Initialize(); -} +//PaError PortAudioWrap::init() +//{ +// return Pa_Initialize(); +//} PaError PortAudioWrap::streamOpen() { @@ -37,15 +37,15 @@ PaError PortAudioWrap::streamOpen() PaError PortAudioWrap::streamStart() { - return Pa_StartStream(this->stream); + return Pa_StartStream(stream); } PaError PortAudioWrap::streamClose() { if(isOpen()) { - PaError rv = Pa_CloseStream(this->stream); - this->stream = NULL; + PaError rv = Pa_CloseStream(stream); +// stream = NULL; return rv; } else diff --git a/fdmdv2/paclass.h b/fdmdv2/paclass.h index f7418f83..c7a9b946 100644 --- a/fdmdv2/paclass.h +++ b/fdmdv2/paclass.h @@ -30,8 +30,8 @@ class PortAudioWrap PaStreamCallback *streamCallback; PaStreamFinishedCallback *streamFinishedCallback; const PaStreamCallbackTimeInfo *timeInfo; - PaDeviceIndex inputDevice; - PaDeviceIndex outputDevice; +// PaDeviceIndex inputDevice; +// PaDeviceIndex outputDevice; public: @@ -66,7 +66,7 @@ class PortAudioWrap void setOutputHostApiStreamInfo(void *info = NULL); PaTime getOutputDefaultLowLatency(); - PaError init(); +// PaError init(); PaError streamStart(); PaError streamClose(); void terminate();