From 3f2a5d794d9f643f5b00dad3882eedc960b7f19f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 29 Apr 2024 15:09:20 +0100 Subject: [PATCH] Make the FM resampler optional. --- DStarNetwork.cpp | 5 +++-- FMNetwork.cpp | 33 +++++++++++++++++++++++++++------ FMNetwork.h | 8 ++++++-- MMDVMHost.vcxproj | 28 ++++++++++++++++------------ Makefile | 4 +++- Makefile.Pi.Adafruit | 4 +++- Makefile.Pi.HD44780 | 4 +++- Makefile.Pi.I2C | 4 +++- Makefile.Pi.OLED | 4 +++- Makefile.Pi.PCF8574 | 4 +++- Version.h | 2 +- 11 files changed, 71 insertions(+), 29 deletions(-) diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index dbb6a2cb..67099d6c 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016,2019,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2019,2020,2021,2024 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -164,7 +164,7 @@ bool CDStarNetwork::writePoll(const char* text) buffer[2] = 'R'; buffer[3] = 'P'; - buffer[4] = 0x0A; // Poll with text + buffer[4] = 0x0AU; // Poll with text unsigned int length = ::strlen(text); @@ -226,6 +226,7 @@ void CDStarNetwork::clock(unsigned int ms) case 0x01U: // NETWORK_TEMPTEXT; case 0x04U: // NETWORK_STATUS1..5 + case 0x0AU: // POLL case 0x24U: // NETWORK_DD_DATA return; diff --git a/FMNetwork.cpp b/FMNetwork.cpp index 10891ef5..5545967e 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -45,7 +45,9 @@ m_debug(debug), m_enabled(false), m_buffer(2000U, "FM Network"), m_seqNo(0U), +#if defined(HAS_SRC) m_resampler(NULL), +#endif m_error(0), m_fp(NULL) { @@ -67,12 +69,16 @@ m_fp(NULL) else m_protocol = FMNP_USRP; +#if defined(HAS_SRC) m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error); +#endif } CFMNetwork::~CFMNetwork() { +#if defined(HAS_SRC) ::src_delete(m_resampler); +#endif } bool CFMNetwork::open() @@ -84,18 +90,25 @@ bool CFMNetwork::open() LogMessage("Opening FM network connection"); - if (!m_squelchFile.empty()) { - m_fp = ::fopen(m_squelchFile.c_str(), "wb"); - if (m_fp == NULL) { + if (m_protocol == FMNP_RAW) { + if (!m_squelchFile.empty()) { + m_fp = ::fopen(m_squelchFile.c_str(), "wb"); + if (m_fp == NULL) { #if !defined(_WIN32) && !defined(_WIN64) - LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); + LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); #else - LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); + LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); #endif - return false; + return false; + } } } + if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { + LogError("The resampler needed for non-native sample rates has not been included"); + return false; + } + return m_socket.open(m_addr); } @@ -201,6 +214,7 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) unsigned int length = 0U; +#if defined(HAS_SRC) if (m_sampleRate != MMDVM_SAMPLERATE) { unsigned int nOut = (nIn * m_sampleRate) / MMDVM_SAMPLERATE; @@ -227,13 +241,16 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) buffer[length++] = (val >> 8) & 0xFFU; } } else { +#endif for (unsigned int i = 0U; i < nIn; i++) { short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE buffer[length++] = (val >> 0) & 0xFFU; buffer[length++] = (val >> 8) & 0xFFU; } +#if defined(HAS_SRC) } +#endif if (m_debug) CUtils::dump(1U, "FM Network Data Sent", buffer, length); @@ -395,6 +412,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) if (bytes == 0U) return 0U; +#if defined(HAS_SRC) if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { unsigned int nIn = (nOut * m_sampleRate) / MMDVM_SAMPLERATE; @@ -427,6 +445,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) return false; } } else { +#endif if (bytes < nOut) nOut = bytes; @@ -437,7 +456,9 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) short val = ((buffer[i * 2U + 0U] & 0xFFU) << 0) + ((buffer[i * 2U + 1U] & 0xFFU) << 8); out[i] = float(val) / 65536.0F; } +#if defined(HAS_SRC) } +#endif return nOut; } diff --git a/FMNetwork.h b/FMNetwork.h index 6380d6f0..60042cfe 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2023,2024 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +16,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef FMNetwork_H +#if !defined(FMNetwork_H) #define FMNetwork_H #include "RingBuffer.h" #include "UDPSocket.h" +#if defined(HAS_SRC) #include +#endif #include #include @@ -65,7 +67,9 @@ class CFMNetwork { bool m_enabled; CRingBuffer m_buffer; unsigned int m_seqNo; +#if defined(HAS_SRC) SRC_STATE* m_resampler; +#endif int m_error; FILE* m_fp; diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index c0fba946..0b29f635 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -88,13 +88,14 @@ Level3 Disabled HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -104,13 +105,14 @@ Level3 Disabled HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) "$(ProjectDir)prebuild.cmd" $(ProjectDir) @@ -128,15 +130,16 @@ true true HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\Release;%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -148,15 +151,16 @@ true true HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true true true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) diff --git a/Makefile b/Makefile index aa7dec76..495a862e 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ # This makefile is for all platforms, but doesn't include support for the HD44780, OLED, or PCF8574 displays on the Raspberry Pi. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -I/usr/local/include -LIBS = -lpthread -lutil -lsamplerate +LIBS = -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index 1b4e15b0..42147587 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -1,10 +1,12 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # Support for the Adafruit i2c 16 x 2 RGB LCD Pi Plate +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index 31a3159d..ae98870e 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -1,9 +1,11 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.I2C b/Makefile.Pi.I2C index 44f436d6..4c3e2b4c 100644 --- a/Makefile.Pi.I2C +++ b/Makefile.Pi.I2C @@ -1,9 +1,11 @@ # This makefile is for use with the Raspberry Pi. The wiringpi library is needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DRASPBERRY_PI -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index 538ff649..8fdb0503 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -1,9 +1,11 @@ # This makefile is for use with the Raspberry Pi when using an OLED display. The wiringpi library is not needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DOLED -I/usr/local/include -LIBS = -lArduiPi_OLED -lpthread -lutil -lsamplerate +LIBS = -lArduiPi_OLED -lpthread -lutil # If you use NetBSD, add following CFLAGS #CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index c1aa3d1e..86a3351a 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -1,10 +1,12 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # Support for the HD44780 connected via a PCF8574 8-bit GPIO expander IC +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Version.h b/Version.h index 20b0fc67..54784411 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240223"; +const char* VERSION = "20240429"; #endif