Skip to content

Commit

Permalink
Make the FM resampler optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Apr 29, 2024
1 parent 738c82d commit 3f2a5d7
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 29 deletions.
5 changes: 3 additions & 2 deletions DStarNetwork.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
33 changes: 27 additions & 6 deletions FMNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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()
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -427,6 +445,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut)
return false;
}
} else {
#endif
if (bytes < nOut)
nOut = bytes;

Expand All @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions FMNetwork.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>
Expand Down Expand Up @@ -65,7 +67,9 @@ class CFMNetwork {
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;

Expand Down
28 changes: 16 additions & 12 deletions MMDVMHost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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'">
Expand All @@ -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>
Expand All @@ -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'">
Expand All @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.Pi.Adafruit
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.Pi.HD44780
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.Pi.I2C
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.Pi.OLED
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion Makefile.Pi.PCF8574
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20240223";
const char* VERSION = "20240429";

#endif

0 comments on commit 3f2a5d7

Please sign in to comment.