mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-20 22:45:44 +08:00
Make the FM resampler optional.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 <samplerate.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -65,7 +67,9 @@ private:
|
||||
bool m_enabled;
|
||||
CRingBuffer<unsigned char> m_buffer;
|
||||
unsigned int m_seqNo;
|
||||
#if defined(HAS_SRC)
|
||||
SRC_STATE* m_resampler;
|
||||
#endif
|
||||
int m_error;
|
||||
FILE* m_fp;
|
||||
|
||||
|
||||
@@ -88,13 +88,14 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<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>
|
||||
<AdditionalLibraryDirectories>..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<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>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@@ -104,13 +105,14 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<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>
|
||||
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<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>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>"$(ProjectDir)prebuild.cmd" $(ProjectDir)</Command>
|
||||
@@ -128,15 +130,16 @@
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<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>
|
||||
<AdditionalLibraryDirectories>..\..\libsamplerate\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<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>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@@ -148,15 +151,16 @@
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<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>
|
||||
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<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>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
||||
4
Makefile
4
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 = \
|
||||
|
||||
@@ -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 = \
|
||||
|
||||
@@ -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 = \
|
||||
|
||||
@@ -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 = \
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = \
|
||||
|
||||
Reference in New Issue
Block a user