0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-27 11:33:54 +01:00
This commit is contained in:
2025-01-03 10:21:36 +01:00
parent 53266b1c17
commit 7a20c89cb4
9 changed files with 59 additions and 36 deletions

13
lib/fm_modulator.c Normal file
View File

@@ -0,0 +1,13 @@
#include "fm_modulator.h"
void init_fm_modulator(FMModulator *fm, float frequency, float deviation, float sample_rate) {
fm->frequency = frequency;
fm->deviation = deviation;
init_oscillator(&fm->osc, frequency, sample_rate);
}
float modulate_fm(FMModulator *fm, float sample) {
float inst_freq = fm->frequency+(sample*fm->deviation);
change_oscillator_frequency(&fm->osc, inst_freq);
return get_oscillator_sin_sample(&fm->osc);
}

11
lib/fm_modulator.h Normal file
View File

@@ -0,0 +1,11 @@
#include "oscillator.h"
typedef struct
{
float frequency;
float deviation;
Oscillator osc;
} FMModulator;
void init_fm_modulator(FMModulator *fm, float frequency, float deviation, float sample_rate);
float modulate_fm(FMModulator *fm, float sample);

View File

@@ -74,12 +74,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};

View File

@@ -1,2 +1,2 @@
// #define PREEMPHASIS
#define LPF
// #define LPF

View File

@@ -73,12 +73,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};

View File

@@ -10,6 +10,7 @@
#include "../lib/constants.h"
#include "../lib/oscillator.h"
#include "../lib/filters.h"
#include "../lib/fm_modulator.h"
// Features
#include "features.h"
@@ -63,12 +64,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};
@@ -109,8 +110,8 @@ int main() {
return 1;
}
Oscillator osc;
init_oscillator(&osc, FREQUENCY, SAMPLE_RATE);
FMModulator mod;
init_fm_modulator(&mod, FREQUENCY, DEVIATION, SAMPLE_RATE);
#ifdef PREEMPHASIS
Emphasis preemp;
init_emphasis(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
@@ -154,8 +155,7 @@ int main() {
#endif
#endif
change_oscillator_frequency(&osc, (FREQUENCY+((current_input*VOLUME_AUDIO)*DEVIATION)));
signal[i] = get_oscillator_sin_sample(&osc)*VOLUME;
signal[i] = modulate_fm(&mod, current_input)*VOLUME;
}
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {

View File

@@ -76,12 +76,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};

View File

@@ -74,12 +74,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};

View File

@@ -10,6 +10,7 @@
#include "../lib/constants.h"
#include "../lib/oscillator.h"
#include "../lib/filters.h"
#include "../lib/fm_modulator.h"
// Features
#include "features.h"
@@ -74,12 +75,12 @@ int main() {
};
pa_buffer_attr input_buffer_atr = {
.maxlength = 4096, // You can lower this to 512, but this is fine, it's sub-second delay, you're probably not gonna notice unless you're looking for it
.fragsize = 2048
.maxlength = 8192,
.fragsize = 4096
};
pa_buffer_attr output_buffer_atr = {
.maxlength = 4096,
.tlength = 2048,
.maxlength = 8192,
.tlength = 4096,
.prebuf = 0
};
@@ -120,9 +121,9 @@ int main() {
return 1;
}
Oscillator osc_mono, osc_stereo;
init_oscillator(&osc_mono, 67000, SAMPLE_RATE);
init_oscillator(&osc_stereo, 80000, SAMPLE_RATE);
FMModulator mod_mono, mod_stereo;
init_fm_modulator(&mod_mono, 67000, 6000, SAMPLE_RATE);
init_fm_modulator(&mod_stereo, 80000, 6000, SAMPLE_RATE);
#ifdef PREEMPHASIS
Emphasis preemp_l, preemp_r;
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
@@ -181,10 +182,8 @@ int main() {
float mono = (current_left_input+current_right_input)/2.0f;
float stereo = (current_left_input-current_right_input)/2.0f;
change_oscillator_frequency(&osc_mono, (67000+(mono*6000)));
change_oscillator_frequency(&osc_stereo, (80000+(stereo*6000)));
signal[i] = get_oscillator_sin_sample(&osc_mono)*MONO_VOLUME+
get_oscillator_sin_sample(&osc_stereo)*STEREO_VOLUME;
signal[i] = modulate_fm(&mod_mono, mono)*MONO_VOLUME+
modulate_fm(&mod_stereo, stereo)*STEREO_VOLUME;
}
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {