mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +01:00
add libfmio and make the seperators in the helps tabs
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -20,7 +20,10 @@
|
|||||||
"asoundlib.h": "c",
|
"asoundlib.h": "c",
|
||||||
"hilbert.h": "c",
|
"hilbert.h": "c",
|
||||||
"fm_modulator.h": "c",
|
"fm_modulator.h": "c",
|
||||||
"bs412.h": "c"
|
"bs412.h": "c",
|
||||||
|
"gain_control.h": "c",
|
||||||
|
"optimization.h": "c",
|
||||||
|
"string.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "disabled"
|
"C_Cpp.errorSquiggles": "disabled"
|
||||||
}
|
}
|
||||||
@@ -9,18 +9,21 @@ file(GLOB SRC_FILES "src/*.c")
|
|||||||
|
|
||||||
file(GLOB LIB_FILES "lib/*.c")
|
file(GLOB LIB_FILES "lib/*.c")
|
||||||
|
|
||||||
|
file(GLOB IO_FILES "io/*.c")
|
||||||
|
|
||||||
add_library(libfm OBJECT ${LIB_FILES})
|
add_library(libfm OBJECT ${LIB_FILES})
|
||||||
|
|
||||||
set(LINK_LIBS "-lpulse -lpulse-simple -lm")
|
add_library(libfmio OBJECT ${IO_FILES})
|
||||||
|
|
||||||
|
set(FM_LIBS libfm libfmio pulse pulse-simple m)
|
||||||
|
|
||||||
foreach(SRC_FILE ${SRC_FILES})
|
foreach(SRC_FILE ${SRC_FILES})
|
||||||
get_filename_component(EXEC_NAME ${SRC_FILE} NAME_WE)
|
get_filename_component(EXEC_NAME ${SRC_FILE} NAME_WE)
|
||||||
|
|
||||||
add_executable(${EXEC_NAME} ${SRC_FILE})
|
add_executable(${EXEC_NAME} ${SRC_FILE})
|
||||||
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 libfm ${LINK_LIBS})
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
113
io/audio.c
Normal file
113
io/audio.c
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
#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) {
|
||||||
|
if (dev->initialized) return -1;
|
||||||
|
pa_sample_spec sample_spec = {
|
||||||
|
.format = PA_SAMPLE_FLOAT32NE,
|
||||||
|
.channels = channels,
|
||||||
|
.rate = sample_rate
|
||||||
|
};
|
||||||
|
pa_buffer_attr new_buffer_attr = *buffer_attr;
|
||||||
|
dev->sample_spec = sample_spec;
|
||||||
|
dev->buffer_attr = new_buffer_attr;
|
||||||
|
|
||||||
|
char* new_app_name = strdup(app_name);
|
||||||
|
char* new_stream_name = strdup(stream_name);
|
||||||
|
char* new_device = strdup(device);
|
||||||
|
if (!(dev->app_name = strdup(app_name)) || !(dev->stream_name = strdup(stream_name)) || !(dev->device = strdup(device))) {
|
||||||
|
free(dev->app_name);
|
||||||
|
free(dev->stream_name);
|
||||||
|
free(dev->device);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
dev->app_name = new_app_name;
|
||||||
|
dev->stream_name = new_stream_name;
|
||||||
|
dev->device = new_device;
|
||||||
|
|
||||||
|
int error;
|
||||||
|
dev->dev = pa_simple_new(
|
||||||
|
NULL,
|
||||||
|
new_app_name,
|
||||||
|
PA_STREAM_RECORD,
|
||||||
|
new_device,
|
||||||
|
new_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;
|
||||||
|
if (pa_simple_read(dev->dev, buffer, size * sizeof(float), &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);
|
||||||
|
free(dev->stream_name);
|
||||||
|
free(dev->device);
|
||||||
|
dev->initialized = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_PulseOutputDevice(PulseOutputDevice* dev, int sample_rate, int channels, char* app_name, char *stream_name, char* device, pa_buffer_attr* buffer_attr) {
|
||||||
|
if (dev->initialized) return -1;
|
||||||
|
pa_sample_spec sample_spec = {
|
||||||
|
.format = PA_SAMPLE_FLOAT32NE,
|
||||||
|
.channels = channels,
|
||||||
|
.rate = sample_rate
|
||||||
|
};
|
||||||
|
pa_buffer_attr new_buffer_attr = *buffer_attr;
|
||||||
|
dev->sample_spec = sample_spec;
|
||||||
|
dev->buffer_attr = new_buffer_attr;
|
||||||
|
|
||||||
|
char* new_app_name = strdup(app_name);
|
||||||
|
char* new_stream_name = strdup(stream_name);
|
||||||
|
char* new_device = strdup(device);
|
||||||
|
if (!(dev->app_name = strdup(app_name)) || !(dev->stream_name = strdup(stream_name)) || !(dev->device = strdup(device))) {
|
||||||
|
free(dev->app_name);
|
||||||
|
free(dev->stream_name);
|
||||||
|
free(dev->device);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
dev->app_name = new_app_name;
|
||||||
|
dev->stream_name = new_stream_name;
|
||||||
|
dev->device = new_device;
|
||||||
|
|
||||||
|
int error;
|
||||||
|
dev->dev = pa_simple_new(
|
||||||
|
NULL,
|
||||||
|
new_app_name,
|
||||||
|
PA_STREAM_PLAYBACK,
|
||||||
|
new_device,
|
||||||
|
new_stream_name,
|
||||||
|
&sample_spec,
|
||||||
|
NULL,
|
||||||
|
&new_buffer_attr,
|
||||||
|
&error
|
||||||
|
);
|
||||||
|
if (!dev->dev) return error;
|
||||||
|
dev->initialized = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_PulseOutputDevice(PulseOutputDevice* dev, float* buffer, size_t size) {
|
||||||
|
if (!dev->initialized) return -1;
|
||||||
|
int error;
|
||||||
|
if (pa_simple_write(dev->dev, buffer, size * sizeof(float), &error) < 0) return error;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_PulseOutputDevice(PulseOutputDevice* dev) {
|
||||||
|
if (dev->dev && dev->initialized) pa_simple_free(dev->dev);
|
||||||
|
free(dev->app_name);
|
||||||
|
free(dev->stream_name);
|
||||||
|
free(dev->device);
|
||||||
|
dev->initialized = 0;
|
||||||
|
}
|
||||||
26
io/audio.h
Normal file
26
io/audio.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pulse/simple.h>
|
||||||
|
#include <pulse/error.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
pa_simple* dev;
|
||||||
|
pa_sample_spec sample_spec;
|
||||||
|
pa_buffer_attr buffer_attr;
|
||||||
|
char* app_name;
|
||||||
|
char* stream_name;
|
||||||
|
char* device;
|
||||||
|
int initialized;
|
||||||
|
} 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 read_PulseInputDevice(PulseInputDevice *dev, float *buffer, size_t size);
|
||||||
|
void free_PulseInputDevice(PulseInputDevice *dev);
|
||||||
|
|
||||||
|
typedef PulseInputDevice PulseOutputDevice;
|
||||||
|
int init_PulseOutputDevice(PulseOutputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr);
|
||||||
|
int write_PulseOutputDevice(PulseOutputDevice *dev, float *buffer, size_t size);
|
||||||
|
void free_PulseOutputDevice(PulseOutputDevice *dev);
|
||||||
@@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
#define BUFFER_SIZE 256
|
#define BUFFER_SIZE 256
|
||||||
|
|
||||||
#include <pulse/simple.h>
|
#include "../io/audio.h"
|
||||||
#include <pulse/error.h>
|
|
||||||
|
|
||||||
#define DEFAULT_MASTER_VOLUME 0.5f
|
#define DEFAULT_MASTER_VOLUME 0.5f
|
||||||
#define DEFAULT_OFFSET 0
|
#define DEFAULT_OFFSET 0
|
||||||
@@ -53,13 +52,13 @@ void show_version() {
|
|||||||
|
|
||||||
void show_help(char *name) {
|
void show_help(char *name) {
|
||||||
printf(
|
printf(
|
||||||
"Usage: %s\n"
|
"Usage:\t%s\n"
|
||||||
" -o,--output Override output device [default: %s]\n"
|
"\t-o,--output\tOverride output device [default: %s]\n"
|
||||||
" -F,--frequency GTS Frequency [default: %.1f Hz]\n"
|
"\t-F,--frequency\tGTS Frequency [default: %.1f Hz]\n"
|
||||||
" -s,--samplerate Output Samplerate [default: %d]\n"
|
"\t-s,--samplerate\tOutput Samplerate [default: %d]\n"
|
||||||
" -v,--volume Output volume [default: %.2f]\n"
|
"\t-v,--volume\tOutput volume [default: %.2f]\n"
|
||||||
" -t,--offset GTS Offset [default: %d s]\n"
|
"\t-t,--offset\tGTS Offset [default: %d s]\n"
|
||||||
" -T,--test Enable test mode (plays full hour signal at end of every minute)\n"
|
"\t-T,--test\tEnable test mode (plays full hour signal at end of every minute)\n"
|
||||||
,name
|
,name
|
||||||
,OUTPUT_DEVICE
|
,OUTPUT_DEVICE
|
||||||
,DEFAULT_FREQ
|
,DEFAULT_FREQ
|
||||||
@@ -179,7 +178,8 @@ int check_time_for_sequence(int test_mode, int offset) {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
show_version();
|
show_version();
|
||||||
|
|
||||||
pa_simple *output_device;
|
PulseOutputDevice output_device;
|
||||||
|
|
||||||
char audio_output_device[64] = OUTPUT_DEVICE;
|
char audio_output_device[64] = OUTPUT_DEVICE;
|
||||||
float master_volume = DEFAULT_MASTER_VOLUME;
|
float master_volume = DEFAULT_MASTER_VOLUME;
|
||||||
float freq = DEFAULT_FREQ;
|
float freq = DEFAULT_FREQ;
|
||||||
@@ -237,12 +237,6 @@ int main(int argc, char **argv) {
|
|||||||
printf(" Test mode: %s\n", test_mode ? "Enabled" : "Disabled");
|
printf(" Test mode: %s\n", test_mode ? "Enabled" : "Disabled");
|
||||||
|
|
||||||
// Setup PulseAudio
|
// Setup PulseAudio
|
||||||
pa_sample_spec mono_format = {
|
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
|
||||||
.channels = 1,
|
|
||||||
.rate = sample_rate
|
|
||||||
};
|
|
||||||
|
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = buffer_maxlength,
|
.maxlength = buffer_maxlength,
|
||||||
.tlength = buffer_tlength_fragsize,
|
.tlength = buffer_tlength_fragsize,
|
||||||
@@ -253,19 +247,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
printf("Connecting to output device... (%s)\n", audio_output_device);
|
printf("Connecting to output device... (%s)\n", audio_output_device);
|
||||||
|
|
||||||
output_device = pa_simple_new(
|
pulse_error = init_PulseOutputDevice(&output_device, sample_rate, 1, "chimer95", "Main Audio Output", audio_output_device, &output_buffer_atr);
|
||||||
NULL,
|
if (pulse_error) {
|
||||||
"chimer95",
|
|
||||||
PA_STREAM_PLAYBACK,
|
|
||||||
audio_output_device,
|
|
||||||
"GTS Output",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&output_buffer_atr,
|
|
||||||
&pulse_error
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!output_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(pulse_error));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -316,7 +299,7 @@ int main(int argc, char **argv) {
|
|||||||
static int idle_counter = 0;
|
static int idle_counter = 0;
|
||||||
if (idle_counter++ % 10 == 0) {
|
if (idle_counter++ % 10 == 0) {
|
||||||
memset(output, 0, sizeof(output));
|
memset(output, 0, sizeof(output));
|
||||||
pa_simple_write(output_device, output, sizeof(output), &pulse_error);
|
write_PulseOutputDevice(&output_device, output, sizeof(output));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec ts = {0, 5000000}; // 5ms sleep
|
struct timespec ts = {0, 5000000}; // 5ms sleep
|
||||||
@@ -334,7 +317,7 @@ int main(int argc, char **argv) {
|
|||||||
sequence_completed = 1;
|
sequence_completed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, output, sizeof(output), &pulse_error) < 0) {
|
if((pulse_error = write_PulseOutputDevice(&output_device, output, sizeof(output)))) {
|
||||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
@@ -342,6 +325,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Cleaning up...\n");
|
printf("Cleaning up...\n");
|
||||||
pa_simple_free(output_device);
|
free_PulseOutputDevice(&output_device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
45
src/dcf95.c
45
src/dcf95.c
@@ -22,8 +22,7 @@
|
|||||||
|
|
||||||
#define BUFFER_SIZE 512
|
#define BUFFER_SIZE 512
|
||||||
|
|
||||||
#include <pulse/simple.h>
|
#include "../io/audio.h"
|
||||||
#include <pulse/error.h>
|
|
||||||
|
|
||||||
#define DEFAULT_MASTER_VOLUME 0.5f
|
#define DEFAULT_MASTER_VOLUME 0.5f
|
||||||
#define DEFAULT_OFFSET 0
|
#define DEFAULT_OFFSET 0
|
||||||
@@ -212,14 +211,14 @@ void show_version() {
|
|||||||
|
|
||||||
void show_help(char *name) {
|
void show_help(char *name) {
|
||||||
printf(
|
printf(
|
||||||
"Usage: %s\n"
|
"Usage: \t%s\n"
|
||||||
" -o,--output Override output device [default: %s]\n"
|
"\t-o,--output\tOverride output device [default: %s]\n"
|
||||||
" -F,--frequency DCF77 Frequency [default: %.1f Hz]\n"
|
"\t-F,--frequency\tDCF77 Frequency [default: %.1f Hz]\n"
|
||||||
" -s,--samplerate Output Samplerate [default: %d]\n"
|
"\t-s,--samplerate\tOutput Samplerate [default: %d]\n"
|
||||||
" -v,--volume Output volume [default: %.2f]\n"
|
"\t-v,--volume\tOutput volume [default: %.2f]\n"
|
||||||
" -t,--offset Time Offset [default: %ds]\n"
|
"\t-t,--offset\tTime Offset [default: %ds]\n"
|
||||||
" -T,--test Enable test mode\n"
|
"\t-T,--test\tEnable test mode\n"
|
||||||
" -n,--no-phase Disable phase modulation\n"
|
"\t-n,--no-phase\tDisable phase modulation\n"
|
||||||
,name
|
,name
|
||||||
,OUTPUT_DEVICE
|
,OUTPUT_DEVICE
|
||||||
,DEFAULT_FREQ
|
,DEFAULT_FREQ
|
||||||
@@ -232,7 +231,7 @@ void show_help(char *name) {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
show_version();
|
show_version();
|
||||||
|
|
||||||
pa_simple *output_device;
|
PulseOutputDevice output_device;
|
||||||
|
|
||||||
char audio_output_device[64] = OUTPUT_DEVICE;
|
char audio_output_device[64] = OUTPUT_DEVICE;
|
||||||
|
|
||||||
@@ -311,12 +310,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #region Setup devices
|
// #region Setup devices
|
||||||
pa_sample_spec mono_format = {
|
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
|
||||||
.channels = 1,
|
|
||||||
.rate = sample_rate
|
|
||||||
};
|
|
||||||
|
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = buffer_maxlength,
|
.maxlength = buffer_maxlength,
|
||||||
.tlength = buffer_tlength_fragsize,
|
.tlength = buffer_tlength_fragsize,
|
||||||
@@ -327,18 +320,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
printf("Connecting to output device... (%s)\n", audio_output_device);
|
printf("Connecting to output device... (%s)\n", audio_output_device);
|
||||||
|
|
||||||
output_device = pa_simple_new(
|
opentime_pulse_error = init_PulseOutputDevice(&output_device, sample_rate, 1, "dcf95", "Main Audio Output", audio_output_device, &output_buffer_atr);
|
||||||
NULL,
|
if (opentime_pulse_error) {
|
||||||
"dcf95",
|
|
||||||
PA_STREAM_PLAYBACK,
|
|
||||||
audio_output_device,
|
|
||||||
"DCF77 Output",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&output_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!output_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -464,7 +447,7 @@ int main(int argc, char **argv) {
|
|||||||
elapsed_samples++;
|
elapsed_samples++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, output, sizeof(output), &pulse_error) < 0) {
|
if((pulse_error = write_PulseOutputDevice(&output_device, output, sizeof(output)))) {
|
||||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
@@ -472,6 +455,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Cleaning up...\n");
|
printf("Cleaning up...\n");
|
||||||
pa_simple_free(output_device);
|
free_PulseOutputDevice(&output_device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
181
src/fm95.c
181
src/fm95.c
@@ -33,8 +33,7 @@
|
|||||||
|
|
||||||
#define BUFFER_SIZE 2048
|
#define BUFFER_SIZE 2048
|
||||||
|
|
||||||
#include <pulse/simple.h>
|
#include "../io/audio.h"
|
||||||
#include <pulse/error.h>
|
|
||||||
|
|
||||||
#define DEFAULT_MASTER_VOLUME 1.0f // Volume of everything combined, for calibration
|
#define DEFAULT_MASTER_VOLUME 1.0f // Volume of everything combined, for calibration
|
||||||
#define DEFAULT_AUDIO_VOLUME 1.0f // Audio volume, before clipper
|
#define DEFAULT_AUDIO_VOLUME 1.0f // Audio volume, before clipper
|
||||||
@@ -81,24 +80,24 @@ void show_version() {
|
|||||||
}
|
}
|
||||||
void show_help(char *name) {
|
void show_help(char *name) {
|
||||||
printf(
|
printf(
|
||||||
"Usage: %s\n"
|
"Usage: \t%s\n"
|
||||||
" -s,--stereo Force Stereo [default: %d]\n"
|
"\t-s,--stereo\tForce Stereo [default: %d]\n"
|
||||||
" -i,--input Override input device [default: %s]\n"
|
"\t-i,--input\tOverride input device [default: %s]\n"
|
||||||
" -o,--output Override output device [default: %s]\n"
|
"\t-o,--output\tOverride output device [default: %s]\n"
|
||||||
" -M,--mpx Override MPX input device [default: %s]\n"
|
"\t-M,--mpx\tOverride MPX input device [default: %s]\n"
|
||||||
" -r,--rds Override RDS95 input device [default: %s]\n"
|
"\t-r,--rds\tOverride RDS95 input device [default: %s]\n"
|
||||||
" -C,--sca Override the SCA input device [default: %s]\n"
|
"\t-C,--sca\tOverride the SCA input device [default: %s]\n"
|
||||||
" -f,--sca_freq Override the SCA frequency [default: %.1f]\n"
|
"\t-f,--sca_freq\tOverride the SCA frequency [default: %.1f]\n"
|
||||||
" -F,--sca_dev Override the SCA deviation [default: %.2f]\n"
|
"\t-F,--sca_dev\tOverride the SCA deviation [default: %.2f]\n"
|
||||||
" -L,--sca_clip Override the SCA clipper threshold [default: %.2f]\n"
|
"\t-L,--sca_clip\tOverride the SCA clipper threshold [default: %.2f]\n"
|
||||||
" -c,--clipper Override the clipper threshold [default: %.2f]\n"
|
"\t-c,--clipper\tOverride the clipper threshold [default: %.2f]\n"
|
||||||
" -P,--polar Force Polar Stereo (does not take effect with -m%s)\n"
|
"\t-P,--polar\tForce Polar Stereo (does not take effect with -m%s)\n"
|
||||||
" -R,--preemp Override preemphasis [default: %.2f µs]\n"
|
"\t-R,--preemp\tOverride preemphasis [default: %.2f µs]\n"
|
||||||
" -V,--calibrate Enable Calibration mode [default: off]\n"
|
"\t-V,--calibrate\tEnable Calibration mode [default: off]\n"
|
||||||
" -p,--power Set the MPX power [default: %.1f]\n"
|
"\t-p,--power\tSet the MPX power [default: %.1f]\n"
|
||||||
" -d,--mpx_dev Set the MPX deviation [default: %.1f]\n"
|
"\t-d,--mpx_dev\tSet the MPX deviation [default: %.1f]\n"
|
||||||
" -A,--master_vol Set master volume [default: %.3f]\n"
|
"\t-A,--master_vol\tSet master volume [default: %.3f]\n"
|
||||||
" -v,--audio_vol Set audio volume [default: %.3f]\n"
|
"\t-v,--audio_vol\tSet audio volume [default: %.3f]\n"
|
||||||
,name
|
,name
|
||||||
,DEFAULT_STEREO
|
,DEFAULT_STEREO
|
||||||
,INPUT_DEVICE
|
,INPUT_DEVICE
|
||||||
@@ -134,12 +133,10 @@ void show_help(char *name) {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
show_version();
|
show_version();
|
||||||
|
|
||||||
pa_simple *mpx_device = NULL;
|
PulseInputDevice mpx_device, rds_device, sca_device;
|
||||||
pa_simple *rds_device = NULL;
|
|
||||||
pa_simple *sca_device = NULL;
|
|
||||||
|
|
||||||
pa_simple *input_device;
|
PulseInputDevice input_device;
|
||||||
pa_simple *output_device;
|
PulseOutputDevice output_device;
|
||||||
|
|
||||||
float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD;
|
float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD;
|
||||||
int stereo = DEFAULT_STEREO;
|
int stereo = DEFAULT_STEREO;
|
||||||
@@ -282,17 +279,6 @@ int main(int argc, char **argv) {
|
|||||||
// #region Setup devices
|
// #region Setup devices
|
||||||
|
|
||||||
// Define formats and buffer atributes
|
// Define formats and buffer atributes
|
||||||
pa_sample_spec stereo_format = {
|
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
|
||||||
.channels = 2,
|
|
||||||
.rate = sample_rate
|
|
||||||
};
|
|
||||||
pa_sample_spec mono_format = {
|
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
|
||||||
.channels = 1,
|
|
||||||
.rate = sample_rate
|
|
||||||
};
|
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
pa_buffer_attr input_buffer_atr = {
|
||||||
.maxlength = buffer_maxlength,
|
.maxlength = buffer_maxlength,
|
||||||
.fragsize = buffer_tlength_fragsize
|
.fragsize = buffer_tlength_fragsize
|
||||||
@@ -306,19 +292,8 @@ int main(int argc, char **argv) {
|
|||||||
int opentime_pulse_error;
|
int opentime_pulse_error;
|
||||||
|
|
||||||
printf("Connecting to input device... (%s)\n", audio_input_device);
|
printf("Connecting to input device... (%s)\n", audio_input_device);
|
||||||
|
opentime_pulse_error = init_PulseInputDevice(&input_device, sample_rate, 2, "fm95", "Main Audio Input", audio_input_device, &input_buffer_atr);
|
||||||
input_device = pa_simple_new(
|
if (opentime_pulse_error) {
|
||||||
NULL,
|
|
||||||
"fm95",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
audio_input_device,
|
|
||||||
"Main Audio Input",
|
|
||||||
&stereo_format,
|
|
||||||
NULL,
|
|
||||||
&input_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!input_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open input device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open input device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -326,41 +301,21 @@ int main(int argc, char **argv) {
|
|||||||
if(mpx_on) {
|
if(mpx_on) {
|
||||||
printf("Connecting to MPX device... (%s)\n", audio_mpx_device);
|
printf("Connecting to MPX device... (%s)\n", audio_mpx_device);
|
||||||
|
|
||||||
mpx_device = pa_simple_new(
|
opentime_pulse_error = init_PulseInputDevice(&mpx_device, sample_rate, 1, "fm95", "MPX Input", audio_mpx_device, &input_buffer_atr);
|
||||||
NULL,
|
if (opentime_pulse_error) {
|
||||||
"fm95",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
audio_mpx_device,
|
|
||||||
"MPX Input",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&input_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!mpx_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open MPX device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open MPX device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rds_on) {
|
if(rds_on) {
|
||||||
printf("Connecting to RDS95 device... (%s)\n", audio_rds_device);
|
printf("Connecting to RDS95 device... (%s)\n", audio_rds_device);
|
||||||
|
|
||||||
rds_device = pa_simple_new(
|
opentime_pulse_error = init_PulseInputDevice(&rds_device, sample_rate, 1, "fm95", "RDS95 Input", audio_rds_device, &input_buffer_atr);
|
||||||
NULL,
|
if (opentime_pulse_error) {
|
||||||
"fm95",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
audio_rds_device,
|
|
||||||
"RDS Input",
|
|
||||||
&stereo_format,
|
|
||||||
NULL,
|
|
||||||
&input_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!rds_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open RDS device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open RDS device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) free_PulseInputDevice(&mpx_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,45 +323,25 @@ int main(int argc, char **argv) {
|
|||||||
if(sca_on) {
|
if(sca_on) {
|
||||||
printf("Connecting to SCA device... (%s)\n", audio_sca_device);
|
printf("Connecting to SCA device... (%s)\n", audio_sca_device);
|
||||||
|
|
||||||
sca_device = pa_simple_new(
|
opentime_pulse_error = init_PulseInputDevice(&sca_device, sample_rate, 1, "fm95", "SCA Input", audio_sca_device, &input_buffer_atr);
|
||||||
NULL,
|
if (opentime_pulse_error) {
|
||||||
"fm95",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
audio_sca_device,
|
|
||||||
"SCA Input",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&input_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!sca_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open SCA device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open SCA device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) free_PulseInputDevice(&mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) free_PulseInputDevice(&rds_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Connecting to output device... (%s)\n", audio_output_device);
|
printf("Connecting to output device... (%s)\n", audio_output_device);
|
||||||
|
|
||||||
output_device = pa_simple_new(
|
opentime_pulse_error = init_PulseOutputDevice(&output_device, sample_rate, 2, "fm95", "Main Audio Output", audio_output_device, &output_buffer_atr);
|
||||||
NULL,
|
if (opentime_pulse_error) {
|
||||||
"StereoEncoder",
|
|
||||||
PA_STREAM_PLAYBACK,
|
|
||||||
audio_output_device,
|
|
||||||
"MPX Output",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&output_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!output_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(opentime_pulse_error));
|
fprintf(stderr, "Error: cannot open output device: %s\n", pa_strerror(opentime_pulse_error));
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) free_PulseInputDevice(&mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) free_PulseInputDevice(&rds_device);
|
||||||
if(sca_on) pa_simple_free(sca_device);
|
if(sca_on) free_PulseInputDevice(&sca_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// #endregion
|
// #endregion
|
||||||
@@ -424,18 +359,18 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < BUFFER_SIZE; i++) {
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
output[i] = get_oscillator_sin_sample(&osc)*master_volume;
|
output[i] = get_oscillator_sin_sample(&osc)*master_volume;
|
||||||
}
|
}
|
||||||
if (pa_simple_write(output_device, output, sizeof(output), &pulse_error) < 0) {
|
if((pulse_error = write_PulseOutputDevice(&output_device, output, sizeof(output)))) { // get output from the function and assign it into pulse_error, this comment to avoid confusion
|
||||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Cleaning up...\n");
|
printf("Cleaning up...\n");
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) free_PulseInputDevice(&mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) free_PulseInputDevice(&rds_device);
|
||||||
if(sca_on) pa_simple_free(sca_device);
|
if(sca_on) free_PulseInputDevice(&sca_device);
|
||||||
pa_simple_free(output_device);
|
free_PulseOutputDevice(&output_device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,21 +410,21 @@ int main(int argc, char **argv) {
|
|||||||
float output[BUFFER_SIZE];
|
float output[BUFFER_SIZE];
|
||||||
|
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
if (pa_simple_read(input_device, audio_stereo_input, sizeof(audio_stereo_input), &pulse_error) < 0) {
|
if((pulse_error = read_PulseInputDevice(&input_device, audio_stereo_input, sizeof(audio_stereo_input)))) { // get output from the function and assign it into pulse_error, this comment to avoid confusion
|
||||||
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uninterleave(audio_stereo_input, left, right, BUFFER_SIZE*2);
|
uninterleave(audio_stereo_input, left, right, BUFFER_SIZE*2);
|
||||||
if(mpx_on) {
|
if(mpx_on) {
|
||||||
if (pa_simple_read(mpx_device, mpx_in, sizeof(mpx_in), &pulse_error) < 0) {
|
if((pulse_error = read_PulseInputDevice(&mpx_device, mpx_in, sizeof(mpx_in)))) {
|
||||||
fprintf(stderr, "Error reading from MPX device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from MPX device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rds_on) {
|
if(rds_on) {
|
||||||
if (pa_simple_read(rds_device, rds1_rds2_in, sizeof(rds1_rds2_in), &pulse_error) < 0) {
|
if((pulse_error = read_PulseInputDevice(&rds_device, rds1_rds2_in, sizeof(rds1_rds2_in)))) {
|
||||||
fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
@@ -497,7 +432,7 @@ int main(int argc, char **argv) {
|
|||||||
uninterleave(rds1_rds2_in, rds1_in, rds2_in, BUFFER_SIZE*2);
|
uninterleave(rds1_rds2_in, rds1_in, rds2_in, BUFFER_SIZE*2);
|
||||||
}
|
}
|
||||||
if(sca_on) {
|
if(sca_on) {
|
||||||
if (pa_simple_read(sca_device, sca_in, sizeof(sca_in), &pulse_error) < 0) {
|
if((pulse_error = read_PulseInputDevice(&sca_device, sca_in, sizeof(sca_in)))) {
|
||||||
fprintf(stderr, "Error reading from SCA device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from SCA device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
@@ -561,17 +496,17 @@ int main(int argc, char **argv) {
|
|||||||
if(rds_on || stereo) advance_oscillator(&osc);
|
if(rds_on || stereo) advance_oscillator(&osc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, output, sizeof(output), &pulse_error) < 0) {
|
if(write_PulseOutputDevice(&output_device, output, sizeof(output))) {
|
||||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Cleaning up...\n");
|
printf("Cleaning up...\n");
|
||||||
pa_simple_free(input_device);
|
free_PulseInputDevice(&input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) free_PulseInputDevice(&mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) free_PulseInputDevice(&rds_device);
|
||||||
if(sca_on) pa_simple_free(sca_device);
|
if(sca_on) free_PulseInputDevice(&sca_device);
|
||||||
pa_simple_free(output_device);
|
free_PulseOutputDevice(&output_device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user