From: wittend99 Date: Wed, 22 Aug 2012 17:33:04 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@636 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=00d6d8ac0fe858c807210585a78dc3aaa53392f4;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@636 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/build/Release/fdmdv2.exe b/fdmdv2/build/Release/fdmdv2.exe index c8875b6e..43dae154 100644 Binary files a/fdmdv2/build/Release/fdmdv2.exe and b/fdmdv2/build/Release/fdmdv2.exe differ diff --git a/fdmdv2/build/fdmdv2.mk b/fdmdv2/build/fdmdv2.mk index 2fe87495..d6da8782 100644 --- a/fdmdv2/build/fdmdv2.mk +++ b/fdmdv2/build/fdmdv2.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=OFA-Staff -Date :=8/20/2012 +Date :=8/22/2012 CodeLitePath :="C:\bin\CodeLite" LinkerName :=g++ ArchiveTool :=ar rcus @@ -56,7 +56,8 @@ 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 -Objects=$(IntermediateDirectory)/src_dlg_about$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_audio$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_comports$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_options$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_main$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_plot$(ObjectSuffix) $(IntermediateDirectory)/src_paclass$(ObjectSuffix) $(IntermediateDirectory)/src_topFrame$(ObjectSuffix) +Objects=$(IntermediateDirectory)/src_dlg_about$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_audio$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_comports$(ObjectSuffix) $(IntermediateDirectory)/src_dlg_options$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_main$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_plot$(ObjectSuffix) $(IntermediateDirectory)/src_topFrame$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(ObjectSuffix) \ + $(IntermediateDirectory)/src_fdmdv2_scalar$(ObjectSuffix) $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(ObjectSuffix) ## ## Main Build Targets @@ -127,14 +128,6 @@ $(IntermediateDirectory)/src_fdmdv2_plot$(DependSuffix): ../src/fdmdv2_plot.cpp $(IntermediateDirectory)/src_fdmdv2_plot$(PreprocessSuffix): ../src/fdmdv2_plot.cpp @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_plot$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot.cpp" -$(IntermediateDirectory)/src_paclass$(ObjectSuffix): ../src/paclass.cpp $(IntermediateDirectory)/src_paclass$(DependSuffix) - $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/paclass.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_paclass$(ObjectSuffix) $(IncludePath) -$(IntermediateDirectory)/src_paclass$(DependSuffix): ../src/paclass.cpp - @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_paclass$(ObjectSuffix) -MF$(IntermediateDirectory)/src_paclass$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/paclass.cpp" - -$(IntermediateDirectory)/src_paclass$(PreprocessSuffix): ../src/paclass.cpp - @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_paclass$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/paclass.cpp" - $(IntermediateDirectory)/src_topFrame$(ObjectSuffix): ../src/topFrame.cpp $(IntermediateDirectory)/src_topFrame$(DependSuffix) $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/topFrame.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_topFrame$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/src_topFrame$(DependSuffix): ../src/topFrame.cpp @@ -143,6 +136,46 @@ $(IntermediateDirectory)/src_topFrame$(DependSuffix): ../src/topFrame.cpp $(IntermediateDirectory)/src_topFrame$(PreprocessSuffix): ../src/topFrame.cpp @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_topFrame$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/topFrame.cpp" +$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(ObjectSuffix): ../src/fdmdv2_plot_scatter.cpp $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_scatter.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(DependSuffix): ../src/fdmdv2_plot_scatter.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(ObjectSuffix) -MF$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_scatter.cpp" + +$(IntermediateDirectory)/src_fdmdv2_plot_scatter$(PreprocessSuffix): ../src/fdmdv2_plot_scatter.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_scatter.cpp" + +$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(ObjectSuffix): ../src/fdmdv2_plot_waterfall.cpp $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_waterfall.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(DependSuffix): ../src/fdmdv2_plot_waterfall.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(ObjectSuffix) -MF$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_waterfall.cpp" + +$(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(PreprocessSuffix): ../src/fdmdv2_plot_waterfall.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_waterfall.cpp" + +$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(ObjectSuffix): ../src/fdmdv2_plot_spectrum.cpp $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_spectrum.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(DependSuffix): ../src/fdmdv2_plot_spectrum.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(ObjectSuffix) -MF$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_spectrum.cpp" + +$(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(PreprocessSuffix): ../src/fdmdv2_plot_spectrum.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_plot_spectrum.cpp" + +$(IntermediateDirectory)/src_fdmdv2_scalar$(ObjectSuffix): ../src/fdmdv2_scalar.cpp $(IntermediateDirectory)/src_fdmdv2_scalar$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_scalar.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_fdmdv2_scalar$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src_fdmdv2_scalar$(DependSuffix): ../src/fdmdv2_scalar.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_fdmdv2_scalar$(ObjectSuffix) -MF$(IntermediateDirectory)/src_fdmdv2_scalar$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_scalar.cpp" + +$(IntermediateDirectory)/src_fdmdv2_scalar$(PreprocessSuffix): ../src/fdmdv2_scalar.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_scalar$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_scalar.cpp" + +$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(ObjectSuffix): ../src/fdmdv2_pa_wrapper.cpp $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_pa_wrapper.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(DependSuffix): ../src/fdmdv2_pa_wrapper.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(ObjectSuffix) -MF$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(DependSuffix) -MM "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_pa_wrapper.cpp" + +$(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(PreprocessSuffix): ../src/fdmdv2_pa_wrapper.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(PreprocessSuffix) "C:/bin/Projects/Radio/fdmdv2/src/fdmdv2_pa_wrapper.cpp" + -include $(IntermediateDirectory)/*$(DependSuffix) ## @@ -167,12 +200,24 @@ clean: $(RM) $(IntermediateDirectory)/src_fdmdv2_plot$(ObjectSuffix) $(RM) $(IntermediateDirectory)/src_fdmdv2_plot$(DependSuffix) $(RM) $(IntermediateDirectory)/src_fdmdv2_plot$(PreprocessSuffix) - $(RM) $(IntermediateDirectory)/src_paclass$(ObjectSuffix) - $(RM) $(IntermediateDirectory)/src_paclass$(DependSuffix) - $(RM) $(IntermediateDirectory)/src_paclass$(PreprocessSuffix) $(RM) $(IntermediateDirectory)/src_topFrame$(ObjectSuffix) $(RM) $(IntermediateDirectory)/src_topFrame$(DependSuffix) $(RM) $(IntermediateDirectory)/src_topFrame$(PreprocessSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(DependSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_scatter$(PreprocessSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(DependSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_waterfall$(PreprocessSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(DependSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_spectrum$(PreprocessSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_scalar$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_scalar$(DependSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_scalar$(PreprocessSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(DependSuffix) + $(RM) $(IntermediateDirectory)/src_fdmdv2_pa_wrapper$(PreprocessSuffix) $(RM) $(OutputFile) $(RM) $(OutputFile).exe $(RM) "C:\bin\Projects\Radio\fdmdv2\build\.build-release\fdmdv2" diff --git a/fdmdv2/build/fdmdv2.project b/fdmdv2/build/fdmdv2.project index b44fc174..13f23b04 100644 --- a/fdmdv2/build/fdmdv2.project +++ b/fdmdv2/build/fdmdv2.project @@ -14,8 +14,12 @@ - + + + + + @@ -24,7 +28,6 @@ - @@ -52,6 +55,11 @@ + + + + + diff --git a/fdmdv2/build/fdmdv2.txt b/fdmdv2/build/fdmdv2.txt index 89acdf59..72cab8da 100644 --- a/fdmdv2/build/fdmdv2.txt +++ b/fdmdv2/build/fdmdv2.txt @@ -1 +1 @@ -./Release/src_dlg_about.o ./Release/src_dlg_audio.o ./Release/src_dlg_comports.o ./Release/src_dlg_options.o ./Release/src_fdmdv2_main.o ./Release/src_fdmdv2_plot.o ./Release/src_paclass.o ./Release/src_topFrame.o +./Release/src_dlg_about.o ./Release/src_dlg_audio.o ./Release/src_dlg_comports.o ./Release/src_dlg_options.o ./Release/src_fdmdv2_main.o ./Release/src_fdmdv2_plot.o ./Release/src_topFrame.o ./Release/src_fdmdv2_plot_scatter.o ./Release/src_fdmdv2_plot_waterfall.o ./Release/src_fdmdv2_plot_spectrum.o ./Release/src_fdmdv2_scalar.o ./Release/src_fdmdv2_pa_wrapper.o diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 34d3c72c..37d36b90 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -26,17 +26,30 @@ #include "sndfile.h" #include "portaudio.h" -#include "paclass.h" +#include "fdmdv2_pa_wrapper.h" #include "codec2.h" #include "fdmdv.h" +#define MIN_DB -40.0 +#define MAX_DB 0.0 +#define BETA 0.1 // constant for time averageing spectrum data +#define MIN_HZ 0 +#define MAX_HZ 4000 +#define WATERFALL_SECS_Y 5 // number of seconds respresented by y axis of waterfall +#define DT 0.02 // time between samples +#define FS 8000 // FDMDV modem sample rate + #include "topFrame.h" #include "dlg_about.h" #include "dlg_audio.h" #include "dlg_options.h" #include "dlg_comports.h" #include "fdmdv2_plot.h" +#include "fdmdv2_scalar.h" +#include "fdmdv2_plot_scatter.h" +#include "fdmdv2_plot_waterfall.h" +#include "fdmdv2_plot_spectrum.h" enum { diff --git a/fdmdv2/src/fdmdv2_pa_wrapper.cpp b/fdmdv2/src/fdmdv2_pa_wrapper.cpp new file mode 100644 index 00000000..d427d4ec --- /dev/null +++ b/fdmdv2/src/fdmdv2_pa_wrapper.cpp @@ -0,0 +1,212 @@ +#include "fdmdv2_pa_wrapper.h" + +PortAudioWrap::PortAudioWrap() +{ + 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::streamOpen() +{ + return Pa_OpenStream( + &stream, + &inputBuffer, + &outputBuffer, + samplerate, + framesPerBuffer, + statusFlags, + *streamCallback, + userData + ); +} + +PaError PortAudioWrap::streamStart() +{ + return Pa_StartStream(stream); +} + +PaError PortAudioWrap::streamClose() +{ + if(isOpen()) + { + PaError rv = Pa_CloseStream(stream); +// stream = NULL; + return rv; + } + else + { + return paNoError; + } +} + +void PortAudioWrap::terminate() +{ + if(Pa_IsStreamStopped(stream) != paNoError) + { + Pa_StopStream(stream); + } + Pa_Terminate(); +} + +void PortAudioWrap::stop() +{ + Pa_StopStream(stream); +} + +void PortAudioWrap::abort() +{ + Pa_AbortStream(stream); +} + +bool PortAudioWrap::isStopped() const +{ + PaError ret = Pa_IsStreamStopped(stream); + return ret; +} + +bool PortAudioWrap::isActive() const +{ + PaError ret = Pa_IsStreamActive(stream); + return ret; +} + +bool PortAudioWrap::isOpen() const +{ + return (stream != NULL); +} + +PaDeviceIndex PortAudioWrap::getDefaultInputDevice() +{ + return Pa_GetDefaultInputDevice(); +} + +PaDeviceIndex PortAudioWrap::getDefaultOutputDevice() +{ + return Pa_GetDefaultOutputDevice(); +} + +PaError PortAudioWrap::setInputChannelCount(int count) +{ + inputBuffer.channelCount = count; + return paNoError; +} + +PaError PortAudioWrap::getInputChannelCount() +{ + return inputBuffer.channelCount; +} + +PaError PortAudioWrap::setInputSampleFormat(PaSampleFormat format) +{ + inputBuffer.sampleFormat = format; + return paNoError; +} + +PaError PortAudioWrap::setInputLatency(PaTime latency) +{ + inputBuffer.suggestedLatency = latency; + return paNoError; +} + +void PortAudioWrap::setInputHostApiStreamInfo(void *info) +{ + inputBuffer.hostApiSpecificStreamInfo = info; +} + +PaTime PortAudioWrap::getInputDefaultLowLatency() +{ + return Pa_GetDeviceInfo(inputBuffer.device)->defaultLowInputLatency; +} + +PaError PortAudioWrap::setOutputChannelCount(int count) +{ + outputBuffer.channelCount = count; + return paNoError; +} + +const int PortAudioWrap::getOutputChannelCount() +{ + return outputBuffer.channelCount; +} + +const char *PortAudioWrap::getDeviceName(PaDeviceIndex dev) +{ + const PaDeviceInfo *info; + info = Pa_GetDeviceInfo(dev); + return info->name; +} + +PaError PortAudioWrap::setOutputSampleFormat(PaSampleFormat format) +{ + outputBuffer.sampleFormat = format; + return paNoError; +} + +PaError PortAudioWrap::setOutputLatency(PaTime latency) +{ + outputBuffer.suggestedLatency = latency; + return paNoError; +} + +void PortAudioWrap::setOutputHostApiStreamInfo(void *info) +{ + outputBuffer.hostApiSpecificStreamInfo = info; +} + +PaTime PortAudioWrap::getOutputDefaultLowLatency() +{ + return Pa_GetDeviceInfo(outputBuffer.device)->defaultLowOutputLatency; +} + +PaError PortAudioWrap::setFramesPerBuffer(unsigned long size) +{ + framesPerBuffer = size; + return paNoError; +} + +PaError PortAudioWrap::setSampleRate(unsigned long rate) +{ + samplerate = rate; + return paNoError; +} + +PaError PortAudioWrap::setStreamFlags(PaStreamFlags flags) +{ + statusFlags = flags; + return paNoError; +} + +PaError PortAudioWrap::setInputDevice(PaDeviceIndex index) +{ +// inputDevice = index; + inputBuffer.device = index; + return paNoError; +} + +PaError PortAudioWrap::setOutputDevice(PaDeviceIndex index) +{ +// outputDevice = index; + outputBuffer.device = index; + return paNoError; +} + +PaError PortAudioWrap::setCallback(PaStreamCallback *callback) +{ + streamCallback = callback; + return paNoError; +} diff --git a/fdmdv2/src/fdmdv2_pa_wrapper.h b/fdmdv2/src/fdmdv2_pa_wrapper.h new file mode 100644 index 00000000..4177d6fc --- /dev/null +++ b/fdmdv2/src/fdmdv2_pa_wrapper.h @@ -0,0 +1,78 @@ +#include +#include +#include "portaudio.h" + +// Note that many of the older ISA sound cards on PCs do NOT support +// full duplex audio (simultaneous record and playback). +// And some only support full duplex at lower sample rates. +#define SAMPLE_RATE (44100) +#define PA_SAMPLE_TYPE paFloat32 //paInt16 +#define FRAMES_PER_BUFFER (64) + +typedef float SAMPLE; + +float CubicAmplifier(float input); + +class PortAudioWrap +{ + public: + PortAudioWrap(); + ~PortAudioWrap(); + + private: + PaStream *stream; + PaStreamParameters inputBuffer; + PaStreamParameters outputBuffer; + void *userData; + int samplerate; + unsigned long framesPerBuffer; + PaStreamCallbackFlags statusFlags; + PaStreamCallback *streamCallback; + PaStreamFinishedCallback *streamFinishedCallback; + const PaStreamCallbackTimeInfo *timeInfo; +// PaDeviceIndex inputDevice; +// PaDeviceIndex outputDevice; + + public: + + PaError streamOpen(); + + PaDeviceIndex getDefaultInputDevice(); + PaDeviceIndex getDefaultOutputDevice(); + + PaStreamParameters *getDeviceInfo(PaDeviceIndex idx); + PaError setFramesPerBuffer(unsigned long size); + PaError setSampleRate(unsigned long size); + PaError setStreamFlags(PaStreamFlags flags); + PaError setCallback(PaStreamCallback *streamCallback); + PaError setStreamCallback(PaStream *stream, PaStreamCallback* callback ) { streamCallback = callback; return 0;} + PaError setStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); + + PaError setInputDevice(PaDeviceIndex dev); + PaError setInputChannelCount(int count); + int getInputChannelCount(); + PaError setInputSampleFormat(PaSampleFormat format); + PaError setInputSampleRate(PaSampleFormat format); + PaError setInputLatency(PaTime latency); + void setInputHostApiStreamInfo(void *info = NULL); + PaTime getInputDefaultLowLatency(); + const char *getDeviceName(PaDeviceIndex dev); + + PaError setOutputDevice(PaDeviceIndex dev); + PaError setOutputChannelCount(int count); + const int getOutputChannelCount(); + PaError setOutputSampleFormat(PaSampleFormat format); + PaError setOutputLatency(PaTime latency); + void setOutputHostApiStreamInfo(void *info = NULL); + PaTime getOutputDefaultLowLatency(); + +// PaError init(); + PaError streamStart(); + PaError streamClose(); + void terminate(); + bool isOpen() const; + void stop(); + void abort(); + bool isStopped() const; + bool isActive() const; +}; diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index e6e0f48d..72be483e 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -3,6 +3,7 @@ // Purpose: Implements simple wxWidgets application with GUI. // Created: Apr. 9, 2012 // Initial author: David Witten +// Derived from: code written by David Rowe // License: BSD License (other licenses may apply to other // components of this project) //========================================================================== @@ -215,3 +216,6 @@ void DrawPanel::paintNow() render(dc); } +// general purpose way of plotting scalar values that are +// updated once per frame + diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index 52022e36..e143278b 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -3,6 +3,7 @@ // Purpose: Declares simple wxWidgets application with GUI // Created: Apr. 10, 2012 // Initial author: David Witten +// Derived from: code written by David Rowe // License: BSD License (other licenses may apply to other // components of this project) //========================================================================== @@ -44,6 +45,14 @@ class DrawPanel : public wxPanel void OnShow(wxShowEvent& event); protected: + int m_x; + int m_y; + int m_w; + int m_h; + int m_prev_w; + int m_prev_h; + int m_prev_x; + int m_prev_y; bool m_bitmap; bool m_clip; bool m_rubberBand; diff --git a/fdmdv2/src/fdmdv2_plot_scatter.cpp b/fdmdv2/src/fdmdv2_plot_scatter.cpp new file mode 100644 index 00000000..1b76e64a --- /dev/null +++ b/fdmdv2/src/fdmdv2_plot_scatter.cpp @@ -0,0 +1,109 @@ +//========================================================================== +// Name: fdmdv2_plot_scatter.cpp +// Purpose: Implements a scatter plot derivative of fdmdv2_plot. +// Created: June 24, 2012 +// Initial author: David Witten +// Derived from: code written by David Rowe +// License: BSD License (other licenses may apply to other +// components of this project) +//========================================================================== +#include +#include "wx/wx.h" +#include "fdmdv2_main.h" +#include "fdmdv2_plot.h" +#include "fdmdv2_plot_scatter.h" + +BEGIN_EVENT_TABLE(ScatterPlot, DrawPanel) + EVT_PAINT (ScatterPlot::OnPaint) + EVT_MOTION (ScatterPlot::OnMouseMove) + EVT_LEFT_DOWN (ScatterPlot::OnMouseDown) + EVT_LEFT_UP (ScatterPlot::OnMouseUp) + EVT_MOUSEWHEEL (ScatterPlot::OnMouseWheelMoved) + EVT_SIZE (ScatterPlot::OnSize) + EVT_SHOW (ScatterPlot::OnShow) +// EVT_ERASE_BACKGROUND(DrawPanel::OnErase) +END_EVENT_TABLE() + +ScatterPlot::ScatterPlot(wxFrame* parent) : DrawPanel(parent) +{ + int i; + + //align(FL_ALIGN_TOP); + //labelsize(10); + + for(i=0; i +#include "wx/wx.h" +#include "fdmdv2_main.h" +#include "fdmdv2_plot.h" + +#include "fdmdv2_plot_spectrum.h" + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// Class SpectrumPlot +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +SpectrumPlot::SpectrumPlot(wxFrame* parent, int x, int y, int w, int h): DrawPanel(parent) +{ +// align(FL_ALIGN_TOP); +// labelsize(10); +} + +int SpectrumPlot::handle(int event) +{ +/* + // detect a left mouse down if inside the spectrum window + if((event == FL_NO_EVENT) && (Fl::event_button() == 1)) + { + if((Fl::event_x() > x()) && (Fl::event_x() < (x() + w())) && (Fl::event_y() > y()) && (Fl::event_y() < (y() + h()))) + { + // show zoomed spectrum window + zoomSpectrumWindow->show(); + } + } +*/ + return 0; +} + +void SpectrumPlot::draw() +{ + float x_px_per_point = 0.0; + float y_px_per_dB = 0.0; + int i, x1, y1, x2, y2; + float mag1, mag2; + char label[20]; + float px_per_hz; +/* + Fl_Box::draw(); + fl_color(FL_BLACK); + fl_rectf(x(),y(),w(),h()); + fl_color(FL_GREEN); + fl_line_style(FL_SOLID); + + fl_push_clip(x(),y(),w(),h()); + //printf("%d %d\n", w(), h()); +*/ + x_px_per_point = (float)m_w / FDMDV_NSPEC; + y_px_per_dB = (float)m_h / (MAX_DB - MIN_DB); + + // plot spectrum + + for(i=0; i +#include "wx/wx.h" +#include "fdmdv2_main.h" +#include "fdmdv2_plot.h" +#include "fdmdv2_plot_waterfall.h" + +/* + + Notes: + + The height h() pixels represents WATERFALL_SECS_Y of data. Every DT + seconds we get a vector of FDMDV_NSPEC spectrum samples which we use + to update the last row. The height of each row is dy pixels, which + maps to DT seconds. We call each dy high rectangle of pixels a + block. + +*/ +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// Class WaterfallPlot +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +//Waterfall::Waterfall(int x, int y, int w, int h): Fl_Box(x, y, w, h, "Waterfall") +Waterfall::Waterfall(wxFrame* parent, int x, int y, int w, int h, const char name[]): DrawPanel(parent) +{ + int i; + + for(i=0; i<255; i++) + { + heatmap_lut[i] = heatmap((float)i, 0.0, 255.0); + } + greyscale = 0; + //align(FL_ALIGN_TOP); + //labelsize(10); + new_pixel_buf(w,h); +}; + +Waterfall::~Waterfall() +{ + delete pixel_buf; +} + +void Waterfall::new_pixel_buf(int w, int h) +{ + int buf_sz, i; + + prev_w = w; prev_h = h; + buf_sz = h*w; + pixel_buf = new unsigned[buf_sz]; + for(i=0; i x()) && (Fl::event_x() < (x() + w())) && (Fl::event_y() > y()) && (Fl::event_y() < (y() + h()))) + { + // show zoomed spectrum window + zoomWaterfallWindow->show(); + } + } +*/ + return 0; +} + +// map val to a rgb colour +// from http://eddiema.ca/2011/01/21/c-sharp-heatmaps/ +unsigned Waterfall::heatmap(float val, float min, float max) +{ + unsigned r = 0; + unsigned g = 0; + unsigned b = 0; + + val = (val - min) / (max - min); + if(val <= 0.2) + { + b = (unsigned)((val / 0.2) * 255); + } + else if(val > 0.2 && val <= 0.7) + { + b = (unsigned)((1.0 - ((val - 0.2) / 0.5)) * 255); + } + if(val >= 0.2 && val <= 0.6) + { + g = (unsigned)(((val - 0.2) / 0.4) * 255); + } + else if(val > 0.6 && val <= 0.9) + { + g = (unsigned)((1.0 - ((val - 0.6) / 0.3)) * 255); + } + if(val >= 0.5) + { + r = (unsigned)(((val - 0.5) / 0.5) * 255); + } + //printf("%f %x %x %x\n", val, r, g, b); + return (b << 16) + (g << 8) + r; +} + +void Waterfall::draw() +{ + float spec_index_per_px, intensity_per_dB; + int px_per_sec; + int index, dy, dy_blocks, bytes_in_row_of_blocks, b; + int px, py, intensity; + unsigned *last_row, *pdest, *psrc; + + /* detect resizing of window */ + if ((m_h != m_prev_h) || (m_w != m_prev_w)) + { + delete pixel_buf; + new_pixel_buf(m_w, m_h); + } +// Fl_Box::draw(); + // determine dy, the height of one "block" + px_per_sec = (float)m_h / WATERFALL_SECS_Y; + dy = DT * px_per_sec; + // number of dy high blocks in spectrogram + dy_blocks = m_h / dy; + // shift previous bit map + bytes_in_row_of_blocks = dy * m_w * sizeof(unsigned); + for(b = 0; b < dy_blocks - 1; b++) + { + pdest = pixel_buf + b * m_w * dy; + psrc = pixel_buf + (b + 1) * m_w * dy; + memcpy(pdest, psrc, bytes_in_row_of_blocks); + } + // create a new row of blocks at bottom + spec_index_per_px = (float)FDMDV_NSPEC / (float) m_w; + intensity_per_dB = (float)256 /(MAX_DB - MIN_DB); + last_row = pixel_buf + dy *(dy_blocks - 1)* m_w; + for(px = 0; px < m_w; px++) + { +// index = px*spec_index_per_px; +// intensity = intensity_per_dB * (av_mag[index] - MIN_DB); + if (intensity > 255) + { + intensity = 255; + } + if (intensity < 0) + { + intensity = 0; + } + if (greyscale) + { + for(py = 0; py < dy; py++) + { + last_row[px + py * m_w] = intensity<<8; + } + } + else + { + for(py = 0; py < dy; py++) + { + last_row[px + py * m_w] = heatmap_lut[intensity]; + } + } + } + // update bit map + //fl_draw_image((unsigned char*)pixel_buf, m_x, m_y, m_w, m_h, 4, 0); +} + + diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.h b/fdmdv2/src/fdmdv2_plot_waterfall.h new file mode 100644 index 00000000..1b51ea24 --- /dev/null +++ b/fdmdv2/src/fdmdv2_plot_waterfall.h @@ -0,0 +1,36 @@ +//========================================================================== +// Name: fdmdv2_plot_waterfall.h +// Purpose: Defines a waterfall plot derivative of fdmdv2_plot. +// Created: June 22, 2012 +// Initial author: David Witten +// Derived from: code written by David Rowe +// License: BSD License (other licenses may apply to other +// components of this project) +//========================================================================== +#ifndef __FDMDV2_PLOT_WATERFALL__ +#define __FDMDV2_PLOT_WATERFALL__ + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// Class Waterfall +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +class Waterfall : public DrawPanel +{ +public: + //Waterfall(int x, int y, int w, int h); + Waterfall(wxFrame* parent, int x, int y, int w, int h, const char name[]); + ~Waterfall(); + +protected: + int prev_w, prev_h; + unsigned *pixel_buf; + unsigned heatmap_lut[256]; + int greyscale; + + void new_pixel_buf(int w, int h); + int handle(int event); + unsigned heatmap(float val, float min, float max); + void draw(); + +}; + +#endif //__FDMDV2_PLOT_WATERFALL__ diff --git a/fdmdv2/src/fdmdv2_scalar.cpp b/fdmdv2/src/fdmdv2_scalar.cpp new file mode 100644 index 00000000..968dc9cb --- /dev/null +++ b/fdmdv2/src/fdmdv2_scalar.cpp @@ -0,0 +1,154 @@ +//========================================================================== +// Name: fdmdv2_plot_waterfall.cpp +// Purpose: Implements a waterfall plot derivative of fdmdv2_plot. +// Created: June 22, 2012 +// Initial author: David Witten +// Derived from: code written by David Rowe +// License: BSD License (other licenses may apply to other +// components of this project) +//========================================================================== +#include +#include "wx/wx.h" +#include "fdmdv2_main.h" +#include "fdmdv2_plot.h" +#include "fdmdv2_scalar.h" + +Scalar::Scalar(wxFrame* parent, int x, int y, int w, int h, int x_max_, int y_max_, const char name[]): DrawPanel(parent) +{ + int i; + + //align(FL_ALIGN_TOP); + //labelsize(10); + + m_x_max = x_max_; + m_y_max = y_max_; + m_mem = new float[m_x_max]; + + for(i = 0; i < m_x_max; i++) + { + m_mem[i] = 0.0; + } + m_prev_w = 0; + m_prev_h = 0; + m_prev_x = 0; + m_prev_y = 0; + m_index = 0; +} + +Scalar::~Scalar() +{ + delete m_mem; +} + +void Scalar::add_new_sample(float sample) +{ + m_new_sample = sample; +} + +int Scalar::clip(int y1) +{ + if(y1 > (m_h/2 - 10)) + { + y1 = m_h/2 - 10; + } + if(y1 < -(m_h/2 - 10)) + { + y1 = -(m_h/2 - 10); + } + return y1; +} + +void Scalar::draw() +{ + float x_scale; + float y_scale; + int i; + int x1; + int y1; + int x2; + int y2; + char label[100]; + +// DrawPanel::draw(); + + /* detect resizing of window */ + if((m_h != m_prev_h) || (m_w != m_prev_w) || (m_x != m_prev_x) || (m_y != m_prev_y)) + { + //fl_color(FL_BLACK); + //fl_rectf(m_x, m_y, m_w, m_h); + m_prev_h = m_h; + m_prev_w = m_w; + m_prev_x = m_x; + m_prev_y = m_y; + } + + //fl_push_clip(m_x, m_y, m_w, m_h); + x_scale = (float)m_x_max; + y_scale = (float)m_h /(2.0 * m_y_max); + + // erase last sample + //fl_color(FL_BLACK); + x1 = x_scale * m_index + m_x; + y1 = y_scale * m_mem[m_index]; + y1 = clip(y1); + y1 = m_y + m_h/2 - y1; + //fl_point(x1, y1); + + // draw new sample + //fl_color(FL_GREEN); + x1 = x_scale * m_index + m_x; + y1 = y_scale * m_new_sample; + y1 = clip(y1); + y1 = m_y + m_h/2 - y1; +// fl_point(x1, y1); + m_mem[m_index] = m_new_sample; + m_index++; + if(m_index >= m_x_max) + { + m_index = 0; + } + + // y axis graticule + m_step = 10; + while((2.0 * m_y_max/m_step) > 10) + { + m_step *= 2.0; + } + while((2.0 * m_y_max/m_step) < 4) + { + m_step /= 2.0; + } + // fl_color(FL_DARK_GREEN); + // fl_line_style(FL_DOT); + for(i =- m_y_max; i < m_y_max; i += m_step) + { + x1 = m_x; + y1 = m_y + m_h/2 - i * y_scale; + x2 = m_x + m_w; + y2 = y1; + //fl_line(x1, y1, x2, y2); + } + + // y axis graticule labels + // fl_color(FL_GREEN); + // fl_line_style(FL_SOLID); + for(i =- m_y_max; i < m_y_max; i += m_step) + { + x1 = m_x; + y1 = m_y + m_h/2 - i * y_scale; + sprintf(label, "%d", i); + //fl_draw(label, x1, y1); + } + //fl_pop_clip(); +} + +// // update average of each spectrum point +// void new_data(float mag_dB[]) +// { +// int i; +// +// for(i=0; idefaultLowInputLatency; -} - -PaError PortAudioWrap::setOutputChannelCount(int count) -{ - outputBuffer.channelCount = count; - return paNoError; -} - -const int PortAudioWrap::getOutputChannelCount() -{ - return outputBuffer.channelCount; -} - -const char *PortAudioWrap::getDeviceName(PaDeviceIndex dev) -{ - const PaDeviceInfo *info; - info = Pa_GetDeviceInfo(dev); - return info->name; -} - -PaError PortAudioWrap::setOutputSampleFormat(PaSampleFormat format) -{ - outputBuffer.sampleFormat = format; - return paNoError; -} - -PaError PortAudioWrap::setOutputLatency(PaTime latency) -{ - outputBuffer.suggestedLatency = latency; - return paNoError; -} - -void PortAudioWrap::setOutputHostApiStreamInfo(void *info) -{ - outputBuffer.hostApiSpecificStreamInfo = info; -} - -PaTime PortAudioWrap::getOutputDefaultLowLatency() -{ - return Pa_GetDeviceInfo(outputBuffer.device)->defaultLowOutputLatency; -} - -PaError PortAudioWrap::setFramesPerBuffer(unsigned long size) -{ - framesPerBuffer = size; - return paNoError; -} - -PaError PortAudioWrap::setSampleRate(unsigned long rate) -{ - samplerate = rate; - return paNoError; -} - -PaError PortAudioWrap::setStreamFlags(PaStreamFlags flags) -{ - statusFlags = flags; - return paNoError; -} - -PaError PortAudioWrap::setInputDevice(PaDeviceIndex index) -{ -// inputDevice = index; - inputBuffer.device = index; - return paNoError; -} - -PaError PortAudioWrap::setOutputDevice(PaDeviceIndex index) -{ -// outputDevice = index; - outputBuffer.device = index; - return paNoError; -} - -PaError PortAudioWrap::setCallback(PaStreamCallback *callback) -{ - streamCallback = callback; - return paNoError; -} diff --git a/fdmdv2/src/paclass.h b/fdmdv2/src/paclass.h deleted file mode 100644 index 4177d6fc..00000000 --- a/fdmdv2/src/paclass.h +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include "portaudio.h" - -// Note that many of the older ISA sound cards on PCs do NOT support -// full duplex audio (simultaneous record and playback). -// And some only support full duplex at lower sample rates. -#define SAMPLE_RATE (44100) -#define PA_SAMPLE_TYPE paFloat32 //paInt16 -#define FRAMES_PER_BUFFER (64) - -typedef float SAMPLE; - -float CubicAmplifier(float input); - -class PortAudioWrap -{ - public: - PortAudioWrap(); - ~PortAudioWrap(); - - private: - PaStream *stream; - PaStreamParameters inputBuffer; - PaStreamParameters outputBuffer; - void *userData; - int samplerate; - unsigned long framesPerBuffer; - PaStreamCallbackFlags statusFlags; - PaStreamCallback *streamCallback; - PaStreamFinishedCallback *streamFinishedCallback; - const PaStreamCallbackTimeInfo *timeInfo; -// PaDeviceIndex inputDevice; -// PaDeviceIndex outputDevice; - - public: - - PaError streamOpen(); - - PaDeviceIndex getDefaultInputDevice(); - PaDeviceIndex getDefaultOutputDevice(); - - PaStreamParameters *getDeviceInfo(PaDeviceIndex idx); - PaError setFramesPerBuffer(unsigned long size); - PaError setSampleRate(unsigned long size); - PaError setStreamFlags(PaStreamFlags flags); - PaError setCallback(PaStreamCallback *streamCallback); - PaError setStreamCallback(PaStream *stream, PaStreamCallback* callback ) { streamCallback = callback; return 0;} - PaError setStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); - - PaError setInputDevice(PaDeviceIndex dev); - PaError setInputChannelCount(int count); - int getInputChannelCount(); - PaError setInputSampleFormat(PaSampleFormat format); - PaError setInputSampleRate(PaSampleFormat format); - PaError setInputLatency(PaTime latency); - void setInputHostApiStreamInfo(void *info = NULL); - PaTime getInputDefaultLowLatency(); - const char *getDeviceName(PaDeviceIndex dev); - - PaError setOutputDevice(PaDeviceIndex dev); - PaError setOutputChannelCount(int count); - const int getOutputChannelCount(); - PaError setOutputSampleFormat(PaSampleFormat format); - PaError setOutputLatency(PaTime latency); - void setOutputHostApiStreamInfo(void *info = NULL); - PaTime getOutputDefaultLowLatency(); - -// PaError init(); - PaError streamStart(); - PaError streamClose(); - void terminate(); - bool isOpen() const; - void stop(); - void abort(); - bool isStopped() const; - bool isActive() const; -};