Email or username:

Password:

Forgot your password?
Top-level
⛧ esoterik ⛧

currently i'm promoting each 8-bit sample to an unsigned short and averaging them, e.g. (left+right)/2.

it sounds ok but not great: as expected it gets quieter and it maybe also introduces some artifacts.

5 comments | Expand all CWs
⛧ esoterik ⛧

i can imagine doing some kind of smart scaling/compression to keep the apparent gain higher but i sort of dread figuring out how to do it with integer math

Howard Chu @ Symas

@d6 nope, simple sum like you've done is all there is to it. You might also first check for clipping before deciding to do the div by 2. If nothing clipped, then skip it.

⛧ esoterik ⛧

@hyc i don't think that approach is great because when you are near clipping you're unscaled then suddenly you drop down by 2 once you exceed the peak. i have seen people talk about clamping at the max value but in my test cases that sounds too distorted.

thanks for confirming my intuition about the sum!

Howard Chu @ Symas

@d6 no I meant, scan the entire audio stream. If nothing clips, skip the div for the whole thing.

Clamping just a few samples would distort the hell out of it, yeah.

Nick Appleton

@d6 what you’re doing is fine if you need both channels preserved.

Different people do different things here (l+r)*.5 is one sensible option and will preserve the level of correlated content in the left and right channels. This makes sense for most music. If the channels are not correlated, you will observe a level dip - but if you wanted to fix this, you would need a peak limiter (and clipping is one peak limiter) and that’s a whole other can of worms.

Go Up