mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +01:00
add error checking
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"port": 13452,
|
"port": 13452,
|
||||||
"time": 1735683786793,
|
"time": 1735729771954,
|
||||||
"version": "0.0.3"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
@@ -122,11 +122,13 @@ int main() {
|
|||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
signal(SIGTERM, stop);
|
signal(SIGTERM, stop);
|
||||||
|
|
||||||
|
int pulse_error;
|
||||||
float input[BUFFER_SIZE]; // Input from device
|
float input[BUFFER_SIZE]; // Input from device
|
||||||
float signal[BUFFER_SIZE]; // this goes to the output
|
float signal[BUFFER_SIZE]; // this goes to the output
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
if (pa_simple_read(input_device, input, sizeof(input), NULL) < 0) {
|
if (pa_simple_read(input_device, input, sizeof(input), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error reading from input device.\n");
|
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,8 +157,9 @@ int main() {
|
|||||||
signal[i] = get_oscillator_sin_sample(&osc)*VOLUME;
|
signal[i] = get_oscillator_sin_sample(&osc)*VOLUME;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, signal, sizeof(signal), NULL) < 0) {
|
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error writing to output device.\n");
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
// Features
|
// Features
|
||||||
#include "features.h"
|
#include "features.h"
|
||||||
|
#define USB
|
||||||
|
|
||||||
#define SAMPLE_RATE 192000 // Don't go lower than 108 KHz, becuase it (53000*2) and (38000+15000)
|
#define SAMPLE_RATE 192000 // Don't go lower than 108 KHz, becuase it (53000*2) and (38000+15000)
|
||||||
|
|
||||||
@@ -140,12 +141,14 @@ int main() {
|
|||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
signal(SIGTERM, stop);
|
signal(SIGTERM, stop);
|
||||||
|
|
||||||
|
int pulse_error;
|
||||||
float input[BUFFER_SIZE*2]; // Input from device, interleaved stereo
|
float input[BUFFER_SIZE*2]; // Input from device, interleaved stereo
|
||||||
float left[BUFFER_SIZE+64], right[BUFFER_SIZE+64]; // Audio, same thing as in input but ininterleaved, ai told be there could be a buffer overflow here
|
float left[BUFFER_SIZE+64], right[BUFFER_SIZE+64]; // Audio, same thing as in input but ininterleaved, ai told be there could be a buffer overflow here
|
||||||
float mpx[BUFFER_SIZE]; // MPX, this goes to the output
|
float mpx[BUFFER_SIZE]; // MPX, this goes to the output
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
if (pa_simple_read(input_device, input, sizeof(input), NULL) < 0) {
|
if (pa_simple_read(input_device, input, sizeof(input), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error reading from input device.\n");
|
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uninterleave(input, left, right, BUFFER_SIZE*2);
|
uninterleave(input, left, right, BUFFER_SIZE*2);
|
||||||
@@ -188,15 +191,20 @@ int main() {
|
|||||||
float stereo = (current_left_input - current_right_input) / 2.0f; // Also Stereo to Mono but a bit diffrent
|
float stereo = (current_left_input - current_right_input) / 2.0f; // Also Stereo to Mono but a bit diffrent
|
||||||
float stereo_i, stereo_q;
|
float stereo_i, stereo_q;
|
||||||
apply_hilbert(&hilbert, stereo, &stereo_i, &stereo_q); // I/Q, the Quadrature data is 90 degrees apart from the In-phase data
|
apply_hilbert(&hilbert, stereo, &stereo_i, &stereo_q); // I/Q, the Quadrature data is 90 degrees apart from the In-phase data
|
||||||
float lsb = (stereo_i*cos38-stereo_q*(sin38*0.73f)); // Compute LSB, as the Hilbert isn't perfect, i'll have to a bit silence down the Q carrier in order to make it better, also, it is just perfect as FM Stereo LSB shouldn't be fully LSB
|
#ifdef USB
|
||||||
|
float signal = (stereo_i*cos38+stereo_q*(sin38*0.73f)); // Compute LSB/USB, as the Hilbert isn't perfect, i'll have to a bit silence down the Q carrier in order to make it better, also, it is just perfect as FM Stereo LSB shouldn't be fully LSB
|
||||||
|
#else
|
||||||
|
float signal = (stereo_i*cos38-stereo_q*(sin38*0.73f)); // Compute LSB/USB, as the Hilbert isn't perfect, i'll have to a bit silence down the Q carrier in order to make it better, also, it is just perfect as FM Stereo LSB shouldn't be fully LSB
|
||||||
|
#endif
|
||||||
|
|
||||||
mpx[i] = delay_line(&monoDelay, mono) * MONO_VOLUME +
|
mpx[i] = delay_line(&monoDelay, mono) * MONO_VOLUME +
|
||||||
pilot * PILOT_VOLUME +
|
pilot * PILOT_VOLUME +
|
||||||
lsb *STEREO_VOLUME;
|
signal*STEREO_VOLUME;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, mpx, sizeof(mpx), NULL) < 0) {
|
if (pa_simple_write(output_device, mpx, sizeof(mpx), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error writing to output device.\n");
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,12 +135,14 @@ int main() {
|
|||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
signal(SIGTERM, stop);
|
signal(SIGTERM, stop);
|
||||||
|
|
||||||
|
int pulse_error;
|
||||||
float input[BUFFER_SIZE*2]; // Input from device, interleaved stereo
|
float input[BUFFER_SIZE*2]; // Input from device, interleaved stereo
|
||||||
float left[BUFFER_SIZE+64], right[BUFFER_SIZE+64]; // Audio, same thing as in input but ininterleaved, ai told be there could be a buffer overflow here
|
float left[BUFFER_SIZE+64], right[BUFFER_SIZE+64]; // Audio, same thing as in input but ininterleaved, ai told be there could be a buffer overflow here
|
||||||
float mpx[BUFFER_SIZE]; // MPX, this goes to the output
|
float mpx[BUFFER_SIZE]; // MPX, this goes to the output
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
if (pa_simple_read(input_device, input, sizeof(input), NULL) < 0) {
|
if (pa_simple_read(input_device, input, sizeof(input), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error reading from input device.\n");
|
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uninterleave(input, left, right, BUFFER_SIZE*2);
|
uninterleave(input, left, right, BUFFER_SIZE*2);
|
||||||
@@ -185,8 +187,9 @@ int main() {
|
|||||||
(stereo * stereo_carrier) * STEREO_VOLUME; // DSB-SC modulation
|
(stereo * stereo_carrier) * STEREO_VOLUME; // DSB-SC modulation
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, mpx, sizeof(mpx), NULL) < 0) {
|
if (pa_simple_write(output_device, mpx, sizeof(mpx), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error writing to output device.\n");
|
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||||
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user