Created
May 5, 2022 15:35
-
-
Save coderofsalvation/1c43ab467a1172ddecc00dd6860b12cc to your computer and use it in GitHub Desktop.
scaling limiter attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem: it's bad | |
if( treshold > 0.0f ){ | |
float avg = srcL + srcR; | |
if( avg > peak ) peak = avg; | |
buffer[i] = (mp_sint32)( tanh(srcL*1.2) * 1.31 * max); // compand once | |
buffer[i+1] = (mp_sint32)( tanh(srcR*1.2) * 1.31 * max); // compand once | |
if( ZEROCROSSING(srcL+srcR,lastL) ){ | |
for( ; offset <= i; offset+=2 ){ | |
float L = (float)buffer[offset]*(1.0/max); | |
float R = (float)buffer[offset+1]*(1.0/max); | |
if( peak > treshold ){ | |
L *= (treshold/peak); | |
R *= (treshold/peak); | |
} | |
buffer[offset] = (mp_sint32)( L * max); | |
buffer[offset+1] = (mp_sint32)( R * max); | |
} | |
peak = 0.0; | |
offset = i; | |
} | |
lastL = srcL+srcR; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment