AI-Assisted Development & Documentation: This tool and its documentation were developed with substantial assistance from Artificial Intelligence (AI), specifically Large Language Models (LLMs). AI played a significant role in:
- Generating initial code structures (threading pipeline, buffer management, argument parsing).
- Refactoring code for better organization, error handling, and platform compatibility (POSIX/Windows).
- Implementing DSP integration (liquid-dsp) and metadata parsing (expat).
- Debugging logical errors and suggesting fixes.
- Generating platform-specific code (e.g., Windows path handling, file I/O).
- Explaining concepts (threading, DSP, file formats).
- Writing documentation, including this HTML page.
Human oversight directed the process, defined specifications, reviewed code, performed testing, and made final decisions, but the AI contribution was integral to development. While efforts were made to ensure quality, the significant reliance on AI means the resulting codebase might exhibit some inconsistencies, areas needing optimization, or contain undiscovered bugs.
Overview
nrsc5_resample_tool
is a command-line utility designed to read I/Q data from WAV files (common output from SDR software), optionally apply frequency shifting, resample the data to specific rates required by the open source nrsc5
(HD Radio) decoder, apply amplitude scaling, and output the result as raw complex samples (either 8-bit unsigned or 16-bit signed). Its main purpose is to take I/Q files recorded by various SDR programs and process them into a format suitable for playback with the open-source nrsc5
decoder.
It leverages a multi-threaded pipeline (Reader -> Processor -> Writer) to improve performance on multi-core systems. It uses the liquid-dsp
library for high-quality resampling and frequency shifting (NCO), libsndfile
for robust WAV file handling, and expat
for parsing XML metadata found in some SDR recording formats.
Core Features
- Reads 2-channel (I/Q) WAV files: 8-bit Signed/Unsigned PCM, 16-bit Signed PCM.
- Outputs raw complex samples in specified formats:
cu8
: Complex Unsigned 8-bit (Target Rate: 1488375.0 Hz) AM/FMcs16_fm
: Complex Signed 16-bit (Target Rate: 744187.5 Hz) FMcs16_am
: Complex Signed 16-bit (Target Rate: 46511.71875 Hz) AM
- High-quality resampling using liquid-dsp (
msresamp_crcf
). - Optional frequency shifting using liquid-dsp NCO (
nco_crcf
):-F
: Apply an absolute frequency shift.-c
: Shift based on input file metadata (requires center frequency info in file).-x
: Option to apply the shift after resampling (useful if shift exceeds input Nyquist).
- Customizable amplitude scaling (
-s
) applied before resampling. - Parses SDR metadata from:
- SDR Console / SDRuno / SDRconnect
auxi
chunks (XML or Binary format via expat/custom parsing). - SDR# filename patterns (Timestamp and Frequency).
- SDR Console / SDRuno / SDRconnect
- Utilizes a multi-threaded pipeline (Reader, Processor, Writer) with thread-safe queues for efficient processing.
- Output to file (
-f
) or stdout (-o
). - Cross-platform: Builds and runs on Linux, macOS (POSIX) and Windows. Handles platform differences (paths, binary stdout).
- Provides progress indication and informative configuration summary (when not writing to stdout).
- Includes Nyquist warnings for potentially problematic frequency shifts.
Dependencies
Before building, you need the following installed:
- CMake (Version 3.10 or higher recommended)
- A C Compiler (GCC, Clang, MSVC)
- Required Libraries (libsndfile, liquid-dsp, Expat, pthreads):
- Debian/Ubuntu:
sudo apt install libsndfile1-dev libliquid-dev libexpat1-dev
- Fedora:
sudo dnf install libsndfile-devel liquid-dsp-devel expat-devel
- macOS (Homebrew):
brew install libsndfile liquid-dsp expat
- Windows (vcpkg):
(pthread support typically handled by vcpkg/compiler setup)vcpkg install libsndfile libliquid expat
- Debian/Ubuntu:
Note: For Windows without vcpkg, ensure your build environment (e.g., MinGW-w64) provides pthreads support. Package names might vary slightly between distributions or versions. Ensure you install the development packages containing header files unless using a package manager like vcpkg or Homebrew which usually handles this.
Building the Tool (CMake) Linux
- Navigate to the root directory of the project in your terminal.
- Create a build directory:
mkdir build
- Change into the build directory:
cd build
- Run CMake to configure the project. You might need to tell CMake where to find dependencies if they aren't in standard locations (e.g., using
-DCMAKE_PREFIX_PATH=/path/to/libs
or toolchain files for vcpkg).cmake ..
(Use
cmake .. -G "Your Generator"
if needed, e.g., for Visual Studio on Windows). - Build the project (the
-j 4
suggests using 4 parallel jobs, adjust as needed):make -j 4
(Or use the appropriate build command for your generator, e.g.,
cmake --build . --config Release
for MSVC). - (Optional) Install the executable to the location specified in CMakeLists.txt (often
/usr/local/bin
or similar):sudo make install
(Requires appropriate permissions).
After building or downloading, the executable (e.g., nrsc5_resample_tool.exe
or nrsc5_resample_tool
) will be located in the build directory (or the installation path).
Windows Users: This is a command-line application. You must run it from a terminal like Command Prompt (cmd.exe
), PowerShell, or Windows Terminal. Do not simply double-click the .exe
file. You also need the runtime DLLs for libsndfile, liquid-dsp, expat, pthreads (e.g., libwinpthread-1.dll
), and potentially the C runtime (e.g., libgcc_s_seh-1.dll
for MinGW) to be accessible (either in the same directory as the executable or in the system's PATH). Using vcpkg often simplifies managing these dependencies.
Command-Line Options
The tool accepts the following command-line arguments:
Usage: ./nrsc5_resample_tool -i <input.wav> -m <mode_name> [-s <scale_value>] [-F <shift_freq_hz>] [-c <target_freq_hz>] [-x] { -f <output_file> | -o }
Options:
-i <file> I/Q input file (8-bit Signed/Unsigned WAV or 16-bit Signed WAV (Required).
-m <mode_name> Output mode (Required): cu8, cs16_fm, cs16_am
-s <value> Scaling factor applied before resampling (effectively scales input samples).
(Optional, Default: 0.02000 for cu8, 0.500 for cs16). Affects amplitude.
-F <shift_freq_hz> Apply frequency shift in Hz before resampling.
Mutually exclusive with -c. (Optional).
-c <target_freq_hz> Shift signal so original center frequency moves to <target_freq_hz> (Requires center frequency metadata).
Mutually exclusive with -F. (Optional).
-x Apply frequency shift AFTER resampling (default is before).
Useful if required shift exceeds input Nyquist limit.
-f <file> Output to file.
-o Output to stdout (binary format, suppresses most messages).
Note: -f and -o are mutually exclusive; -F and -c are mutually exclusive.
Usage Examples
Example 1: Basic Conversion (16-bit WAV to CU8 File)
Convert a standard 16-bit signed IQ recording to the cu8 format required by `nrsc5`, using default scaling.
$ ./nrsc5_resample_tool -i recording_16bit.wav -m cu8 -f output.cu8
---Input Details---
Input File: /path/to/recording_16bit.wav
Input Format: 16-bit Signed PCM
Input Rate: 2048000.0 Hz
Input File Size: 1.91 GB
Timestamp: 01-15-2024 10:30:05 UTC
Center Frequency: 97.900000 MHz
SDR Software: SDR Console 3.3
---Output Details---
Output Mode: cu8 (Unsigned 8-bit Complex)
Output Rate: 1488375 Hz
Scale Factor: 0.02000
Frequency Shift: +0.00 Hz (Applied Before Resampling)
Output File: /path/to/output.cu8
Starting Resample...
Processed 500000000 / 500000000 input frames (100.0%)... Done.
Total output frames generated: 363373
Total output samples generated: 726746
Output File Size: 726.75 KB
Resample operation completed successfully.
Example 2: Conversion with Absolute Frequency Shift and Scaling
Convert a 16-bit signed WAV, apply a +400 kHz frequency shift (-F
), use custom scaling, and output as cu8.
$ ./nrsc5_resample_tool -i sdrsharp_rec_16bit.wav -m cu8 -F 400000 -s 0.015 -f output_shifted.cu8
---Input Details---
Input File: /data/sdrsharp_rec_16bit.wav
Input Format: 16-bit Signed PCM
Input Rate: 1800000.0 Hz
Input File Size: 1.02 GB
Timestamp: 2024-01-15 11:05:20 UTC
Center Frequency: 101.100000 MHz
SDR Software: SDR#
---Output Details---
Output Mode: cu8 (Unsigned 8-bit Complex)
Output Rate: 1488375 Hz
Scale Factor: 0.01500
Frequency Shift: +400000.00 Hz (Applied Before Resampling)
Output File: /data/output_shifted.cu8
Starting Resample...
Processed 284444444 / 284444444 input frames (100.0%)... Done.
Total output frames generated: 235994
Total output samples generated: 471988
Output File Size: 471.99 KB
Resample operation completed successfully.
Example 3: Metadata Shift to Target Frequency, Output to Stdout for nrsc5
Convert a 16-bit signed WAV file recorded by SDR Console (assume its metadata indicates 93.3 MHz), shift it so the signal is centered at 98.5 MHz (-c 98.5e6
), and pipe the resulting cu8 output directly to the nrsc5
decoder.
$ ./nrsc5_resample_tool -i sdrc_rec_16bit.wav -m cu8 -c 98.5e6 -o | nrsc5 -r - 0
(Binary data piped to nrsc5...)
(No progress or summary printed to stderr when using -o)
Note: When using -o
, most informational messages are suppressed to keep stderr clean. Only fatal errors are typically printed. The binary output goes directly to standard output.
Disclaimer of Warranty & Limitation of Liability
This software is provided "AS IS", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
You use this software entirely at your own risk.
Downloads
Choose the appropriate binary for your CPU, or download the source code.
Download Windows Binary 64-bit (AVX2) Download Windows Binary 64-bit (AVX)Download Source Code (.zip)
Windows Binary Requirements & Notes:
- Operating System: Windows 8 64-bit or newer
- CPU Instruction Set: Binaries require specific CPU features.
- The AVX2 build requires a CPU supporting AVX2 instructions (generally Intel Haswell / AMD Excavator generation or newer, ~2013+). May offer better performance.
- The AVX build requires a CPU supporting AVX instructions (generally Intel Sandy Bridge / AMD Bulldozer generation or newer, ~2011+). More compatible with older hardware.
Important Compatibility Warning:
Running a binary that requires newer instructions than your CPU supports (e.g., running the AVX2 build on an AVX-only CPU, or either on a very old CPU without AVX) will cause the program to crash or close immediately upon starting. You might see a generic "program has stopped working" message, or it might simply disappear without warning. Please verify your CPU's capabilities before downloading. (The underlying reason is an "Illegal Instruction" processor exception).
Recommended Check: The easiest way to check if your CPU supports the necessary instructions (AVX and AVX2) is to download and run our dedicated CPU Checker tool:
Download AVX CPU Compatibility Checker 64-bit
Alternatively, if you prefer not to download the checker, you can check manually using tools like CPU-Z (look for AVX/AVX2 in the Instructions field) or by searching your CPU model online (e.g., "Intel Core i5-8400 instruction sets").
Note: Building from source is recommended for other platforms (Linux, macOS), for systems not meeting the Windows requirements, or for modifications.