mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-07-31 16:59:16 +02:00
updates
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
@@ -74,12 +74,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
// #define PREEMPHASIS
|
// #define PREEMPHASIS
|
||||||
#define LPF
|
// #define LPF
|
||||||
@@ -73,12 +73,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -10,6 +10,7 @@
|
|||||||
#include "../lib/constants.h"
|
#include "../lib/constants.h"
|
||||||
#include "../lib/oscillator.h"
|
#include "../lib/oscillator.h"
|
||||||
#include "../lib/filters.h"
|
#include "../lib/filters.h"
|
||||||
|
#include "../lib/fm_modulator.h"
|
||||||
|
|
||||||
// Features
|
// Features
|
||||||
#include "features.h"
|
#include "features.h"
|
||||||
@@ -63,12 +64,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,8 +110,8 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Oscillator osc;
|
FMModulator mod;
|
||||||
init_oscillator(&osc, FREQUENCY, SAMPLE_RATE);
|
init_fm_modulator(&mod, FREQUENCY, DEVIATION, SAMPLE_RATE);
|
||||||
#ifdef PREEMPHASIS
|
#ifdef PREEMPHASIS
|
||||||
Emphasis preemp;
|
Emphasis preemp;
|
||||||
init_emphasis(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
init_emphasis(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||||
@@ -154,8 +155,7 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
change_oscillator_frequency(&osc, (FREQUENCY+((current_input*VOLUME_AUDIO)*DEVIATION)));
|
signal[i] = modulate_fm(&mod, current_input)*VOLUME;
|
||||||
signal[i] = get_oscillator_sin_sample(&osc)*VOLUME;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
||||||
|
|||||||
@@ -76,12 +76,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -74,12 +74,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -10,6 +10,7 @@
|
|||||||
#include "../lib/constants.h"
|
#include "../lib/constants.h"
|
||||||
#include "../lib/oscillator.h"
|
#include "../lib/oscillator.h"
|
||||||
#include "../lib/filters.h"
|
#include "../lib/filters.h"
|
||||||
|
#include "../lib/fm_modulator.h"
|
||||||
|
|
||||||
// Features
|
// Features
|
||||||
#include "features.h"
|
#include "features.h"
|
||||||
@@ -74,12 +75,12 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
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
|
.maxlength = 8192,
|
||||||
.fragsize = 2048
|
.fragsize = 4096
|
||||||
};
|
};
|
||||||
pa_buffer_attr output_buffer_atr = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = 4096,
|
.maxlength = 8192,
|
||||||
.tlength = 2048,
|
.tlength = 4096,
|
||||||
.prebuf = 0
|
.prebuf = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,9 +121,9 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Oscillator osc_mono, osc_stereo;
|
FMModulator mod_mono, mod_stereo;
|
||||||
init_oscillator(&osc_mono, 67000, SAMPLE_RATE);
|
init_fm_modulator(&mod_mono, 67000, 6000, SAMPLE_RATE);
|
||||||
init_oscillator(&osc_stereo, 80000, SAMPLE_RATE);
|
init_fm_modulator(&mod_stereo, 80000, 6000, SAMPLE_RATE);
|
||||||
#ifdef PREEMPHASIS
|
#ifdef PREEMPHASIS
|
||||||
Emphasis preemp_l, preemp_r;
|
Emphasis preemp_l, preemp_r;
|
||||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
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 mono = (current_left_input+current_right_input)/2.0f;
|
||||||
float stereo = (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)));
|
signal[i] = modulate_fm(&mod_mono, mono)*MONO_VOLUME+
|
||||||
change_oscillator_frequency(&osc_stereo, (80000+(stereo*6000)));
|
modulate_fm(&mod_stereo, stereo)*STEREO_VOLUME;
|
||||||
signal[i] = get_oscillator_sin_sample(&osc_mono)*MONO_VOLUME+
|
|
||||||
get_oscillator_sin_sample(&osc_stereo)*STEREO_VOLUME;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user