Skip to content

Commit

Permalink
Revert all samplerate changes. These will go in another PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Dec 4, 2024
1 parent 7b2e79d commit f1a66f0
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install codespell libpulse-dev libspeexdsp-dev libsoxr-dev sox git libwxgtk3.2-dev portaudio19-dev libhamlib-dev libasound2-dev libao-dev libgsm1-dev libsndfile-dev xvfb pipewire pulseaudio-utils pipewire-pulse wireplumber metacity dbus-x11 at-spi2-core rtkit
sudo apt-get install codespell libpulse-dev libspeexdsp-dev libsamplerate0-dev sox git libwxgtk3.2-dev portaudio19-dev libhamlib-dev libasound2-dev libao-dev libgsm1-dev libsndfile-dev xvfb pipewire pulseaudio-utils pipewire-pulse wireplumber metacity dbus-x11 at-spi2-core rtkit
- name: Spellcheck codebase
shell: bash
Expand Down
42 changes: 21 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ set(USE_STATIC_PORTAUDIO FALSE CACHE BOOL
"Download and build static portaudio instead of the system library.")
set(USE_STATIC_SNDFILE FALSE CACHE BOOL
"Download and build static sndfile instead of the system library.")
set(USE_STATIC_SOXR FALSE CACHE BOOL
"Download and build static soxr instead of the system library.")
set(USE_STATIC_SAMPLERATE FALSE CACHE BOOL
"Download and build static samplerate instead of the system library.")
set(USE_STATIC_SPEEXDSP FALSE CACHE BOOL
"Download and build static speex instead of the system library.")
set(BOOTSTRAP_WXWIDGETS FALSE CACHE BOOL
Expand Down Expand Up @@ -201,7 +201,7 @@ endif(SIGN_WINDOWS_BINARIES)
if(USE_STATIC_DEPS)
set(USE_STATIC_PORTAUDIO TRUE FORCE)
set(USE_STATIC_SNDFILE TRUE FORCE)
set(USE_STATIC_SOXR TRUE FORCE)
set(USE_STATIC_SAMPLERATE TRUE FORCE)
set(USE_STATIC_SPEEXDSP TRUE FORCE)
endif(USE_STATIC_DEPS)

Expand Down Expand Up @@ -488,25 +488,25 @@ endif(SIOCLIENT_LIBRARY AND SIOCLIENT_INCLUDE_DIR)


#
# Soxr Library
# Samplerate Library
#
if(NOT USE_STATIC_SOXR)
message(STATUS "Looking for soxr...")
find_library(LIBSOXR soxr)
find_path(LIBSOXR_INCLUDE_DIR soxr.h)
message(STATUS " soxr library: ${LIBSOXR}")
message(STATUS " soxr headers: ${LIBSOXR_INCLUDE_DIR}")
if(LIBSOXR AND LIBSOXR_INCLUDE_DIR)
list(APPEND FREEDV_LINK_LIBS ${LIBSOXR})
include_directories(${LIBSOXR_INCLUDE_DIR})
else(LIBSOXR AND LIBSOXR_INCLUDE_DIR)
message(STATUS "Will attempt static build of soxr.")
include(cmake/BuildSoxr.cmake)
endif(LIBSOXR AND LIBSOXR_INCLUDE_DIR)
else(NOT USE_STATIC_SOXR)
message(STATUS "Will attempt static build of soxr.")
include(cmake/BuildSoxr.cmake)
endif(NOT USE_STATIC_SOXR)
if(NOT USE_STATIC_SAMPLERATE)
message(STATUS "Looking for samplerate...")
find_library(LIBSAMPLERATE samplerate)
find_path(LIBSAMPLERATE_INCLUDE_DIR samplerate.h)
message(STATUS " samplerate library: ${LIBSAMPLERATE}")
message(STATUS " samplerate headers: ${LIBSAMPLERATE_INCLUDE_DIR}")
if(LIBSAMPLERATE AND LIBSAMPLERATE_INCLUDE_DIR)
list(APPEND FREEDV_LINK_LIBS ${LIBSAMPLERATE})
include_directories(${LIBSAMPLERATE_INCLUDE_DIR})
else(LIBSTAMPLERATE AND LIBSAMPLERATE_INCLUDE_DIR)
message(STATUS "Will attempt static build of samplerate.")
include(cmake/BuildSamplerate.cmake)
endif(LIBSAMPLERATE AND LIBSAMPLERATE_INCLUDE_DIR)
else(NOT USE_STATIC_SAMPLERATE)
message(STATUS "Will attempt static build of samplerate.")
include(cmake/BuildSamplerate.cmake)
endif(NOT USE_STATIC_SAMPLERATE)

#
# sndfile Library
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This document describes how to build the FreeDV GUI program for various operatin
## Building on Ubuntu Linux

```
$ sudo apt install libspeexdsp-dev libsoxr-dev sox git \
$ sudo apt install libspeexdsp-dev libsamplerate0-dev sox git \
libwxgtk3.2-dev libhamlib-dev libasound2-dev libao-dev \
libgsm1-dev libsndfile1-dev cmake module-assistant build-essential
$ git clone https://github.com/drowe67/freedv-gui.git
Expand All @@ -37,7 +37,7 @@ This document describes how to build the FreeDV GUI program for various operatin
## Building on Fedora Linux
```
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf install cmake wxGTK3-devel soxr-devel \
$ sudo dnf install cmake wxGTK3-devel libsamplerate-devel \
libsndfile-devel speexdsp-devel hamlib-devel alsa-lib-devel libao-devel \
gsm-devel gcc-c++ sox
$ git clone https://github.com/drowe67/freedv-gui.git
Expand Down
24 changes: 24 additions & 0 deletions cmake/BuildSamplerate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(SAMPLERATE_VERSION "0.2.2")

set(BUILD_TESTING OFF CACHE BOOL "Enable unit tests for libsamplerate")

include(FetchContent)
FetchContent_Declare(
samplerate
GIT_REPOSITORY https://github.com/libsndfile/libsamplerate.git
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
GIT_TAG 0.2.2
)

FetchContent_GetProperties(samplerate)
if(NOT samplerate_POPULATED)
FetchContent_Populate(samplerate)
add_subdirectory(${samplerate_SOURCE_DIR} ${samplerate_BINARY_DIR} EXCLUDE_FROM_ALL)
list(APPEND FREEDV_PACKAGE_SEARCH_PATHS ${samplerate_BINARY_DIR}/src)
endif()

list(APPEND FREEDV_LINK_LIBS samplerate)

target_include_directories(samplerate BEFORE PRIVATE ${samplerate_BINARY_DIR})
include_directories(${samplerate_SOURCE_DIR}/include)
25 changes: 0 additions & 25 deletions cmake/BuildSoxr.cmake

This file was deleted.

1 change: 0 additions & 1 deletion cmake/GetDependencies.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ set( _windlls
OLEACC.dll
msvcrt.dll
bcrypt.dll
PSAPI.DLL

# The below are additional DLLs required when compiled
# using the LLVM version of MinGW.
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if(APPLE)
TARGET FreeDV
POST_BUILD
COMMAND rm -rf dist_tmp FreeDV.dmg || true
COMMAND DYLD_LIBRARY_PATH=${CODEC2_BUILD_DIR}/src:${LPCNET_DYLIBBUNDLER_PATH}${portaudio_BINARY_DIR}:${soxr_BINARY_DIR}/src:${Python3_ROOT_DIR}:${DYLD_LIBRARY_PATH} ${CMAKE_SOURCE_DIR}/macdylibbundler/dylibbundler ARGS -od -b -x FreeDV.app/Contents/MacOS/FreeDV -d FreeDV.app/Contents/libs -p @loader_path/../libs/ -i /usr/lib ${LPCNET_DYLIBBUNDLER_ARG} -s ${CODEC2_BUILD_DIR}/src -s ${CMAKE_BINARY_DIR}/LPCNet_build/src -s ${CMAKE_BINARY_DIR}/codec2_build/src -s ${portaudio_BINARY_DIR} -s ${soxr_BINARY_DIR}/src -s ${rade_BINARY_DIR}/src -s ${Python3_ROOT_DIR}
COMMAND DYLD_LIBRARY_PATH=${CODEC2_BUILD_DIR}/src:${LPCNET_DYLIBBUNDLER_PATH}${portaudio_BINARY_DIR}:${samplerate_BINARY_DIR}/src:${Python3_ROOT_DIR}:${DYLD_LIBRARY_PATH} ${CMAKE_SOURCE_DIR}/macdylibbundler/dylibbundler ARGS -od -b -x FreeDV.app/Contents/MacOS/FreeDV -d FreeDV.app/Contents/libs -p @loader_path/../libs/ -i /usr/lib ${LPCNET_DYLIBBUNDLER_ARG} -s ${CODEC2_BUILD_DIR}/src -s ${CMAKE_BINARY_DIR}/LPCNet_build/src -s ${CMAKE_BINARY_DIR}/codec2_build/src -s ${portaudio_BINARY_DIR} -s ${samplerate_BINARY_DIR}/src -s ${rade_BINARY_DIR}/src -s ${Python3_ROOT_DIR}
COMMAND cp ARGS ${CMAKE_CURRENT_SOURCE_DIR}/freedv.icns FreeDV.app/Contents/Resources
COMMAND rm ARGS -rf FreeDV.app/Contents/Frameworks
COMMAND mkdir ARGS FreeDV.app/Contents/Frameworks
Expand Down
2 changes: 2 additions & 0 deletions src/freedv_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern "C"
#include "lpcnet.h"
}

#include <samplerate.h>

class IPipelineStep;
class ParallelStep;
class RADETransmitStep;
Expand Down
59 changes: 10 additions & 49 deletions src/gui/dialogs/dlg_audiooptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <wx/app.h>
#include <wx/confbase.h>

#include <soxr.h>

#include "dlg_audiooptions.h"

#include "audio/AudioEngineFactory.h"
Expand Down Expand Up @@ -837,8 +835,9 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(wxString devName, PlotScalar *p
m_audioPlotThread = new std::thread([&](wxString devName, PlotScalar* ps) {
std::mutex callbackFifoMutex;
std::condition_variable callbackFifoCV;
SRC_STATE *src;
FIFO *fifo, *callbackFifo;
soxr_t src = nullptr;
int src_error;

// Reset plot before starting.
CallAfter([&]() {
Expand All @@ -847,6 +846,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(wxString devName, PlotScalar *p
});

fifo = codec2_fifo_create((int)(DT*TEST_WAVEFORM_PLOT_FS*2)); assert(fifo != NULL);
src = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(src != NULL);

auto engine = AudioEngineFactory::GetAudioEngine();
auto devList = engine->getAudioDeviceList(IAudioEngine::AUDIO_ENGINE_IN);
Expand All @@ -856,19 +856,6 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(wxString devName, PlotScalar *p
{
int sampleCount = 0;
int sampleRate = wxAtoi(m_cbSampleRateRxIn->GetValue());

soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I);
src = soxr_create(
sampleRate,
8000,
1,
nullptr,
&ioSpec,
nullptr, // soxr_quality_spec(SOXR_HQ, 0)
nullptr // soxr_runtime_spec(1)
);
assert(src != NULL);

auto device = engine->getAudioDevice(
devInfo.name,
IAudioEngine::AUDIO_ENGINE_IN,
Expand Down Expand Up @@ -908,11 +895,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(wxString devName, PlotScalar *p
}
}

size_t inputUsed = 0;
size_t n8k = 0;
soxr_process(
src, in48k_short, TEST_BUF_SIZE, &inputUsed,
in8k_short, TEST_BUF_SIZE, &n8k);
int n8k = resample(src, in8k_short, in48k_short, 8000, sampleRate, TEST_BUF_SIZE, TEST_BUF_SIZE);
resample_for_plot(fifo, in8k_short, n8k, FS);

short plotSamples[TEST_WAVEFORM_PLOT_BUF];
Expand Down Expand Up @@ -947,10 +930,7 @@ void AudioOptsDialog::plotDeviceInputForAFewSecs(wxString devName, PlotScalar *p
}

codec2_fifo_destroy(fifo);
if (src != nullptr)
{
soxr_delete(src);
}
src_delete(src);

CallAfter([&]() {
m_audioPlotThread->join();
Expand Down Expand Up @@ -980,9 +960,9 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(wxString devName, PlotScalar *
m_btnTxOutTest->Enable(false);

m_audioPlotThread = new std::thread([&](wxString devName, PlotScalar* ps) {
SRC_STATE *src;
FIFO *fifo, *callbackFifo;
int n = 0;
soxr_t src = nullptr;
int src_error, n = 0;

// Reset plot before starting.
CallAfter([&]() {
Expand All @@ -991,6 +971,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(wxString devName, PlotScalar *
});

fifo = codec2_fifo_create((int)(DT*TEST_WAVEFORM_PLOT_FS*2)); assert(fifo != NULL);
src = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(src != NULL);

auto engine = AudioEngineFactory::GetAudioEngine();
auto devList = engine->getAudioDeviceList(IAudioEngine::AUDIO_ENGINE_OUT);
Expand All @@ -1000,19 +981,6 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(wxString devName, PlotScalar *
{
int sampleCount = 0;
int sampleRate = wxAtoi(m_cbSampleRateRxIn->GetValue());

soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I);
src = soxr_create(
sampleRate,
8000,
1,
nullptr,
&ioSpec,
nullptr, // soxr_quality_spec(SOXR_HQ, 0)
nullptr // soxr_runtime_spec(1)
);
assert(src != NULL);

auto device = engine->getAudioDevice(
devInfo.name,
IAudioEngine::AUDIO_ENGINE_OUT,
Expand Down Expand Up @@ -1060,11 +1028,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(wxString devName, PlotScalar *
}
}

size_t inputUsed = 0;
size_t n8k = 0;
soxr_process(
src, out48k_short, TEST_BUF_SIZE, &inputUsed,
out8k_short, TEST_BUF_SIZE, &n8k);
int n8k = resample(src, out8k_short, out48k_short, 8000, sampleRate, TEST_BUF_SIZE, TEST_BUF_SIZE);
resample_for_plot(fifo, out8k_short, n8k, FS);

short plotSamples[TEST_WAVEFORM_PLOT_BUF];
Expand Down Expand Up @@ -1100,10 +1064,7 @@ void AudioOptsDialog::plotDeviceOutputForAFewSecs(wxString devName, PlotScalar *
}

codec2_fifo_destroy(fifo);
if (src != nullptr)
{
soxr_delete(src);
}
src_delete(src);

CallAfter([&]() {
m_audioPlotThread->join();
Expand Down
9 changes: 1 addition & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int g_tx;
float g_snr;
bool g_half_duplex;
bool g_voice_keyer_tx;
SRC_STATE *g_spec_src; // sample rate converter for spectrum

// sending and receiving Call Sign data
struct FIFO *g_txDataInFifo;
Expand Down Expand Up @@ -518,14 +519,6 @@ bool MainApp::OnInit()

#endif // _WIN32 || __APPLE__

#if __aarch64__
// For 64-bit ARM, it's safe to assume some form of SIMD is available,
// so make sure we enable it for soxr. (soxr will auto-enable on x86
// as appropriate, so no need to explicitly force on that platform).
wxSetEnv("SOXR_USE_SIMD32", "1");
wxSetEnv("SOXR_USE_SIMD64", "1");
#endif // __aarch64__

#if defined(UNOFFICIAL_RELEASE)
// Terminate the application if the current date > expiration date
wxDateTime buildDate;
Expand Down
10 changes: 10 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <wx/regex.h>
#include <wx/socket.h>

#include <samplerate.h>

#include <stdint.h>
#include <speex/speex_preprocess.h>
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
Expand Down Expand Up @@ -517,6 +519,14 @@ class MainFrame : public TopFrame

void resample_for_plot(struct FIFO *plotFifo, short buf[], int length, int fs);

int resample(SRC_STATE *src,
short output_short[],
short input_short[],
int output_sample_rate,
int input_sample_rate,
int length_output_short, // maximum output array length in samples
int length_input_short
);
void txRxProcessing();

// FreeDv API calls this when there is a test frame that needs a-plottin'
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ add_library(fdv_audio_pipeline STATIC

target_include_directories(fdv_audio_pipeline PRIVATE ${CODEC2_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/..)

add_dependencies(fdv_audio_pipeline rade opus codec2)
add_dependencies(fdv_audio_pipeline rade opus)

if(BOOTSTRAP_WXWIDGETS)
add_dependencies(fdv_audio_pipeline wx::core wx::base wx::aui wx::html wx::net wx::adv wx::propgrid wx::xrc)
Expand All @@ -36,7 +36,7 @@ endif(BOOTSTRAP_WXWIDGETS)
if(UNITTEST)
macro(DefineUnitTest utName)
add_executable(${utName} test/${utName}.cpp)
target_link_libraries(${utName} PRIVATE fdv_audio_pipeline fdv_util codec2)
target_link_libraries(${utName} PRIVATE fdv_audio_pipeline fdv_util)
target_include_directories(${utName} PRIVATE ${CODEC2_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/..)

add_test(NAME pipeline_${utName} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${utName})
Expand Down
Loading

0 comments on commit f1a66f0

Please sign in to comment.