experimental compressor

This commit is contained in:
Kuba 2024-03-22 14:46:37 +01:00 committed by GitHub
parent d589654a5b
commit 2dae591244
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 8 deletions

View File

@ -24,6 +24,8 @@
monaural or stereo audio. monaural or stereo audio.
*/ */
// #define ExperimentalLimiter
#include <sndfile.h> #include <sndfile.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
@ -72,7 +74,14 @@ float left_max=1, right_max=1; // start compressor with low gain
SNDFILE *inf; SNDFILE *inf;
#ifdef ExperimentalLimiter
float limiter(float input, float threshold) {
if (fabsf(input) > threshold) {
return (input > 0) ? threshold : -threshold;
}
return input;
}
#endif
float *alloc_empty_buffer(size_t length) { float *alloc_empty_buffer(size_t length) {
float *p =(float *) malloc(length * sizeof(float)); float *p =(float *) malloc(length * sizeof(float));
@ -201,7 +210,7 @@ int fm_mpx_open(char *filename, size_t len, int raw, double preemphasis, int raw
// samples provided by this function are in 0..10: they need to be divided by // samples provided by this function are in 0..10: they need to be divided by
// 10 after. // 10 after.
int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain, int enablecompressor, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex) { int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain, int enablecompressor, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex) {
*audio_buffer = 0.0; //in order to avoild what i call "frame looping", so the exact same thing isnt played, if the audio stream is cut off, audio also has frames like video, shocking right? so what happens if we have the same thing? we litrally transmit the exact same audio as the last time, its like if you'd create a tone generator with matching freqs and volumes, the same thing now and before *audio_buffer = 0.0;
int stereo_capable = (channels > 1) && (!disablestereo); //chatgpt int stereo_capable = (channels > 1) && (!disablestereo); //chatgpt
if(!drds && generate_multiplex) get_rds_samples(mpx_buffer, length, stereo_capable, rds_ct_enabled, rds_volume); if(!drds && generate_multiplex) get_rds_samples(mpx_buffer, length, stereo_capable, rds_ct_enabled, rds_volume);
@ -324,6 +333,11 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa
if(channels > 1) out_right = 0; if(channels > 1) out_right = 0;
} }
#ifdef ExperimentalLimiter
out_left = limiter(out_left, 10); //chatgpt says that its 20db
if( channels > 1 ) out_right = limiter(out_right, 10);
#endif
// Generate the stereo mpx // Generate the stereo mpx
if( channels > 1 ) { if( channels > 1 ) {
if(!disablestereo) { if(!disablestereo) {
@ -332,18 +346,14 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa
mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal
4.05 * carrier_38[phase_38] * (out_left-out_right) + // Stereo difference signal 4.05 * carrier_38[phase_38] * (out_left-out_right) + // Stereo difference signal
pilot_volume*carrier_19[phase_19]; // Stereo pilot tone pilot_volume*carrier_19[phase_19]; // Stereo pilot tone
phase_19++; phase_19++;
phase_38++; phase_38++;
if(phase_19 >= 12) phase_19 = 0; if(phase_19 >= 12) phase_19 = 0;
if(phase_38 >= 6) phase_38 = 0; if(phase_38 >= 6) phase_38 = 0;
} else { // polar stereo (https://forums.stereotool.com/viewtopic.php?t=6233, https://personal.utdallas.edu/~dlm/3350%20comm%20sys/ITU%20std%20on%20FM%20--%20R-REC-BS.450-3-200111-I!!PDF-E.pdf) } else { // polar stereo (https://forums.stereotool.com/viewtopic.php?t=6233, https://personal.utdallas.edu/~dlm/3350%20comm%20sys/ITU%20std%20on%20FM%20--%20R-REC-BS.450-3-200111-I!!PDF-E.pdf)
mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal (L+R) mpx_buffer[i] += 4.05*(out_left+out_right) + // Stereo sum signal (L+R)
4.05 * carrier_3125[phase_3125] * (out_left-out_right); // Stereo difference signal 4.05 * (out_left-out_right); // Stereo difference signal
//NO PIOT TONE!!!!!!!!!!!!!!!!!!!!!!!!!!!! (its missplelled correctly probably just like misspelled) //NO PIOT TONE!!!!!!!!!!!!!!!!!!!!!!!!!!!! (its missplelled correctly probably just like misspelled)
phase_3125++;
if(phase_3125 >= 6) phase_3125 = 0;
} }
} }
} else { } else {
@ -370,7 +380,6 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa
audio_pos++; audio_pos++;
} }
return 0; return 0;
} }