diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 0211f69..79ddb0c 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,8 +3,7 @@ { "name": "Win32", "includePath": [ - "${workspaceFolder}/**", - "C:\\lua\\*" + "${workspaceFolder}/**" ], "defines": [ "_DEBUG", diff --git a/lib/stereo_encoder.c b/lib/stereo_encoder.c index 38898b9..16bbcbc 100644 --- a/lib/stereo_encoder.c +++ b/lib/stereo_encoder.c @@ -16,31 +16,28 @@ void init_stereo_encoder(StereoEncoder* st, uint8_t stereo_ssb, uint8_t multipli float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right, float *audio) { float mid = (left+right) * 0.5f; if(!enabled) { - *audio = mid * 2.0f * st->audio_volume; + *audio = mid * st->audio_volume * 2.0f; return 0.0f; } - if(st->stereo_hilbert) mid = delay_line(&st->delay, mid); - float side = (left-right) * 0.5f; - - 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); - - 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); - - *audio = mid * st->audio_volume; if(st->stereo_hilbert) { - float stereo = (crealf(stereo_hilbert) * signalx2) - (cimagf(stereo_hilbert) * signalx2cos); - *audio += stereo * st->audio_volume; - } else *audio += (side*signalx2) * st->audio_volume; + float complex stereo_hilbert = 0+0*I; + float signalx2cos = get_oscillator_cos_multiplier_ni(st->osc, st->multiplier * 2.0f); + + mid = delay_line(&st->delay, mid); + *audio = mid * st->audio_volume; + signalx1 = delay_line(&st->delay_pilot, signalx1); + + firhilbf_r2c_execute(st->stereo_hilbert, side, &stereo_hilbert); + + *audio += ((crealf(stereo_hilbert) * signalx2) - (cimagf(stereo_hilbert) * signalx2cos)) * st->audio_volume; + return signalx1 * st->pilot_volume; + } + + *audio = mid * st->audio_volume + (side*signalx2) * st->audio_volume; return signalx1 * st->pilot_volume; } diff --git a/src/fm95.c b/src/fm95.c index c1e842b..6ef6907 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -164,8 +164,6 @@ if((pulse_error = write_PulseOutputDevice(&runtime->output_device, output, sizeo int run_fm95(FM95_Config* config, FM95_Runtime* runtime, FM95_RunResult* result) { float output[BUFFER_SIZE]; - FM95_RunResult temp_result; - memset(&temp_result, 0, sizeof(FM95_RunResult)); int pulse_error; @@ -214,14 +212,14 @@ int run_fm95(FM95_Config* config, FM95_Runtime* runtime, FM95_RunResult* result) float r = audio_stereo_input[2*i+1]*config->audio_preamp; float mono = 0.5f * (fabsf(l) + fabsf(r)); - temp_result.input_level = mono; + result->input_level = mono; if(config->agc_max != 0.0) { float agc_gain = process_agc(&runtime->agc, mono); l *= agc_gain; r *= agc_gain; - temp_result.agc_gain = agc_gain; - } else temp_result.agc_gain = 0.0f; + result->agc_gain = agc_gain; + } else result->agc_gain = 0.0f; float mod_l, mod_r; @@ -238,7 +236,7 @@ int run_fm95(FM95_Config* config, FM95_Runtime* runtime, FM95_RunResult* result) mod_l = tanhf(mod_l * config->volumes.drive) * softclip_norm; mod_r = tanhf(mod_r * config->volumes.drive) * softclip_norm; - if(do_result) temp_result.audio_level = (mod_l + mod_r) * 0.5f; + if(do_result) result->audio_level = (mod_l + mod_r) * 0.5f; mpx = stereo_encode(&runtime->stencode, config->stereo, mod_l, mod_r, &audio); @@ -266,12 +264,11 @@ int run_fm95(FM95_Config* config, FM95_Runtime* runtime, FM95_RunResult* result) } } - mpx = bs412_compress(&runtime->bs412, audio, mpx+mpx_in[i], &temp_result.mpx_power); - temp_result.bs412_gain = runtime->bs412.gain; + mpx = bs412_compress(&runtime->bs412, audio, mpx+mpx_in[i], &result->mpx_power); + result->bs412_gain = runtime->bs412.gain; output[i] = tanhf(mpx)*config->master_volume; // Ensure peak deviation of 75 khz (or the set deviation), assuming we're calibrated correctly - } memcpy(result, &temp_result, sizeof(FM95_RunResult)); - _pulse_output; + } _pulse_output; } return 0; @@ -338,13 +335,8 @@ static int config_handler(void* user, const char* section, const char* name, con else if(MATCH("advanced", "lpf_order")) pconfig->lpf_order = atoi(value); else if(MATCH("advanced", "stereo_ssb")) pconfig->stereo_ssb = atoi(value); else if(MATCH("advanced", "preemp_unity")) pconfig->preemp_unity_freq = strtof(value, NULL); - else if(MATCH("advanced", "sample_rate")) { - pconfig->sample_rate = atoi(value); - if(pconfig->sample_rate < 0) { - fprintf(stderr, "Negative sample rate\n"); - return 0; - } - } else if(MATCH("advanced", "lpf_cutoff")) { + else if(MATCH("advanced", "sample_rate")) pconfig->sample_rate = atoi(value); + else if(MATCH("advanced", "lpf_cutoff")) { pconfig->lpf_cutoff = strtof(value, NULL); if(pconfig->lpf_cutoff > (pconfig->sample_rate * 0.5)) { pconfig->lpf_cutoff = (pconfig->sample_rate * 0.5); @@ -465,8 +457,8 @@ static void *handle_client(ipc_client_arg_t *arg) { FM95_Data* data = arg->user_data; free(arg); - char buf[BUF_SIZE]; - char reply = 0; + uint8_t buf[BUF_SIZE]; + uint8_t reply = 0; ssize_t n; float val; uint8_t bval;