From 363585192d1a21ae522aed5609f4e750c35ccfa7 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 22 Jun 2014 00:42:23 +0000 Subject: [PATCH] freedv-dev building, cleaned up README files, added quickstart versions for cmake git-svn-id: https://svn.code.sf.net/p/freetel/code@1702 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2-dev/README | 0 fdmdv2-dev/README.Win32 | 73 --- fdmdv2-dev/README.cmake | 71 --- fdmdv2-dev/README.osx | 801 --------------------------- fdmdv2-dev/README.txt | 115 +++- fdmdv2-dev/cmake/BuildCodec2.cmake | 2 +- fdmdv2-dev/src/fdmdv2_pa_wrapper.cpp | 337 +++++++++++ fdmdv2-dev/src/fdmdv2_pa_wrapper.h | 115 ++++ 8 files changed, 548 insertions(+), 966 deletions(-) delete mode 100644 fdmdv2-dev/README delete mode 100644 fdmdv2-dev/README.Win32 delete mode 100644 fdmdv2-dev/README.cmake delete mode 100644 fdmdv2-dev/README.osx create mode 100644 fdmdv2-dev/src/fdmdv2_pa_wrapper.cpp create mode 100644 fdmdv2-dev/src/fdmdv2_pa_wrapper.h diff --git a/fdmdv2-dev/README b/fdmdv2-dev/README deleted file mode 100644 index e69de29b..00000000 diff --git a/fdmdv2-dev/README.Win32 b/fdmdv2-dev/README.Win32 deleted file mode 100644 index 3fc3f28e..00000000 --- a/fdmdv2-dev/README.Win32 +++ /dev/null @@ -1,73 +0,0 @@ -README.Win32 -David Rowe 27 Oct 2012 - -Debugging Under Windows ------------------------ - -printfs don't appear until after the program finishes. wxLogDebug() -works but you need to run DebugView available from -http://www.sysinternals.com to capture the messages. - -Building fdmdv2 for Windows ---------------------------- - -This is how David R did it, Dave Witten used a different approach. -Many variations are possible. - -1. Install MinGW & the mysys shell - + pwd -W prints true Win32 directory - + I also installed emacs, "tortise svn", and DebugView - -2. "make install" for various packages below put DLLs in /usr/local/lib - "cd /usr/local/lib; pwd -W" to find the Win32 directory - add this to the Windows PATH (Control Panel - System - Advanced) - -3. WxWidgets: - download 2.9.4 tar ball - mkdir build-debug; cd build-debug - ./configure --with-msw - make && make install - -4. PortAudio: - download latest V19 - ./configure --enable-cxx - make && make install - -5. libsndfile: - download lastest source tar ball (not Win32 binaries) - ./configure && make && make install - -6. libsamplerate: - download latest source tar ball: - http://www.mega-nerd.com/SRC/libsamplerate-0.1.8.tar.gz(not Win32 binaries) - ./configure && make && make install - -7. hamlib - - I couldn't get this to compile from source, so used the pre-built Win32 - DLLs: - - Download https://downloads.sourceforge.net/project/hamlib/hamlib/1.2.15.3/hamlib-win32-1.2.15.3.zip - Open hamlib-win32-1.2.15.3.zip with a GUI archive tool - Copy hamlib/include/* to /usr/local/include - Copy hamlib/bin/hamlib*.dll to /usr/local/lib - Copy hamlib/lib/gcc to /usr/local/lib - -8. sox (used for Filter - EQ) - - $ wget http://sourceforge.net/projects/sox/files/sox/14.4.0/sox-14.4.0.tar.gz - $ tar xvzf sox-14.4.0.tar.gz - $ ./configure --enable-shared=no --without-id3tag --without-png --disable-gomp --with-oggvorbis=no --with-oss=no --with-flac=no --disable-dl-sndfile --with-waveaudio=no - $ make && make install - - I couldn't find an install command line that worked, so manually copied the libs and include files. - -9. Codec 2 - $ wget https://freetel.svn.sourceforge.net/svnroot/freetel/codec2 - $ cd codec2 - $ ./configure && make - -10. svn co fdmdv2 - cd fdmdv2/src - make -f Makefile.Win32 - diff --git a/fdmdv2-dev/README.cmake b/fdmdv2-dev/README.cmake deleted file mode 100644 index 1bb0e8f0..00000000 --- a/fdmdv2-dev/README.cmake +++ /dev/null @@ -1,71 +0,0 @@ -The CMake configuration for FDMDV2 (FreeDV) should be considered experimental at -this time but has been thouroughly tested on Fedora Linux and will likely work -well on most *nix systems and has many advanages over the autotools config. - -- Builds against system libraries (by default). -- Or optionally download, build, and statically link with required libraries on - an individual basis. See USE_STATIC_??? options. - NOTE: We need test reports on mingw/Windows, not all dependencies will build. -- Has experimental NSIS packaing support for Windows (WIN32) targets. *nix - systems should rely on 'make install' or tradional packaing methods as the - packages (RPM & DEB) created by CPack are questionable. - -================================== - Building and installing on Linux -================================== - -To perform a cmake build create a directory anywhere underneath (or outside of) -the source directory. - -Linux command line example: - -$ cd /path/to/fdmdv2 -$ mkdir build_linux -$ cd build_linux -$ cmake ../ (defaults to /usr/local, use CMAKE_INSTALL_PREFIX to override) -(if no errors) -$ make -(as root) -$ make install - -==================================== - Building and installing on Windows -==================================== - -The windows build is similar to linux and follows the same basic workflow. - -Only MinGW is supported. While it is likely possible to perform a pure MinGW -build, installing MSYS will make your life easier. - -CMake may not automatically detect that you're in the MSYS environment. If this -occurs you need to pass cmake the proper generator: - -cmake -G"MSYS Makefiles" [other options] - -=============================== - Bootstrapping wxWidgets build -=============================== - -If wxWidgets (>= 3.0) is not available then one option is to have CMake boot- -strap the build for FreeDV. - -This is required because the tool wx-config is used to get the correct compiler -and linker flags of the wxWidgets components needed by FreeDV. Since this is -normally done at configure time, not during "make", it is not possible for CMake -to have this information prior to building wxWidgets. - -In order to work around this issue you can "bootstrap" the wxWidgets build using -the CMake option, "BOOTSTRAP_WXWIDGETS". wxWidgets will be built using static -libraries. - -NOTE: This forces "USE_STATIC_WXWIDGETS" to be true internally regarless of the -value set manually. - -(from any prefered, but empty directory outside of the source) -$ cmake -DBOOTSTRAP_WXWIDGETS=TRUE /path/to/fdmdv2 -$ make -(wxWidgets is downloaded and built) -$ cmake . -$ make -(if all goes well, as root) -$ make install diff --git a/fdmdv2-dev/README.osx b/fdmdv2-dev/README.osx deleted file mode 100644 index 1e3eeca9..00000000 --- a/fdmdv2-dev/README.osx +++ /dev/null @@ -1,801 +0,0 @@ -README.osx -David Witten 29 Dec 2012 -========================== - -Received today: - -Mooneer Salem -Re: [digitalvoice] Re: Mac build for fdmdv2 - -Yep. I'm attaching a patch to this email with the modifications I had to make to get FreeDV to build on OSX. I develop on 10.8.2, but it should work with 10.5-10.7 I think. Unfortunately it's 32-bit only due to a dependency on Carbon, which Apple deprecated. - -Directions (requires MacPorts to build dependencies): - -1. Apply patch. -2. $ sudo port install wxWidgets30 +aui +universal portaudio +universal sox +universal libsndfile +universal libsamplerate +universal -3. $ cd src && make -f Makefile.osx - -This will create a folder named FreeDV.app in the src folder (shows up as a single file in Finder) that when double-clicked, starts the application. I'll probably need to figure out how to include dependencies in the .app folder so that people won't need to install MacPorts just to run FreeDV ;) - -The patch also includes the change away from libctb. It compiles on POSIX compliant platforms, but I'm not sure about the Windows implementation due to not having a Windows development setup here at home. - -... --Mooneer KG6AOV - -Mooneer's patch is included as /freedv_osx_port.patch.gz in the SVN checkout or just snip & run the following -- -Patch: - -Index: src/Makefile.linux -=================================================================== ---- src/Makefile.linux (revision 1152) -+++ src/Makefile.linux (working copy) -@@ -36,12 +36,6 @@ - SOX_INC=-I$(SOX)/src/ - SOX_LIB=$(SOX)/src/.libs/libsox.a - --# CTB --------------------------------------------------- -- --CTB=libctb-0.16 --CTB_INC=-I$(CTB)/include --CTB_LIB=$(CTB)/lib/libctb-0.16.a -- - # if libasound is available, PortAudio will be using it, so we will - # need to add it to freedv link line. To test if it is present, we try - # to link a small C program with -lasound -@@ -50,8 +44,8 @@ - - # FreeDV ------------------------------------------------ - --CPP_FLAGS = -D_NO_AUTOTOOLS_ $(WX_CPPFLAGS) $(PORTAUDIO_INC) $(CODEC2_INC) $(SOX_INC) $(CTB_INC) -I. -g -Wall -O3 -DSVN_REVISION=\"$(SVN_REVISION)\" --FREEDV_LIBS = $(WX_LIBS) $(PORTAUDIO_LIB) $(CODEC2_LIB) $(SOX_LIB) $(CTB_LIB) -lm -lpthread -lsndfile -lsamplerate $(LIBASOUND) -+CPP_FLAGS = -D_NO_AUTOTOOLS_ $(WX_CPPFLAGS) $(PORTAUDIO_INC) $(CODEC2_INC) $(SOX_INC) -I. -g -Wall -O3 -DSVN_REVISION=\"$(SVN_REVISION)\" -+FREEDV_LIBS = $(WX_LIBS) $(PORTAUDIO_LIB) $(CODEC2_LIB) $(SOX_LIB) -lm -lpthread -lsndfile -lsamplerate $(LIBASOUND) - - OBJS = topFrame.o \ - fdmdv2_main.o \ -@@ -65,11 +59,12 @@ - dlg_comports.o \ - dlg_filter.o \ - varicode.o \ --sox_biquad.o -+sox_biquad.o \ -+serialport.o - --HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h -+HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h serialport.h - --all: $(WXWIDGETS)/.built $(PORTAUDIO)/.built $(CODEC2)/.built $(SOX)/.built $(CTB)/.built freedv -+all: $(WXWIDGETS)/.built $(PORTAUDIO)/.built $(CODEC2)/.built $(SOX)/.built freedv - - freedv: $(OBJS) - g++ -o freedv $(OBJS) $(CPP_FLAGS) $(FREEDV_LIBS) -@@ -81,7 +76,7 @@ - rm -f *.o fdmdv2 - - clean-lib: -- rm -Rf $(WXWIDGETS) $(PORTAUDIO) $(CODEC2) $(SOX) $(CTB) -+ rm -Rf $(WXWIDGETS) $(PORTAUDIO) $(CODEC2) $(SOX) - rm -f *.o fdmdv2 - - # wxWidgets --------------------------------------------------------- -@@ -126,14 +121,3 @@ - - $(SOX).tar.bz2: - wget http://downloads.sourceforge.net/project/sox/sox/14.4.0/sox-14.4.0.tar.bz2 -- --# CTB ------------------------------------------------------------- -- --$(CTB)/.built: $(CTB) -- cd $(CTB)/build && make && touch ../.built -- --$(CTB) : $(CTB).tar.gz -- tar xvzf $(CTB).tar.gz -- --$(CTB).tar.gz: -- wget https://iftools.com/download/ctb/0.16/libctb-0.16.tar.gz -Index: src/Makefile.linux.dmw -=================================================================== ---- src/Makefile.linux.dmw (revision 1152) -+++ src/Makefile.linux.dmw (working copy) -@@ -36,7 +36,8 @@ - dlg_comports.o \ - dlg_filter.o \ - varicode.o \ --sox_biquad.o -+sox_biquad.o \ -+serialport.o - - - all: fdmdv2 -@@ -44,7 +45,7 @@ - fdmdv2: $(OBJS) fdmdv2_main.h - g++ -o fdmdv2 $(OBJS) $(CPP_FLAGS) $(LIBS) - --fdmdv2_main.h: ../version.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_options.h -+fdmdv2_main.h: ../version.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_options.h serialport.h - - %.o: %.cpp - g++ $(CPP_FLAGS) -c $< -o $@ -Index: src/Makefile.osx -=================================================================== ---- src/Makefile.osx (revision 0) -+++ src/Makefile.osx (working copy) -@@ -0,0 +1,76 @@ -+# src/Makefile.osx -+# Mooneer Salem 28 Dec 2012 -+# -+# Makefile for OSX - assumes MacPorts for some libraries and builds the others locally. -+# Note: dependencies must be installed with universal binary support due to the use of Carbon by portaudio and others. -+# (Carbon is officially deprecated by Apple and does not have 64-bit support.) -+# -+# $ sudo port install wxWidgets30 +aui +universal portaudio +universal sox +universal libsndfile +universal libsamplerate +universal -+# $ make -f Makefile.osx -+ -+SVN_REVISION=$(shell svnversion) -+MACPORTS_FOLDER=/opt/local -+ -+# Codec 2 ----------------------------------------------- -+ -+CODEC2=codec2 -+CODEC2_INC=-I$(CODEC2)/src -+CODEC2_LIB=$(CODEC2)/src/.libs/libcodec2.a -+ -+# FreeDV ------------------------------------------------ -+ -+CPP_FLAGS = -D_NO_AUTOTOOLS_ -I$(MACPORTS_FOLDER)/include -arch i386 `wx-config --cppflags` $(CODEC2_INC) -I. -g -Wall -O3 -DSVN_REVISION=\"$(SVN_REVISION)\" -+FREEDV_LIBS = -arch i386 -L$(MACPORTS_FOLDER)/lib `wx-config --libs all` -lportaudio $(CODEC2_LIB) -lm -lpthread -lsndfile -lsamplerate -lsox -+ -+OBJS = topFrame.o \ -+fdmdv2_main.o \ -+fdmdv2_plot.o \ -+fdmdv2_plot_scalar.o \ -+fdmdv2_plot_scatter.o \ -+fdmdv2_plot_spectrum.o \ -+fdmdv2_plot_waterfall_linux.o \ -+fdmdv2_pa_wrapper.o \ -+dlg_audiooptions.o \ -+dlg_comports.o \ -+dlg_filter.o \ -+varicode.o \ -+sox_biquad.o \ -+serialport.o -+ -+HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h serialport.h -+ -+all: $(CODEC2)/.built freedv FreeDV.app -+ -+freedv: $(OBJS) -+ g++ -o freedv $(OBJS) $(CPP_FLAGS) $(FREEDV_LIBS) -+ -+FreeDV.app: info.plist freedv -+ -mkdir -p $@/Contents/MacOS -+ -mkdir -p $@/Contents/Resources/English.lproj -+ cp info.plist $@/Contents -+ echo -n "APPL????" > $@/Contents/PkgInfo -+ cp freedv $@/Contents/MacOS/FreeDV -+ -+%.o: %.cpp $(HDRS) -+ g++ $(CPP_FLAGS) -c $< -o $@ -+ -+sox_biquad.o: sox_biquad.c -+ gcc $(CPP_FLAGS) -c sox_biquad.c -o sox_biquad.o -+ -+varicode.o: varicode.c -+ cc $(CPP_FLAGS) -c varicode.c -o varicode.o -+ -+clean: -+ rm -f *.o fdmdv2 -+ rm -rf FreeDV.app/ -+ -+clean-lib: clean -+ rm -Rf $(CODEC2) -+ -+# Codec 2 ---------------------------------------------------------- -+ -+$(CODEC2)/.built: $(CODEC2) -+ cd $(CODEC2) && CPPFLAGS="-arch i386" LDFLAGS="-arch i386" ./configure && make && touch .built -+ -+$(CODEC2): -+ svn co https://freetel.svn.sourceforge.net/svnroot/freetel/codec2 -\ No newline at end of file -Index: src/Makefile.win32 -=================================================================== ---- src/Makefile.win32 (revision 1152) -+++ src/Makefile.win32 (working copy) -@@ -16,7 +16,7 @@ - CODEC2_LIB=$(CODEC2_PATH)/src/.libs/libcodec2.a - - CPP_FLAGS = -D_NO_AUTOTOOLS_ -I$(INCLUDE_PATH) $(WX_CPPFLAGS) -I$(CODEC2_INC) -I../extern/include -g -Wall -DSVN_REVISION=\"$(SVN_REVISION)\" --LIBS = $(WX_LIBS) $(CODEC2_LIB) -lm -lportaudiocpp -lportaudio -lpthread -lsndfile -lsamplerate -lctb-0.16 -lsox -+LIBS = $(WX_LIBS) $(CODEC2_LIB) -lm -lportaudiocpp -lportaudio -lpthread -lsndfile -lsamplerate -lsox - - OBJS = topFrame.o \ - fdmdv2_main.o \ -@@ -30,9 +30,10 @@ - dlg_comports.o \ - dlg_filter.o \ - varicode.o \ --sox_biquad.o -+sox_biquad.o \ -+serialport.o - --HDRS = ../version.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h topFrame.h varicode.h -+HDRS = ../version.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h topFrame.h varicode.h serialport.h - - all: freedv - -Index: src/Makefile.win32.dmw -=================================================================== ---- src/Makefile.win32.dmw (revision 1152) -+++ src/Makefile.win32.dmw (working copy) -@@ -40,10 +40,11 @@ - dlg_comports.o \ - dlg_filter.o \ - varicode.o \ --sox_biquad.o -+sox_biquad.o \ -+serialport.o - - --HDRS = ../version.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h -+HDRS = ../version.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h dlg_audiooptions.h serialport.h - - all: freedv - -Index: src/dlg_comports.cpp -=================================================================== ---- src/dlg_comports.cpp (revision 1152) -+++ src/dlg_comports.cpp (working copy) -@@ -21,7 +21,6 @@ - //========================================================================== - #include "dlg_comports.h" - #include "fdmdv2_main.h" --#include - #include - - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -@@ -62,8 +61,9 @@ - wxArrayString m_listCtrlPortsArr; - m_listCtrlPorts = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(-1,45), m_listCtrlPortsArr, wxLB_SINGLE | wxLB_SORT); - staticBoxSizer31->Add(m_listCtrlPorts, 1, wxALIGN_CENTER, 0); --#endif --#ifdef __WXGTK__ -+#else -+/*#endif -+#ifdef __WXGTK__*/ - wxBoxSizer* bSizer83; - bSizer83 = new wxBoxSizer(wxHORIZONTAL); - -Index: src/fdmdv2_main.cpp -=================================================================== ---- src/fdmdv2_main.cpp (revision 1152) -+++ src/fdmdv2_main.cpp (working copy) -@@ -163,7 +163,6 @@ - { - m_zoom = 1.; - m_serialPort = NULL; -- m_device = NULL; - - tools->AppendSeparator(); - wxMenuItem* m_menuItemToolsConfigDelete; -@@ -857,22 +856,22 @@ - { - if(wxGetApp().m_boolRTSPos) // RTS asserted HIGH - { -- m_serialPort->SetLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(true); - } - else // RTS asserted LOW - { -- m_serialPort->ClrLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(false); - } - } - else // Use DTR - { - if(wxGetApp().m_boolDTRPos) // DTR asserted HIGH - { -- m_serialPort->SetLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(true); - } - else // DTR asserted LOW - { -- m_serialPort->ClrLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(false); - } - } - } -@@ -882,22 +881,22 @@ - { - if(wxGetApp().m_boolRTSPos) // RTS cleared LOW - { -- m_serialPort->ClrLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(false); - } - else // RTS cleared HIGH - { -- m_serialPort->SetLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(true); - } - } - else // Use DTR - { - if(wxGetApp().m_boolDTRPos) // DTR cleared LOW - { -- m_serialPort->ClrLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(false); - } - else // DTR cleared HIGH - { -- m_serialPort->SetLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(true); - } - } - } -@@ -1351,13 +1350,15 @@ - { - wxUnusedVar(event); - int rv = 0; -- int iLineState = 0; -+ bool rtsEnabled = false; -+ bool dtrEnabled = false; - //bool bPTTEnabled = m_btnTogPTT->IsEnabled(); - //bool bPTTState = m_btnTogPTT->GetValue(); - - if(m_serialPort != NULL) - { -- int iLineState = m_serialPort->GetLineState(); -+ rtsEnabled = m_serialPort->getRTS(); -+ dtrEnabled = m_serialPort->getDTR(); - CloseSerialPort(); - } - ComPortsDlg *dlg = new ComPortsDlg(NULL); -@@ -1372,21 +1373,21 @@ - SetupSerialPort(); - if(m_serialPort != NULL) - { -- if(iLineState | ctb::LinestateRts) -+ if(rtsEnabled) - { -- m_serialPort->SetLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(true); - } - else - { -- m_serialPort->ClrLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(false); - } -- if(iLineState | ctb::LinestateDtr) -+ if(dtrEnabled) - { -- m_serialPort->SetLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(true); - } - else - { -- m_serialPort->ClrLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(false); - } - // m_btnTogPTT->Enable(bPTTEnabled); - // m_btnTogPTT->SetValue(bPTTState); -@@ -2631,26 +2632,25 @@ - if(!wxGetApp().m_strRigCtrlPort.IsEmpty()) - { - wxString protocol = wxGetApp().m_strRigCtrlDatabits + wxGetApp().m_strRigCtrlParity + wxGetApp().m_strRigCtrlStopbits; -- m_serialPort = new ctb::SerialPort(); -- if(m_serialPort->Open(wxGetApp().m_strRigCtrlPort.c_str(), baudrate, protocol.c_str(), ctb::SerialPort::NoFlowControl ) >= 0 ) -+ m_serialPort = new SerialPort(wxGetApp().m_strRigCtrlPort.ToAscii().data()); -+ if(m_serialPort->open(/*baudrate, protocol.c_str()*/ ) >= 0 ) - { -- m_device = m_serialPort; - // always start with PTT cleared - if(wxGetApp().m_boolRTSPos) // RTS cleared LOW - { -- m_serialPort->ClrLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(false); - } - else // RTS cleared HIGH - { -- m_serialPort->SetLineState(ctb::LinestateRts); -+ m_serialPort->setRTS(true); - } - if(wxGetApp().m_boolDTRPos) // DTR cleared LOW - { -- m_serialPort->ClrLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(false); - } - else // DTR cleared HIGH - { -- m_serialPort->SetLineState(ctb::LinestateDtr); -+ m_serialPort->setDTR(true); - } - //m_btnTogPTT->Enable(true); - m_btnTogPTT->SetValue(false); -@@ -2658,7 +2658,6 @@ - else - { - m_serialPort = NULL; -- m_device = NULL; - //m_btnTogPTT->Disable(); - } - } -@@ -2675,11 +2674,10 @@ - //---------------------------------------------------------------- - void MainFrame::CloseSerialPort(void) - { -- if((m_serialPort != NULL) && m_serialPort->IsOpen()) -+ if((m_serialPort != NULL) && m_serialPort->isOpen()) - { -- m_serialPort->Close(); -+ m_serialPort->close(); - m_serialPort = NULL; -- m_device = NULL; - //m_btnTogPTT->SetLabel(wxT("PTT")); - //m_btnTogPTT->Enable(false); - } -Index: src/fdmdv2_main.h -=================================================================== ---- src/fdmdv2_main.h (revision 1152) -+++ src/fdmdv2_main.h (working copy) -@@ -55,10 +55,7 @@ - #include "codec2_fdmdv.h" - #include "codec2_fifo.h" - --#include "ctb-0.16/ctb.h" --#include "ctb-0.16/portscan.h" --#include "ctb-0.16/serportx.h" --#include "ctb-0.16/serport.h" -+#include "serialport.h" - - #include "topFrame.h" - #include "dlg_comports.h" -@@ -353,8 +350,7 @@ - - protected: - -- ctb::IOBase* m_device; -- ctb::SerialPort* m_serialPort; -+ SerialPort* m_serialPort; - - void setsnrBeta(bool snrSlow); - -Index: src/info.plist -=================================================================== ---- src/info.plist (revision 0) -+++ src/info.plist (working copy) -@@ -0,0 +1,34 @@ -+ -+ -+ -+ -+ CFBundleDevelopmentRegion -+ en -+ CFBundleExecutable -+ freedv -+ CFBundleIconFile -+ -+ CFBundleIdentifier -+ org.freedv.freedv -+ CFBundleInfoDictionaryVersion -+ 6.0 -+ CFBundleName -+ FreeDV -+ CFBundlePackageType -+ APPL -+ CFBundleShortVersionString -+ 1.0 -+ CFBundleSignature -+ ???? -+ CFBundleVersion -+ 1 -+ LSMinimumSystemVersion -+ 10.5 -+ NSHumanReadableCopyright -+ Copyright © 2012 FreeDV. All rights reserved. -+ -+ NSPrincipalClass -+ NSApplication -+ -+ -\ No newline at end of file -Index: src/serialport.cpp -=================================================================== ---- src/serialport.cpp (revision 0) -+++ src/serialport.cpp (working copy) -@@ -0,0 +1,207 @@ -+//========================================================================== -+// Name: serialport.cpp -+// -+// Purpose: Serial port management. -+// Created: Dec. 28, 2012 -+// Authors: Mooneer Salem -+// -+// License: -+// -+// This program is free software; you can redistribute it and/or modify -+// it under the terms of the GNU General License version 2.1, -+// as published by the Free Software Foundation. This program is -+// distributed in the hope that it will be useful, but WITHOUT ANY -+// WARRANTY; without even the implied warranty of MERCHANTABILITY or -+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -+// License for more details. -+// -+// You should have received a copy of the GNU General License -+// along with this program; if not, see . -+// -+//========================================================================== -+ -+#ifndef WIN32 -+#include -+#include -+#include -+#include -+#endif // !WIN32 -+ -+#include "serialport.h" -+ -+#define ERROR_CONDITION (-1) -+#ifdef WIN32 -+#define INVALID_FILE_DESCRIPTOR (INVALID_HANDLE_VALUE) -+#else -+#define INVALID_FILE_DESCRIPTOR (-1) -+#endif // WIN32 -+ -+SerialPort::SerialPort(const std::string &portName) -+ : _portName(portName) -+ , _fileDescriptor(INVALID_FILE_DESCRIPTOR) -+#ifdef WIN32 -+ , _rtsEnabled(false) -+ , _dtrEnabled(false) -+#endif // WIN32 -+{ -+ // No action here until open() is called. -+} -+ -+SerialPort::~SerialPort() -+{ -+ // Close serial port if needed. -+ if (isOpen()) -+ { -+ close(); -+ } -+} -+ -+#ifndef WIN32 -+static int posixGetModemControlBits(const int fileDescriptor) -+{ -+ int modemControlBits = 0; -+ -+ if (ioctl(fileDescriptor, TIOCMGET, &modemControlBits) == 0) -+ { -+ return modemControlBits; -+ } -+ else -+ { -+ return ERROR_CONDITION; -+ } -+} -+ -+static int posixSetModemControlBits(const int fileDescriptor, int modemControlBits) -+{ -+ if (ioctl(fileDescriptor, TIOCMSET, &modemControlBits) == 0) -+ { -+ return modemControlBits; -+ } -+ else -+ { -+ return ERROR_CONDITION; -+ } -+} -+#endif // !WIN32 -+ -+bool SerialPort::getRTS() const -+{ -+#ifdef WIN32 -+ // No way to get DTR/RTS directly from Windows, so we have to -+ // grab what the caller put in during a previous set*() call. -+ return _rtsEnabled; -+#else -+ int tmpbits = posixGetModemControlBits(_fileDescriptor); -+ if (tmpbits != ERROR_CONDITION) -+ { -+ return tmpbits & TIOCM_RTS; -+ } -+ else -+ { -+ return ERROR_CONDITION; -+ } -+#endif // WIN32 -+} -+ -+void SerialPort::setRTS(const bool newRTS) -+{ -+#ifdef WIN32 -+ if (newRTS) -+ { -+ EscapeCommFunction(_fileDescriptor, SETRTS); -+ } -+ else -+ { -+ EscapeCommFunction(_fileDescriptor, CLRRTS); -+ } -+ _rtsEnabled = newRTS; -+#else -+ int tmpbits = posixGetModemControlBits(_fileDescriptor); -+ if (tmpbits != ERROR_CONDITION) -+ { -+ if (newRTS) tmpbits |= TIOCM_RTS; -+ else tmpbits &= ~TIOCM_RTS; -+ posixSetModemControlBits(_fileDescriptor, tmpbits); -+ } -+#endif // WIN32 -+} -+ -+bool SerialPort::getDTR() const -+{ -+#ifdef WIN32 -+ // No way to get DTR/RTS directly from Windows, so we have to -+ // grab what the caller put in during a previous set*() call. -+ return _dtrEnabled; -+#else -+ int tmpbits = posixGetModemControlBits(_fileDescriptor); -+ if (tmpbits != ERROR_CONDITION) -+ { -+ return tmpbits & TIOCM_DTR; -+ } -+ else -+ { -+ return ERROR_CONDITION; -+ } -+#endif // WIN32 -+} -+ -+void SerialPort::setDTR(const bool newDTR) -+{ -+#ifdef WIN32 -+ if (newDTR) -+ { -+ EscapeCommFunction(_fileDescriptor, SETDTR); -+ } -+ else -+ { -+ EscapeCommFunction(_fileDescriptor, CLRDTR); -+ } -+ _dtrEnabled = newDTR; -+#else -+ int tmpbits = posixGetModemControlBits(_fileDescriptor); -+ if (tmpbits != ERROR_CONDITION) -+ { -+ if (newDTR) tmpbits |= TIOCM_DTR; -+ else tmpbits &= ~TIOCM_DTR; -+ posixSetModemControlBits(_fileDescriptor, tmpbits); -+ } -+#endif // WIN32 -+} -+ -+int SerialPort::open() -+{ -+#ifdef WIN32 -+ TCHAR portName[32]; -+ _stprintf_s(portName, sizeof(portName)/sizeof(TCHAR), _T("\\\\.\\%s"), _portName.c_str()); -+ -+ _fileDescriptor = CreateFile( -+ portName, -+ GENERIC_READ | GENERIC_WRITE, -+ 0, -+ 0, -+ OPEN_EXISTING, -+ FILE_FLAG_OVERLAPPED, -+ 0); -+#else -+ _fileDescriptor = ::open(_portName.c_str(), O_RDWR); -+#endif // WIN32 -+ -+ return (int)_fileDescriptor; -+} -+ -+int SerialPort::close() -+{ -+#ifdef WIN32 -+ int rv = CloseHandle(_fileDescriptor); -+#else -+ int rv = ::close(_fileDescriptor); -+#endif // WIN32 -+ -+ _fileDescriptor = INVALID_FILE_DESCRIPTOR; -+ return rv; -+} -+ -+bool SerialPort::isOpen() const -+{ -+ return _fileDescriptor != INVALID_FILE_DESCRIPTOR; -+} -\ No newline at end of file -Index: src/serialport.h -=================================================================== ---- src/serialport.h (revision 0) -+++ src/serialport.h (working copy) -@@ -0,0 +1,81 @@ -+//========================================================================== -+// Name: serialport.h -+// -+// Purpose: Serial port management. -+// Created: Dec. 28, 2012 -+// Authors: Mooneer Salem -+// -+// License: -+// -+// This program is free software; you can redistribute it and/or modify -+// it under the terms of the GNU General License version 2.1, -+// as published by the Free Software Foundation. This program is -+// distributed in the hope that it will be useful, but WITHOUT ANY -+// WARRANTY; without even the implied warranty of MERCHANTABILITY or -+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -+// License for more details. -+// -+// You should have received a copy of the GNU General License -+// along with this program; if not, see . -+// -+//========================================================================== -+ -+#ifndef SERIAL_PORT_H -+#define SERIAL_PORT_H -+ -+#ifdef WIN32 -+#include -+#endif // WIN32 -+ -+#include -+ -+enum SerialPortParity -+{ -+ NONE, -+ EVEN, -+ ODD -+}; -+ -+// Quick and dirty serial port class that supports the minimum necessary to -+// do PTT (for now). Can be extended later (send/receive data for CAT control, -+// for example). -+class SerialPort -+{ -+public: -+ // portName is a path to the serial port, in one of the following formats: -+ // OSX: /dev/tty.* -+ // Linux: /dev/ttyS* -+ // Windows: COM*: -+ SerialPort(const std::string &portName); -+ virtual ~SerialPort(); -+ -+ bool getRTS() const; -+ void setRTS(const bool newRTS); -+ -+ bool getDTR() const; -+ void setDTR(const bool newDTR); -+ -+ int open(); -+ int close(); -+ -+ bool isOpen() const; -+ -+private: -+ const std::string _portName; -+ -+#ifdef WIN32 -+ HANDLE _fileDescriptor; -+ -+ bool _rtsEnabled; -+ bool _dtrEnabled; -+#else -+ int _fileDescriptor; -+#endif // WIN32 -+ -+ // Object should not be copied since there can be only one handle open -+ // per serial port. An attempt to use the copy constructor here, even -+ // implicitly, will result in a compile error due to the declaration below. -+ SerialPort(const SerialPort&); -+}; -+ -+#endif // SERIAL_PORT_H -\ No newline at end of file diff --git a/fdmdv2-dev/README.txt b/fdmdv2-dev/README.txt index 89d11561..6f9afc0f 100644 --- a/fdmdv2-dev/README.txt +++ b/fdmdv2-dev/README.txt @@ -1,20 +1,95 @@ -README.txt for FDMDV2 - -README.Win32 contains instructions for building on Windows. -README.linux contains instructions for building on Linux. -README.cmake contains instructions for building on Windows or Linux using cmake. - -Editing -------- - -Please make sure your text editor does not insert tabs, and -used indents of 4 spaces. The following .emacs code was used to -configure emacs: - -(setq-default indent-tabs-mode nil) - -(add-hook 'c-mode-common-hook - (function (lambda () - (setq c-basic-offset 4) - ))) - +================================== + Building and installing on Linux +================================== + +Quickstart 1 +----------- + +Builds static versions of wxWidgets, portaudio, codec2-dev, which are commonly missing on many Linux systems, or of the wrong (older) version. + +Assuming the freedv-dev sources is checked out into ~/fdmdv2-dev: + +$ cd +$ mkdir tmp +$ cd tmp +$ cmake -DBOOTSTRAP_WXWIDGETS=TRUE -DUSE_STATIC_CODEC2=TRUE -DUSE_STATIC_PORTAUDIO=TRUE ~/fdmdv2-dev +$ make +[wxWidgets builds] +$ cmake . +$ make +[FreeDV builds] +$ ./src/freedv + +Quickstart 2 +------------ + +Assumes you have all the dependant libraries: + +$ cd /path/to/fdmdv2 +$ mkdir build_linux +$ cd build_linux +$ cmake ../ (defaults to /usr/local, use CMAKE_INSTALL_PREFIX to override) +(if no errors) +$ make +(as root) +$ make install + +==================================== + Building and installing on Windows +==================================== + +The windows build is similar to linux and follows the same basic workflow. + +Only MinGW is supported. While it is likely possible to perform a pure MinGW +build, installing MSYS will make your life easier. + +CMake may not automatically detect that you're in the MSYS environment. If this +occurs you need to pass cmake the proper generator: + +cmake -G"MSYS Makefiles" [other options] + +=============================== + Bootstrapping wxWidgets build +=============================== + +If wxWidgets (>= 3.0) is not available then one option is to have CMake boot-strap the build for FreeDV. + +This is required because the tool wx-config is used to get the correct compiler and linker flags of the wxWidgets components needed by FreeDV. Since this is normally done at configure time, not during "make", it is not possible for CMake or have this information prior to building wxWidgets. + +In order to work around this issue you can "bootstrap" the wxWidgets build using the CMake option, "BOOTSTRAP_WXWIDGETS". wxWidgets will be built using static libraries. + +NOTE: This forces "USE_STATIC_WXWIDGETS" to be true internally regarless of the +value set manually. + +(from any prefered, but empty directory outside of the source) +$ cmake -DBOOTSTRAP_WXWIDGETS=TRUE /path/to/fdmdv2 +$ make +(wxWidgets is downloaded and built) +$ cmake . +$ make +(if all goes well, as root) +$ make install + +==================================== + Building and installing on OSX +==================================== + +==================================== + Building and installing on FreeBSD +==================================== + +======= +Editing +======= + +Please make sure your text editor does not insert tabs, and +used indents of 4 spaces. The following .emacs code was used to +configure emacs: + +(setq-default indent-tabs-mode nil) + +(add-hook 'c-mode-common-hook + (function (lambda () + (setq c-basic-offset 4) + ))) + diff --git a/fdmdv2-dev/cmake/BuildCodec2.cmake b/fdmdv2-dev/cmake/BuildCodec2.cmake index f56a186b..d7ddcf93 100644 --- a/fdmdv2-dev/cmake/BuildCodec2.cmake +++ b/fdmdv2-dev/cmake/BuildCodec2.cmake @@ -1,6 +1,6 @@ include(ExternalProject) ExternalProject_Add(codec2 - SVN_REPOSITORY https://svn.code.sf.net/p/freetel/code/codec2 + SVN_REPOSITORY https://svn.code.sf.net/p/freetel/code/codec2-dev CMAKE_ARGS -DBUILD_SHARED_LIBS=FALSE INSTALL_COMMAND "" ) diff --git a/fdmdv2-dev/src/fdmdv2_pa_wrapper.cpp b/fdmdv2-dev/src/fdmdv2_pa_wrapper.cpp new file mode 100644 index 00000000..08120873 --- /dev/null +++ b/fdmdv2-dev/src/fdmdv2_pa_wrapper.cpp @@ -0,0 +1,337 @@ +//========================================================================== +// Name: fdmdv2_pa_wrapper.cpp +// Purpose: Implements a wrapper class around the PortAudio library. +// Created: August 12, 2012 +// Authors: David Rowe, David Witten +// +// License: +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2.1, +// as published by the Free Software Foundation. This program is +// distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see . +// +//========================================================================== +#include "fdmdv2_pa_wrapper.h" + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// PortAudioWrap() +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +PortAudioWrap::PortAudioWrap() +{ + m_pStream = NULL; + m_pUserData = NULL; + m_samplerate = 0; + m_framesPerBuffer = 0; + m_statusFlags = 0; + m_pStreamCallback = NULL; + m_pStreamFinishedCallback = NULL; + m_pTimeInfo = 0; + m_newdata = false; + +// loadData(); +} + +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +// ~PortAudioWrap() +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= +PortAudioWrap::~PortAudioWrap() +{ +} + +//---------------------------------------------------------------- +// streamOpen() +//---------------------------------------------------------------- +PaError PortAudioWrap::streamOpen() +{ + return Pa_OpenStream( + &m_pStream, + m_inputBuffer.device == paNoDevice ? NULL : &m_inputBuffer, + m_outputBuffer.device == paNoDevice ? NULL : &m_outputBuffer, + m_samplerate, + m_framesPerBuffer, + m_statusFlags, + *m_pStreamCallback, + m_pUserData + ); +} + +//---------------------------------------------------------------- +// streamStart() +//---------------------------------------------------------------- +PaError PortAudioWrap::streamStart() +{ + return Pa_StartStream(m_pStream); +} + +//---------------------------------------------------------------- +// streamClose() +//---------------------------------------------------------------- +PaError PortAudioWrap::streamClose() +{ + if(isOpen()) + { + PaError rv = Pa_CloseStream(m_pStream); + return rv; + } + else + { + return paNoError; + } +} + +//---------------------------------------------------------------- +// terminate() +//---------------------------------------------------------------- +void PortAudioWrap::terminate() +{ + if(Pa_IsStreamStopped(m_pStream) != paNoError) + { + Pa_StopStream(m_pStream); + } + Pa_Terminate(); +} + +//---------------------------------------------------------------- +// stop() +//---------------------------------------------------------------- +void PortAudioWrap::stop() +{ + Pa_StopStream(m_pStream); +} + +//---------------------------------------------------------------- +// abort() +//---------------------------------------------------------------- +void PortAudioWrap::abort() +{ + Pa_AbortStream(m_pStream); +} + +//---------------------------------------------------------------- +// isStopped() +//---------------------------------------------------------------- +bool PortAudioWrap::isStopped() const +{ + PaError ret = Pa_IsStreamStopped(m_pStream); + return ret; +} + +//---------------------------------------------------------------- +// isActive() +//---------------------------------------------------------------- +bool PortAudioWrap::isActive() const +{ + PaError ret = Pa_IsStreamActive(m_pStream); + return ret; +} + +//---------------------------------------------------------------- +// isOpen() +//---------------------------------------------------------------- +bool PortAudioWrap::isOpen() const +{ + return (m_pStream != NULL); +} + +//---------------------------------------------------------------- +// getDefaultInputDevice() +//---------------------------------------------------------------- +PaDeviceIndex PortAudioWrap::getDefaultInputDevice() +{ + return Pa_GetDefaultInputDevice(); +} + +//---------------------------------------------------------------- +// getDefaultOutputDevice() +//---------------------------------------------------------------- +PaDeviceIndex PortAudioWrap::getDefaultOutputDevice() +{ + return Pa_GetDefaultOutputDevice(); +} + +//---------------------------------------------------------------- +// setInputChannelCount() +//---------------------------------------------------------------- +PaError PortAudioWrap::setInputChannelCount(int count) +{ + m_inputBuffer.channelCount = count; + return paNoError; +} + +//---------------------------------------------------------------- +// getInputChannelCount() +//---------------------------------------------------------------- +PaError PortAudioWrap::getInputChannelCount() +{ + return m_inputBuffer.channelCount; +} + +//---------------------------------------------------------------- +// setInputSampleFormat() +//---------------------------------------------------------------- +PaError PortAudioWrap::setInputSampleFormat(PaSampleFormat format) +{ + m_inputBuffer.sampleFormat = format; + return paNoError; +} + +//---------------------------------------------------------------- +// setInputLatency() +//---------------------------------------------------------------- +PaError PortAudioWrap::setInputLatency(PaTime latency) +{ + m_inputBuffer.suggestedLatency = latency; + return paNoError; +} + +//---------------------------------------------------------------- +// setInputHostApiStreamInfo() +//---------------------------------------------------------------- +void PortAudioWrap::setInputHostApiStreamInfo(void *info) +{ + m_inputBuffer.hostApiSpecificStreamInfo = info; +} + +//---------------------------------------------------------------- +// getInputDefaultLowLatency() +//---------------------------------------------------------------- +PaTime PortAudioWrap::getInputDefaultLowLatency() +{ + return Pa_GetDeviceInfo(m_inputBuffer.device)->defaultLowInputLatency; +} + +//---------------------------------------------------------------- +// setOutputChannelCount() +//---------------------------------------------------------------- +PaError PortAudioWrap::setOutputChannelCount(int count) +{ + m_outputBuffer.channelCount = count; + return paNoError; +} + +//---------------------------------------------------------------- +// getOutputChannelCount() +//---------------------------------------------------------------- +const int PortAudioWrap::getOutputChannelCount() +{ + return m_outputBuffer.channelCount; +} + +//---------------------------------------------------------------- +// getDeviceName() +//---------------------------------------------------------------- +const char *PortAudioWrap::getDeviceName(PaDeviceIndex dev) +{ + const PaDeviceInfo *info; + info = Pa_GetDeviceInfo(dev); + return info->name; +} + +//---------------------------------------------------------------- +// setOutputSampleFormat() +//---------------------------------------------------------------- +PaError PortAudioWrap::setOutputSampleFormat(PaSampleFormat format) +{ + m_outputBuffer.sampleFormat = format; + return paNoError; +} + +//---------------------------------------------------------------- +// setOutputLatency() +//---------------------------------------------------------------- +PaError PortAudioWrap::setOutputLatency(PaTime latency) +{ + m_outputBuffer.suggestedLatency = latency; + return paNoError; +} + +//---------------------------------------------------------------- +// setOutputHostApiStreamInfo() +//---------------------------------------------------------------- +void PortAudioWrap::setOutputHostApiStreamInfo(void *info) +{ + m_outputBuffer.hostApiSpecificStreamInfo = info; +} + +//---------------------------------------------------------------- +// getOutputDefaultLowLatency() +//---------------------------------------------------------------- +PaTime PortAudioWrap::getOutputDefaultLowLatency() +{ + return Pa_GetDeviceInfo(m_outputBuffer.device)->defaultLowOutputLatency; +} + +//---------------------------------------------------------------- +// setFramesPerBuffer() +//---------------------------------------------------------------- +PaError PortAudioWrap::setFramesPerBuffer(unsigned long size) +{ + m_framesPerBuffer = size; + return paNoError; +} + +//---------------------------------------------------------------- +// setSampleRate() +//---------------------------------------------------------------- +PaError PortAudioWrap::setSampleRate(unsigned long rate) +{ + m_samplerate = rate; + return paNoError; +} + +//---------------------------------------------------------------- +// setStreamFlags() +//---------------------------------------------------------------- +PaError PortAudioWrap::setStreamFlags(PaStreamFlags flags) +{ + m_statusFlags = flags; + return paNoError; +} + +//---------------------------------------------------------------- +// setInputDevice() +//---------------------------------------------------------------- +PaError PortAudioWrap::setInputDevice(PaDeviceIndex index) +{ + m_inputBuffer.device = index; + return paNoError; +} + +//---------------------------------------------------------------- +// setOutputDevice() +//---------------------------------------------------------------- +PaError PortAudioWrap::setOutputDevice(PaDeviceIndex index) +{ + m_outputBuffer.device = index; + return paNoError; +} + +//---------------------------------------------------------------- +// setCallback() +//---------------------------------------------------------------- +PaError PortAudioWrap::setCallback(PaStreamCallback *callback) +{ + m_pStreamCallback = callback; + return paNoError; +} + +/* +//---------------------------------------------------------------- +// loadData() : create Dummy Data +//---------------------------------------------------------------- +void PortAudioWrap::loadData() +{ + int i; + for(i = 0; i < FDMDV_NSPEC; i++) + { + m_av_mag[i] = i; + } +} +*/ diff --git a/fdmdv2-dev/src/fdmdv2_pa_wrapper.h b/fdmdv2-dev/src/fdmdv2_pa_wrapper.h new file mode 100644 index 00000000..3d216c0d --- /dev/null +++ b/fdmdv2-dev/src/fdmdv2_pa_wrapper.h @@ -0,0 +1,115 @@ +//========================================================================== +// Name: fdmdv2_pa_wrapper.h +// Purpose: Defines a wrapper class around PortAudio +// Created: August 12, 2012 +// Authors: David Rowe, David Witten +// +// License: +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2.1, +// as published by the Free Software Foundation. This program is +// distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see . +// +//========================================================================== +#include +#include +#include "fdmdv2_defines.h" +#include "codec2_fdmdv.h" +#include "codec2.h" +#include "portaudio.h" + +#define PA_SAMPLE_TYPE paInt16 //paFloat32 +#define FRAMES_PER_BUFFER (64) + +typedef float SAMPLE; + +class PortAudioWrap +{ + public: + PortAudioWrap(); + ~PortAudioWrap(); + +// float m_av_mag[FDMDV_NSPEC]; + + private: + PaStream *m_pStream; + void *m_pUserData; + PaStreamCallback *m_pStreamCallback; + PaStreamFinishedCallback *m_pStreamFinishedCallback; + const PaStreamCallbackTimeInfo *m_pTimeInfo; + struct FDMDV *m_pFDMDV_state; + PaStreamParameters m_inputBuffer; + PaStreamParameters m_outputBuffer; + int m_samplerate; + unsigned long m_framesPerBuffer; + PaStreamCallbackFlags m_statusFlags; + bool m_newdata; + + public: + + void averageData(float mag_dB[]); + + int getDeviceCount() { return Pa_GetDeviceCount(); } + 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 *m_pStreamCallback); + PaError setStreamCallback(PaStream *stream, PaStreamCallback* callback) { m_pStreamCallback = callback; return 0;} + PaError setStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback* m_pStreamFinishedCallback); + + void setInputBuffer(const PaStreamParameters& inputBuffer) {this->m_inputBuffer = inputBuffer;} + 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(); + + void setFdmdvState(FDMDV* fdmdv_state) {this->m_pFDMDV_state = fdmdv_state;} + void setOutputBuffer(const PaStreamParameters& outputBuffer) {this->m_outputBuffer = outputBuffer;} + void setTimeInfo(PaStreamCallbackTimeInfo* timeInfo) {this->m_pTimeInfo = timeInfo;} + void setUserData(void* userData) {this->m_pUserData = userData;} + unsigned long getFramesPerBuffer() const {return m_framesPerBuffer;} + const PaStreamParameters& getInputBuffer() const {return m_inputBuffer;} + const PaStreamParameters& getOutputBuffer() const {return m_outputBuffer;} + const PaStreamCallbackFlags& getStatusFlags() const {return m_statusFlags;} + + FDMDV* getFdmdvState() {return m_pFDMDV_state;} + int getSamplerate() const {return m_samplerate;} + PaStream* getStream() {return m_pStream;} + void *getUserData() {return m_pUserData;} + bool getDataAvail() {return m_newdata;} + PaError streamStart(); + PaError streamClose(); + PaError streamOpen(); + void terminate(); + void stop(); + void abort(); + bool isOpen() const; + bool isStopped() const; + bool isActive() const; +// void loadData(); +}; -- 2.25.1