Skip to content

Commit 3f2a5d7

Browse files
committed
Make the FM resampler optional.
1 parent 738c82d commit 3f2a5d7

11 files changed

+71
-29
lines changed

DStarNetwork.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009-2014,2016,2019,2020,2021 by Jonathan Naylor G4KLX
2+
* Copyright (C) 2009-2014,2016,2019,2020,2021,2024 by Jonathan Naylor G4KLX
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -164,7 +164,7 @@ bool CDStarNetwork::writePoll(const char* text)
164164
buffer[2] = 'R';
165165
buffer[3] = 'P';
166166

167-
buffer[4] = 0x0A; // Poll with text
167+
buffer[4] = 0x0AU; // Poll with text
168168

169169
unsigned int length = ::strlen(text);
170170

@@ -226,6 +226,7 @@ void CDStarNetwork::clock(unsigned int ms)
226226

227227
case 0x01U: // NETWORK_TEMPTEXT;
228228
case 0x04U: // NETWORK_STATUS1..5
229+
case 0x0AU: // POLL
229230
case 0x24U: // NETWORK_DD_DATA
230231
return;
231232

FMNetwork.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ m_debug(debug),
4545
m_enabled(false),
4646
m_buffer(2000U, "FM Network"),
4747
m_seqNo(0U),
48+
#if defined(HAS_SRC)
4849
m_resampler(NULL),
50+
#endif
4951
m_error(0),
5052
m_fp(NULL)
5153
{
@@ -67,12 +69,16 @@ m_fp(NULL)
6769
else
6870
m_protocol = FMNP_USRP;
6971

72+
#if defined(HAS_SRC)
7073
m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error);
74+
#endif
7175
}
7276

7377
CFMNetwork::~CFMNetwork()
7478
{
79+
#if defined(HAS_SRC)
7580
::src_delete(m_resampler);
81+
#endif
7682
}
7783

7884
bool CFMNetwork::open()
@@ -84,18 +90,25 @@ bool CFMNetwork::open()
8490

8591
LogMessage("Opening FM network connection");
8692

87-
if (!m_squelchFile.empty()) {
88-
m_fp = ::fopen(m_squelchFile.c_str(), "wb");
89-
if (m_fp == NULL) {
93+
if (m_protocol == FMNP_RAW) {
94+
if (!m_squelchFile.empty()) {
95+
m_fp = ::fopen(m_squelchFile.c_str(), "wb");
96+
if (m_fp == NULL) {
9097
#if !defined(_WIN32) && !defined(_WIN64)
91-
LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno);
98+
LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno);
9299
#else
93-
LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError());
100+
LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError());
94101
#endif
95-
return false;
102+
return false;
103+
}
96104
}
97105
}
98106

107+
if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) {
108+
LogError("The resampler needed for non-native sample rates has not been included");
109+
return false;
110+
}
111+
99112
return m_socket.open(m_addr);
100113
}
101114

@@ -201,6 +214,7 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn)
201214

202215
unsigned int length = 0U;
203216

217+
#if defined(HAS_SRC)
204218
if (m_sampleRate != MMDVM_SAMPLERATE) {
205219
unsigned int nOut = (nIn * m_sampleRate) / MMDVM_SAMPLERATE;
206220

@@ -227,13 +241,16 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn)
227241
buffer[length++] = (val >> 8) & 0xFFU;
228242
}
229243
} else {
244+
#endif
230245
for (unsigned int i = 0U; i < nIn; i++) {
231246
short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE
232247

233248
buffer[length++] = (val >> 0) & 0xFFU;
234249
buffer[length++] = (val >> 8) & 0xFFU;
235250
}
251+
#if defined(HAS_SRC)
236252
}
253+
#endif
237254

238255
if (m_debug)
239256
CUtils::dump(1U, "FM Network Data Sent", buffer, length);
@@ -395,6 +412,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut)
395412
if (bytes == 0U)
396413
return 0U;
397414

415+
#if defined(HAS_SRC)
398416
if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) {
399417
unsigned int nIn = (nOut * m_sampleRate) / MMDVM_SAMPLERATE;
400418

@@ -427,6 +445,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut)
427445
return false;
428446
}
429447
} else {
448+
#endif
430449
if (bytes < nOut)
431450
nOut = bytes;
432451

@@ -437,7 +456,9 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut)
437456
short val = ((buffer[i * 2U + 0U] & 0xFFU) << 0) + ((buffer[i * 2U + 1U] & 0xFFU) << 8);
438457
out[i] = float(val) / 65536.0F;
439458
}
459+
#if defined(HAS_SRC)
440460
}
461+
#endif
441462

442463
return nOut;
443464
}

FMNetwork.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX
2+
* Copyright (C) 2020,2021,2023,2024 by Jonathan Naylor G4KLX
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -16,13 +16,15 @@
1616
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1717
*/
1818

19-
#ifndef FMNetwork_H
19+
#if !defined(FMNetwork_H)
2020
#define FMNetwork_H
2121

2222
#include "RingBuffer.h"
2323
#include "UDPSocket.h"
2424

25+
#if defined(HAS_SRC)
2526
#include <samplerate.h>
27+
#endif
2628

2729
#include <cstdint>
2830
#include <string>
@@ -65,7 +67,9 @@ class CFMNetwork {
6567
bool m_enabled;
6668
CRingBuffer<unsigned char> m_buffer;
6769
unsigned int m_seqNo;
70+
#if defined(HAS_SRC)
6871
SRC_STATE* m_resampler;
72+
#endif
6973
int m_error;
7074
FILE* m_fp;
7175

MMDVMHost.vcxproj

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@
8888
<WarningLevel>Level3</WarningLevel>
8989
<Optimization>Disabled</Optimization>
9090
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
91-
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
91+
<AdditionalIncludeDirectories>
92+
</AdditionalIncludeDirectories>
9293
</ClCompile>
9394
<Link>
9495
<SubSystem>Console</SubSystem>
9596
<GenerateDebugInformation>true</GenerateDebugInformation>
96-
<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>
97-
<AdditionalLibraryDirectories>..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
97+
<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>
98+
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
9899
</Link>
99100
</ItemDefinitionGroup>
100101
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -104,13 +105,14 @@
104105
<WarningLevel>Level3</WarningLevel>
105106
<Optimization>Disabled</Optimization>
106107
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107-
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
108+
<AdditionalIncludeDirectories>
109+
</AdditionalIncludeDirectories>
108110
</ClCompile>
109111
<Link>
110112
<SubSystem>Console</SubSystem>
111113
<GenerateDebugInformation>true</GenerateDebugInformation>
112-
<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>
113-
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
114+
<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>
115+
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
114116
</Link>
115117
<PreBuildEvent>
116118
<Command>"$(ProjectDir)prebuild.cmd" $(ProjectDir)</Command>
@@ -128,15 +130,16 @@
128130
<FunctionLevelLinking>true</FunctionLevelLinking>
129131
<IntrinsicFunctions>true</IntrinsicFunctions>
130132
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131-
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
133+
<AdditionalIncludeDirectories>
134+
</AdditionalIncludeDirectories>
132135
</ClCompile>
133136
<Link>
134137
<SubSystem>Console</SubSystem>
135138
<EnableCOMDATFolding>true</EnableCOMDATFolding>
136139
<OptimizeReferences>true</OptimizeReferences>
137140
<GenerateDebugInformation>true</GenerateDebugInformation>
138-
<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>
139-
<AdditionalLibraryDirectories>..\..\libsamplerate\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
141+
<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>
142+
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
140143
</Link>
141144
</ItemDefinitionGroup>
142145
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -148,15 +151,16 @@
148151
<FunctionLevelLinking>true</FunctionLevelLinking>
149152
<IntrinsicFunctions>true</IntrinsicFunctions>
150153
<PreprocessorDefinitions>HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
151-
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
154+
<AdditionalIncludeDirectories>
155+
</AdditionalIncludeDirectories>
152156
</ClCompile>
153157
<Link>
154158
<SubSystem>Console</SubSystem>
155159
<EnableCOMDATFolding>true</EnableCOMDATFolding>
156160
<OptimizeReferences>true</OptimizeReferences>
157161
<GenerateDebugInformation>true</GenerateDebugInformation>
158-
<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>
159-
<AdditionalLibraryDirectories>..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
162+
<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>
163+
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
160164
</Link>
161165
</ItemDefinitionGroup>
162166
<ItemGroup>

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# This makefile is for all platforms, but doesn't include support for the HD44780, OLED, or PCF8574 displays on the Raspberry Pi.
22

3+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
4+
35
CC = cc
46
CXX = c++
57
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -I/usr/local/include
6-
LIBS = -lpthread -lutil -lsamplerate
8+
LIBS = -lpthread -lutil
79
LDFLAGS = -g -L/usr/local/lib
810

911
OBJECTS = \

Makefile.Pi.Adafruit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed.
22
# Support for the Adafruit i2c 16 x 2 RGB LCD Pi Plate
33

4+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
5+
46
CC = cc
57
CXX = c++
68
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include
7-
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate
9+
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil
810
LDFLAGS = -g -L/usr/local/lib
911

1012
OBJECTS = \

Makefile.Pi.HD44780

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed.
22

3+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
4+
35
CC = cc
46
CXX = c++
57
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -I/usr/local/include
6-
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate
8+
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil
79
LDFLAGS = -g -L/usr/local/lib
810

911
OBJECTS = \

Makefile.Pi.I2C

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# This makefile is for use with the Raspberry Pi. The wiringpi library is needed.
22

3+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
4+
35
CC = cc
46
CXX = c++
57
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DRASPBERRY_PI -I/usr/local/include
6-
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate
8+
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil
79
LDFLAGS = -g -L/usr/local/lib
810

911
OBJECTS = \

Makefile.Pi.OLED

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# This makefile is for use with the Raspberry Pi when using an OLED display. The wiringpi library is not needed.
22

3+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
4+
35
CC = cc
46
CXX = c++
57
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DOLED -I/usr/local/include
6-
LIBS = -lArduiPi_OLED -lpthread -lutil -lsamplerate
8+
LIBS = -lArduiPi_OLED -lpthread -lutil
79

810
# If you use NetBSD, add following CFLAGS
911
#CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib

Makefile.Pi.PCF8574

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed.
22
# Support for the HD44780 connected via a PCF8574 8-bit GPIO expander IC
33

4+
# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line.
5+
46
CC = cc
57
CXX = c++
68
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include
7-
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate
9+
LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil
810
LDFLAGS = -g -L/usr/local/lib
911

1012
OBJECTS = \

0 commit comments

Comments
 (0)