mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
configs
This commit is contained in:
@@ -1,49 +1,53 @@
|
||||
#include "stereo_encoder.h"
|
||||
|
||||
// Multiplier is the multiplier to get to 19 khz
|
||||
void init_stereo_encoder(StereoEncoder* st, uint8_t multiplier, Oscillator* osc, float audio_volume, float pilot_volume) {
|
||||
void init_stereo_encoder(StereoEncoder* st, uint8_t stereo_ssb, uint8_t multiplier, Oscillator* osc, float audio_volume, float pilot_volume) {
|
||||
st->multiplier = multiplier;
|
||||
st->osc = osc;
|
||||
st->pilot_volume = pilot_volume;
|
||||
st->audio_volume = audio_volume;
|
||||
#ifdef STEREO_SSB
|
||||
init_delay_line(&st->delay_pilot, STEREO_SSB*2+1);
|
||||
init_delay_line(&st->delay, STEREO_SSB*2+1);
|
||||
#endif
|
||||
if(stereo_ssb) {
|
||||
init_delay_line(&st->delay_pilot, stereo_ssb*2+1);
|
||||
init_delay_line(&st->delay, stereo_ssb*2+1);
|
||||
st->stereo_hilbert = firhilbf_create(stereo_ssb, 60);
|
||||
} else st->stereo_hilbert = NULL;
|
||||
}
|
||||
|
||||
float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right, firhilbf *hilbert) {
|
||||
float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right) {
|
||||
float mid = (left+right) * 0.5f;
|
||||
if(!enabled) return mid * st->audio_volume;
|
||||
#ifdef STEREO_SSB
|
||||
mid = delay_line(&st->delay, mid);
|
||||
#endif
|
||||
|
||||
if(st->stereo_hilbert) mid = delay_line(&st->delay, mid);
|
||||
|
||||
float half_audio = st->audio_volume * 0.5f;
|
||||
|
||||
float side = (left-right) * 0.5f;
|
||||
|
||||
#ifdef STEREO_SSB
|
||||
float complex stereo_hilbert;
|
||||
firhilbf_r2c_execute(*hilbert, side, &stereo_hilbert);
|
||||
float signalx2cos = get_oscillator_cos_multiplier_ni(st->osc, st->multiplier * 2.0f);
|
||||
#endif
|
||||
float complex stereo_hilbert = 0+0*I;
|
||||
if(st->stereo_hilbert) firhilbf_r2c_execute(st->stereo_hilbert, side, &stereo_hilbert);
|
||||
|
||||
float signalx1 = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier);
|
||||
#ifdef STEREO_SSB
|
||||
signalx1 = delay_line(&st->delay_pilot, signalx1);
|
||||
#endif
|
||||
|
||||
float signalx2cos = 0.0f;
|
||||
if(st->stereo_hilbert) {
|
||||
signalx1 = delay_line(&st->delay_pilot, signalx1);
|
||||
signalx2cos = get_oscillator_cos_multiplier_ni(st->osc, st->multiplier * 2.0f);
|
||||
}
|
||||
float signalx2 = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier * 2.0f);
|
||||
|
||||
#ifdef STEREO_SSB
|
||||
float stereo = (crealf(stereo_hilbert) * signalx2cos) + (cimagf(stereo_hilbert) * signalx2);
|
||||
return (mid*half_audio) + (signalx1*st->pilot_volume) + (stereo * half_audio);
|
||||
#else
|
||||
return (mid*half_audio) + (signalx1*st->pilot_volume) + ((side*signalx2) * half_audio);
|
||||
#endif
|
||||
if(st->stereo_hilbert) {
|
||||
float stereo = (crealf(stereo_hilbert) * signalx2cos) + (cimagf(stereo_hilbert) * signalx2);
|
||||
return (mid*half_audio) + (signalx1*st->pilot_volume) + (stereo * half_audio);
|
||||
} else {
|
||||
return (mid*half_audio) + (signalx1*st->pilot_volume) + ((side*signalx2) * half_audio);
|
||||
}
|
||||
}
|
||||
|
||||
void exit_stereo_encoder(StereoEncoder* st) {
|
||||
exit_delay_line(&st->delay);
|
||||
exit_delay_line(&st->delay_pilot);
|
||||
if(st->stereo_hilbert) {
|
||||
exit_delay_line(&st->delay);
|
||||
exit_delay_line(&st->delay_pilot);
|
||||
firhilbf_destroy(st->stereo_hilbert);
|
||||
st->stereo_hilbert = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define STEREO_SSB 12
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../dsp/oscillator.h"
|
||||
#include <liquid/liquid.h>
|
||||
@@ -16,8 +14,9 @@ typedef struct
|
||||
float pilot_volume;
|
||||
delay_line_t delay;
|
||||
delay_line_t delay_pilot;
|
||||
firhilbf stereo_hilbert;
|
||||
} StereoEncoder;
|
||||
|
||||
void init_stereo_encoder(StereoEncoder *st, uint8_t multiplier, Oscillator *osc, float audio_volume, float pilot_volume);
|
||||
float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right, firhilbf *hilbert);
|
||||
void init_stereo_encoder(StereoEncoder *st, uint8_t stereo_ssb, uint8_t multiplier, Oscillator *osc, float audio_volume, float pilot_volume);
|
||||
float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right);
|
||||
void exit_stereo_encoder(StereoEncoder* st);
|
||||
Reference in New Issue
Block a user