Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created May 5, 2022 15:35
Show Gist options
  • Save coderofsalvation/1c43ab467a1172ddecc00dd6860b12cc to your computer and use it in GitHub Desktop.
Save coderofsalvation/1c43ab467a1172ddecc00dd6860b12cc to your computer and use it in GitHub Desktop.
scaling limiter attempt
// 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