From dee8ed9845bac3da094164fde625105bd8fb7485 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Tue, 20 May 2025 17:33:47 +0200 Subject: [PATCH] remove some includes as well as add missing functions --- dsp/bs412.c | 3 ++- dsp/bs412.h | 2 ++ dsp/filters.h | 4 ---- io/audio.c | 39 +++++++++++++++++++++++++++++++++++++++ io/audio.h | 2 ++ src/chimer95.c | 1 - src/dcf95.c | 1 - src/fm95.c | 1 - src/vban95.c | 5 ----- 9 files changed, 45 insertions(+), 13 deletions(-) diff --git a/dsp/bs412.c b/dsp/bs412.c index 8f52c67..540b001 100644 --- a/dsp/bs412.c +++ b/dsp/bs412.c @@ -5,7 +5,8 @@ float dbr_to_deviation(float dbr) { } float deviation_to_dbr(float deviation) { - return 10 * log10f((deviation + 1e-6f) / 19000.0f); + if(deviation == 0.0f) return -100.0f; + return 10 * log10f(deviation / 19000.0f); } void init_modulation_power_measure(MPXPowerMeasurement* mpx, int sample_rate) { diff --git a/dsp/bs412.h b/dsp/bs412.h index d4b389a..f99abb7 100644 --- a/dsp/bs412.h +++ b/dsp/bs412.h @@ -1,6 +1,8 @@ #pragma once #include +#ifdef BS412_DEBUG #include "../lib/debug.h" +#endif typedef struct { diff --git a/dsp/filters.h b/dsp/filters.h index 1c16e66..cf40010 100644 --- a/dsp/filters.h +++ b/dsp/filters.h @@ -1,11 +1,7 @@ #pragma once -#include -#include #include -#include "constants.h" #include "../lib/optimization.h" -#include "oscillator.h" typedef struct { diff --git a/io/audio.c b/io/audio.c index 8b19e0f..a16d506 100644 --- a/io/audio.c +++ b/io/audio.c @@ -32,6 +32,38 @@ int init_PulseInputDevice(PulseInputDevice* dev, int sample_rate, int channels, return 0; } +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) { + if (dev->initialized) return -1; + pa_sample_spec sample_spec = { + .format = format, + .channels = channels, + .rate = sample_rate + }; + pa_buffer_attr new_buffer_attr = *buffer_attr; + dev->sample_spec = sample_spec; + dev->buffer_attr = new_buffer_attr; + + dev->app_name = strdup(app_name); + dev->stream_name = strdup(stream_name); + dev->device = strdup(device); + + int error; + dev->dev = pa_simple_new( + NULL, + app_name, + PA_STREAM_RECORD, + device, + stream_name, + &sample_spec, + NULL, + &new_buffer_attr, + &error + ); + if (!dev->dev) return error; + dev->initialized = 1; + return 0; +} + int read_PulseInputDevice(PulseInputDevice* dev, float* buffer, size_t size) { if (!dev->initialized) return -1; int error; @@ -39,6 +71,13 @@ int read_PulseInputDevice(PulseInputDevice* dev, float* buffer, size_t size) { return 0; } +int read_PulseInputDevicef(PulseInputDevice* dev, void* buffer, size_t size) { + if (!dev->initialized) return -1; + int error; + if (pa_simple_read(dev->dev, buffer, size, &error) < 0) return error; + return 0; +} + void free_PulseInputDevice(PulseInputDevice* dev) { if (dev->dev && dev->initialized) pa_simple_free(dev->dev); free(dev->app_name); diff --git a/io/audio.h b/io/audio.h index 634da0f..d43f469 100644 --- a/io/audio.h +++ b/io/audio.h @@ -17,7 +17,9 @@ typedef struct } PulseInputDevice; 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_PulseInputDevicef(PulseInputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr, pa_sample_format_t format); int read_PulseInputDevice(PulseInputDevice *dev, float *buffer, size_t size); +int read_PulseInputDevicef(PulseInputDevice *dev, void *buffer, size_t size); void free_PulseInputDevice(PulseInputDevice *dev); typedef PulseInputDevice PulseOutputDevice; diff --git a/src/chimer95.c b/src/chimer95.c index 17aadc2..debbe36 100644 --- a/src/chimer95.c +++ b/src/chimer95.c @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/src/dcf95.c b/src/dcf95.c index ffdad9b..dbc57a1 100644 --- a/src/dcf95.c +++ b/src/dcf95.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include diff --git a/src/fm95.c b/src/fm95.c index d1f93be..bf63000 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/src/vban95.c b/src/vban95.c index 269f824..8a84768 100644 --- a/src/vban95.c +++ b/src/vban95.c @@ -1,6 +1,4 @@ #include -#include -#include #include #include #include @@ -8,12 +6,9 @@ #include #include #include -#include #include -#include #include #include -#include #define buffer_maxlength 12288 #define buffer_tlength_fragsize 12288