Make the FM resampler optional.

This commit is contained in:
Jonathan Naylor
2024-04-29 15:09:20 +01:00
parent 738c82d7b9
commit 3f2a5d794d
11 changed files with 71 additions and 29 deletions

View File

@@ -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 * 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 * 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[2] = 'R';
buffer[3] = 'P'; buffer[3] = 'P';
buffer[4] = 0x0A; // Poll with text buffer[4] = 0x0AU; // Poll with text
unsigned int length = ::strlen(text); unsigned int length = ::strlen(text);
@@ -226,6 +226,7 @@ void CDStarNetwork::clock(unsigned int ms)
case 0x01U: // NETWORK_TEMPTEXT; case 0x01U: // NETWORK_TEMPTEXT;
case 0x04U: // NETWORK_STATUS1..5 case 0x04U: // NETWORK_STATUS1..5
case 0x0AU: // POLL
case 0x24U: // NETWORK_DD_DATA case 0x24U: // NETWORK_DD_DATA
return; return;

View File

@@ -45,7 +45,9 @@ m_debug(debug),
m_enabled(false), m_enabled(false),
m_buffer(2000U, "FM Network"), m_buffer(2000U, "FM Network"),
m_seqNo(0U), m_seqNo(0U),
#if defined(HAS_SRC)
m_resampler(NULL), m_resampler(NULL),
#endif
m_error(0), m_error(0),
m_fp(NULL) m_fp(NULL)
{ {
@@ -67,12 +69,16 @@ m_fp(NULL)
else else
m_protocol = FMNP_USRP; m_protocol = FMNP_USRP;
#if defined(HAS_SRC)
m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error); m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error);
#endif
} }
CFMNetwork::~CFMNetwork() CFMNetwork::~CFMNetwork()
{ {
#if defined(HAS_SRC)
::src_delete(m_resampler); ::src_delete(m_resampler);
#endif
} }
bool CFMNetwork::open() bool CFMNetwork::open()
@@ -84,6 +90,7 @@ bool CFMNetwork::open()
LogMessage("Opening FM network connection"); LogMessage("Opening FM network connection");
if (m_protocol == FMNP_RAW) {
if (!m_squelchFile.empty()) { if (!m_squelchFile.empty()) {
m_fp = ::fopen(m_squelchFile.c_str(), "wb"); m_fp = ::fopen(m_squelchFile.c_str(), "wb");
if (m_fp == NULL) { if (m_fp == NULL) {
@@ -95,6 +102,12 @@ bool CFMNetwork::open()
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); return m_socket.open(m_addr);
} }
@@ -201,6 +214,7 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn)
unsigned int length = 0U; unsigned int length = 0U;
#if defined(HAS_SRC)
if (m_sampleRate != MMDVM_SAMPLERATE) { if (m_sampleRate != MMDVM_SAMPLERATE) {
unsigned int nOut = (nIn * 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; buffer[length++] = (val >> 8) & 0xFFU;
} }
} else { } else {
#endif
for (unsigned int i = 0U; i < nIn; i++) { for (unsigned int i = 0U; i < nIn; i++) {
short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE
buffer[length++] = (val >> 0) & 0xFFU; buffer[length++] = (val >> 0) & 0xFFU;
buffer[length++] = (val >> 8) & 0xFFU; buffer[length++] = (val >> 8) & 0xFFU;
} }
#if defined(HAS_SRC)
} }
#endif
if (m_debug) if (m_debug)
CUtils::dump(1U, "FM Network Data Sent", buffer, length); 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) if (bytes == 0U)
return 0U; return 0U;
#if defined(HAS_SRC)
if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) {
unsigned int nIn = (nOut * 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; return false;
} }
} else { } else {
#endif
if (bytes < nOut) if (bytes < nOut)
nOut = bytes; 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); short val = ((buffer[i * 2U + 0U] & 0xFFU) << 0) + ((buffer[i * 2U + 1U] & 0xFFU) << 8);
out[i] = float(val) / 65536.0F; out[i] = float(val) / 65536.0F;
} }
#if defined(HAS_SRC)
} }
#endif
return nOut; return nOut;
} }

View File

@@ -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 * 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 * 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. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef FMNetwork_H #if !defined(FMNetwork_H)
#define FMNetwork_H #define FMNetwork_H
#include "RingBuffer.h" #include "RingBuffer.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#if defined(HAS_SRC)
#include <samplerate.h> #include <samplerate.h>
#endif
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@@ -65,7 +67,9 @@ private:
bool m_enabled; bool m_enabled;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
unsigned int m_seqNo; unsigned int m_seqNo;
#if defined(HAS_SRC)
SRC_STATE* m_resampler; SRC_STATE* m_resampler;
#endif
int m_error; int m_error;
FILE* m_fp; FILE* m_fp;

View File

@@ -88,13 +88,14 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>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)</AdditionalDependencies> <AdditionalDependencies>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)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -104,13 +105,14 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>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)</AdditionalDependencies> <AdditionalDependencies>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)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
<PreBuildEvent> <PreBuildEvent>
<Command>"$(ProjectDir)prebuild.cmd" $(ProjectDir)</Command> <Command>"$(ProjectDir)prebuild.cmd" $(ProjectDir)</Command>
@@ -128,15 +130,16 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>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)</AdditionalDependencies> <AdditionalDependencies>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)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\libsamplerate\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -148,15 +151,16 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>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)</AdditionalDependencies> <AdditionalDependencies>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)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@@ -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. # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -I/usr/local/include 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 LDFLAGS = -g -L/usr/local/lib
OBJECTS = \ OBJECTS = \

View File

@@ -1,10 +1,12 @@
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # 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 # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include 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 LDFLAGS = -g -L/usr/local/lib
OBJECTS = \ OBJECTS = \

View File

@@ -1,9 +1,11 @@
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -I/usr/local/include 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 LDFLAGS = -g -L/usr/local/lib
OBJECTS = \ OBJECTS = \

View File

@@ -1,9 +1,11 @@
# This makefile is for use with the Raspberry Pi. The wiringpi library is needed. # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DRASPBERRY_PI -I/usr/local/include 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 LDFLAGS = -g -L/usr/local/lib
OBJECTS = \ OBJECTS = \

View File

@@ -1,9 +1,11 @@
# This makefile is for use with the Raspberry Pi when using an OLED display. The wiringpi library is not needed. # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DOLED -I/usr/local/include 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 # If you use NetBSD, add following CFLAGS
#CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib #CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib

View File

@@ -1,10 +1,12 @@
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # 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 # 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 CC = cc
CXX = c++ CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include 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 LDFLAGS = -g -L/usr/local/lib
OBJECTS = \ OBJECTS = \

View File

@@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20240223"; const char* VERSION = "20240429";
#endif #endif