mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
stuff for developing, actual debug mode as well as add the vban protocol specs
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -27,7 +27,10 @@
|
|||||||
"getopt.h": "c",
|
"getopt.h": "c",
|
||||||
"audio.h": "c",
|
"audio.h": "c",
|
||||||
"signal.h": "c",
|
"signal.h": "c",
|
||||||
"debug.h": "c"
|
"debug.h": "c",
|
||||||
|
"array": "c",
|
||||||
|
"string": "c",
|
||||||
|
"string_view": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "disabled"
|
"C_Cpp.errorSquiggles": "disabled"
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,11 @@ project(FMTools LANGUAGES C)
|
|||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED YES)
|
set(CMAKE_C_STANDARD_REQUIRED YES)
|
||||||
|
|
||||||
|
# Set default build type if not specified
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB SRC_FILES "src/*.c")
|
file(GLOB SRC_FILES "src/*.c")
|
||||||
|
|
||||||
file(GLOB DSP_FILES "dsp/*.c")
|
file(GLOB DSP_FILES "dsp/*.c")
|
||||||
@@ -19,6 +24,12 @@ add_library(libfmdsp OBJECT ${DSP_FILES})
|
|||||||
|
|
||||||
add_library(libfmio OBJECT ${IO_FILES})
|
add_library(libfmio OBJECT ${IO_FILES})
|
||||||
|
|
||||||
|
# Define DEBUG macro for Debug builds on libraries
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_compile_definitions(libfmdsp PRIVATE DEBUG=1)
|
||||||
|
target_compile_definitions(libfmio PRIVATE DEBUG=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(FM_LIBS libfmio libfmdsp pulse pulse-simple m liquid)
|
set(FM_LIBS libfmio libfmdsp pulse pulse-simple m liquid)
|
||||||
|
|
||||||
foreach(SRC_FILE ${SRC_FILES})
|
foreach(SRC_FILE ${SRC_FILES})
|
||||||
@@ -28,6 +39,11 @@ foreach(SRC_FILE ${SRC_FILES})
|
|||||||
target_compile_options(${EXEC_NAME} PRIVATE -O2 -Wall -Wextra -Werror -Wno-unused-parameter)
|
target_compile_options(${EXEC_NAME} PRIVATE -O2 -Wall -Wextra -Werror -Wno-unused-parameter)
|
||||||
target_link_libraries(${EXEC_NAME} PRIVATE ${FM_LIBS})
|
target_link_libraries(${EXEC_NAME} PRIVATE ${FM_LIBS})
|
||||||
|
|
||||||
|
# Define DEBUG macro for Debug builds
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_compile_definitions(${EXEC_NAME} PRIVATE DEBUG=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
install(TARGETS ${EXEC_NAME}
|
install(TARGETS ${EXEC_NAME}
|
||||||
DESTINATION /usr/bin
|
DESTINATION /usr/bin
|
||||||
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ void init_modulation_power_measure(MPXPowerMeasurement* mpx, int sample_rate) {
|
|||||||
mpx->sample_counter = 0;
|
mpx->sample_counter = 0;
|
||||||
mpx->sample = 0;
|
mpx->sample = 0;
|
||||||
mpx->sample_rate = sample_rate;
|
mpx->sample_rate = sample_rate;
|
||||||
|
#ifdef BS412_DEBUG
|
||||||
|
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float measure_mpx(MPXPowerMeasurement* mpx, float deviation) {
|
float measure_mpx(MPXPowerMeasurement* mpx, float deviation) {
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define BS412_DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
#include "../lib/debug.h"
|
#include "../lib/debug.h"
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ void init_refrenced_fm_modulator(RefrencedFMModulator* fm, Oscillator* osc, floa
|
|||||||
fm->osc = osc;
|
fm->osc = osc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float refrenced_modulate_fm(RefrencedFMModulator* fm, float sample) {
|
float refrenced_modulate_fm(RefrencedFMModulator* fm, float sample, float phase_multiplier) {
|
||||||
float inst_freq = sample * fm->deviation;
|
float inst_freq = sample * fm->deviation;
|
||||||
float phase = fm->osc->phase + ((M_2PI * inst_freq) / fm->osc->sample_rate);
|
float phase = (fm->osc->phase * phase_multiplier) + ((M_2PI * inst_freq) / fm->osc->sample_rate);
|
||||||
|
|
||||||
if (phase >= M_2PI) {
|
if (phase >= M_2PI) {
|
||||||
phase -= M_2PI;
|
phase -= M_2PI;
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ typedef struct
|
|||||||
Oscillator* osc;
|
Oscillator* osc;
|
||||||
} RefrencedFMModulator;
|
} RefrencedFMModulator;
|
||||||
void init_refrenced_fm_modulator(RefrencedFMModulator *fm, Oscillator *osc, float deviation);
|
void init_refrenced_fm_modulator(RefrencedFMModulator *fm, Oscillator *osc, float deviation);
|
||||||
float refrenced_modulate_fm(RefrencedFMModulator *fm, float sample);
|
float refrenced_modulate_fm(RefrencedFMModulator *fm, float sample, float phase_multiplier);
|
||||||
|
|||||||
16
io/audio.c
16
io/audio.c
@@ -1,6 +1,10 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
|
||||||
int init_PulseInputDevice(PulseInputDevice* dev, int sample_rate, int channels, char* app_name, char *stream_name, char* device, pa_buffer_attr* buffer_attr) {
|
int init_PulseInputDevice(PulseInputDevice* dev, int sample_rate, int channels, char* app_name, char *stream_name, char* device, pa_buffer_attr* buffer_attr) {
|
||||||
|
#ifdef PULSE_DEBUG
|
||||||
|
debug_printf("Initializing PulseInputDevice with app_name: %s, stream_name: %s, device: %s, sample_rate: %d, channels: %d\n", app_name, stream_name, device, sample_rate, channels);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dev->initialized) return -1;
|
if (dev->initialized) return -1;
|
||||||
pa_sample_spec sample_spec = {
|
pa_sample_spec sample_spec = {
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
.format = PA_SAMPLE_FLOAT32NE,
|
||||||
@@ -33,6 +37,10 @@ int init_PulseInputDevice(PulseInputDevice* dev, int sample_rate, int channels,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int init_PulseInputDevicef(PulseInputDevice* dev, int sample_rate, int channels, char* app_name, char *stream_name, char* device, pa_buffer_attr* buffer_attr, enum pa_sample_format format) {
|
int init_PulseInputDevicef(PulseInputDevice* dev, int sample_rate, int channels, char* app_name, char *stream_name, char* device, pa_buffer_attr* buffer_attr, enum pa_sample_format format) {
|
||||||
|
#ifdef PULSE_DEBUG
|
||||||
|
debug_printf("Initializing PulseInputDevice format with app_name: %s, stream_name: %s, device: %s, sample_rate: %d, channels: %d, format: %d\n", app_name, stream_name, device, sample_rate, channels, format);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dev->initialized) return -1;
|
if (dev->initialized) return -1;
|
||||||
pa_sample_spec sample_spec = {
|
pa_sample_spec sample_spec = {
|
||||||
.format = format,
|
.format = format,
|
||||||
@@ -79,6 +87,10 @@ int read_PulseInputDevicef(PulseInputDevice* dev, void* buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_PulseInputDevice(PulseInputDevice* dev) {
|
void free_PulseInputDevice(PulseInputDevice* dev) {
|
||||||
|
#ifdef PULSE_DEBUG
|
||||||
|
debug_printf("Freeing PulseInputDevice with app_name: %s, stream_name: %s, device: %s\n", dev->app_name, dev->stream_name, dev->device);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dev->dev && dev->initialized) pa_simple_free(dev->dev);
|
if (dev->dev && dev->initialized) pa_simple_free(dev->dev);
|
||||||
free(dev->app_name);
|
free(dev->app_name);
|
||||||
free(dev->stream_name);
|
free(dev->stream_name);
|
||||||
@@ -165,6 +177,10 @@ int write_PulseOutputDevicef(PulseOutputDevice* dev, void* buffer, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_PulseOutputDevice(PulseOutputDevice* dev) {
|
void free_PulseOutputDevice(PulseOutputDevice* dev) {
|
||||||
|
#ifdef PULSE_DEBUG
|
||||||
|
debug_printf("Freeing PulseOutputDevice with app_name: %s, stream_name: %s, device: %s\n", dev->app_name, dev->stream_name, dev->device);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dev->dev && dev->initialized) pa_simple_free(dev->dev);
|
if (dev->dev && dev->initialized) pa_simple_free(dev->dev);
|
||||||
free(dev->app_name);
|
free(dev->app_name);
|
||||||
free(dev->stream_name);
|
free(dev->stream_name);
|
||||||
|
|||||||
@@ -5,6 +5,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define PULSE_DEBUG
|
||||||
|
#endif
|
||||||
|
#ifdef PULSE_DEBUG
|
||||||
|
#include "../lib/debug.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
pa_simple* dev;
|
pa_simple* dev;
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
|
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
|
||||||
|
#ifdef DEBUG
|
||||||
|
#pragma message("Using ARM NEON optimizations")
|
||||||
|
#endif
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#define USE_NEON 1
|
#define USE_NEON 1
|
||||||
#else
|
#else
|
||||||
|
#ifdef DEBUG
|
||||||
|
#pragma message("ARM NEON optimizations not available")
|
||||||
|
#endif
|
||||||
#define USE_NEON 0
|
#define USE_NEON 0
|
||||||
#endif
|
#endif
|
||||||
BIN
specifications/vban95/VBANProtocol_Specifications.pdf
Normal file
BIN
specifications/vban95/VBANProtocol_Specifications.pdf
Normal file
Binary file not shown.
20
src/vban95.c
20
src/vban95.c
@@ -22,7 +22,7 @@
|
|||||||
#define MAX_AUDIO_DATA_SIZE (BUF_SIZE - sizeof(VBANHeader))
|
#define MAX_AUDIO_DATA_SIZE (BUF_SIZE - sizeof(VBANHeader))
|
||||||
#define MAX_BUFFER_PACKETS 128
|
#define MAX_BUFFER_PACKETS 128
|
||||||
|
|
||||||
#define POLL_TIMEOUT_MS 100
|
#define POLL_TIMEOUT_MS 75
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char data[MAX_AUDIO_DATA_SIZE];
|
char data[MAX_AUDIO_DATA_SIZE];
|
||||||
@@ -326,6 +326,11 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strncmp(data.packet_data.streamname, stream_name, sizeof(data.packet_data.streamname)) != 0) continue;
|
||||||
|
|
||||||
|
char* audio_data = buffer + sizeof(VBANHeader);
|
||||||
|
size_t audio_data_size = recv_len - sizeof(VBANHeader);
|
||||||
#if 0
|
#if 0
|
||||||
if (vban_frame == 0) {
|
if (vban_frame == 0) {
|
||||||
vban_frame = data.packet_data.frame_num;
|
vban_frame = data.packet_data.frame_num;
|
||||||
@@ -340,8 +345,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
AudioPacket blank_packet;
|
AudioPacket blank_packet;
|
||||||
uint8_t fill_value = (data.packet_data.format_type == 0) ? 0 : 128;
|
uint8_t fill_value = (data.packet_data.format_type == 0) ? 0 : 128;
|
||||||
memset(blank_packet.data, fill_value, recv_len - sizeof(VBANHeader));
|
memset(blank_packet.data, fill_value, audio_data_size);
|
||||||
blank_packet.size = recv_len - sizeof(VBANHeader);
|
blank_packet.size = audio_data_size;
|
||||||
|
|
||||||
VBANHeaderUnion temp;
|
VBANHeaderUnion temp;
|
||||||
memset(blank_packet.data, 0, blank_packet.size);
|
memset(blank_packet.data, 0, blank_packet.size);
|
||||||
@@ -360,8 +365,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (strncmp(data.packet_data.streamname, stream_name, sizeof(data.packet_data.streamname)) != 0) continue;
|
|
||||||
|
|
||||||
uint8_t actual_sr_idx = data.packet_data.protocol_sample_rate_idx & 0x1f;
|
uint8_t actual_sr_idx = data.packet_data.protocol_sample_rate_idx & 0x1f;
|
||||||
if(vban_last_sr != actual_sr_idx) {
|
if(vban_last_sr != actual_sr_idx) {
|
||||||
vban_last_sr = actual_sr_idx;
|
vban_last_sr = actual_sr_idx;
|
||||||
@@ -409,12 +412,7 @@ int main(int argc, char *argv[]) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* audio_data = buffer + sizeof(VBANHeader);
|
if (add_to_buffer(audio_buffer, audio_data, audio_data_size, &data.packet_data) > 0) process_audio_buffer(audio_buffer, &output);
|
||||||
size_t audio_data_size = recv_len - sizeof(VBANHeader);
|
|
||||||
|
|
||||||
if (add_to_buffer(audio_buffer, audio_data, audio_data_size, &data.packet_data) > 0) {
|
|
||||||
process_audio_buffer(audio_buffer, &output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user