gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Question about quality

#37139 - ProblemBaby - Mon Mar 07, 2005 11:59 pm

Hi...
My player works well but the quality is not enough!
Do you have any hints to make it sound better?
Right now I mix at 18157hz Ive also tried with 31536hz but it doesnt sound much better.
When I listed to the XM in ModPlugTracker with 8-bit, stereo, 19800hz
It sounds clear and good except for a static noise but in my player,
it sounds like a factory at low notes and someone hammering at high notes=) shouldn't it be possible to make it sound as good as it do in ModPlugTracker with those settings?

All hints (big or small) are welcome!
Thanks in advance

#37158 - FluBBa - Tue Mar 08, 2005 10:24 am

Are you mixing to a 16bit buffer and then scale it to 8bit, or are you downscaling the samples before you mix them?
_________________
I probably suck, my not is a programmer.

#37165 - kashiwa - Tue Mar 08, 2005 12:16 pm

I think that Interpolation (linear or cubic spline or...) takes much change.
How about doing incidentally when scaling it from 16 to 8 bits?

#37166 - ProblemBaby - Tue Mar 08, 2005 12:21 pm

I mix 8 samples a time so I loop through each channel and get 8 samples
and then put them in the final buffer.

To get much speed improvement Ive instead of put each sample in one register I put 2 samples in one register so its like a 16 bit buffer
but since I mix 24 channels I also have to shift by 3 after the multiplication
to make it not overflow. so its like 11 bit per sample.

#37185 - poslundc - Tue Mar 08, 2005 5:49 pm

A downshift by three corresponds to dividing by 8.

If you are mixing 24 8-bit samples, you will have to divide by 24 to prevent overflow, not 8.

At that point, I would strongly recommend clipping your results instead of scaling them, since the volume loss you get when dividing by 24 is bound to be significant.

Dan.

#37192 - ProblemBaby - Tue Mar 08, 2005 7:48 pm

Max sample number = 255
Max sample volume = 0x40

so division by 8 is correct in fact it make it possible to mix up to 32 channels, but I dont want to waste memory/speed on eight more channels since I never will use them anyway.

I dont do the division at the end.
First I Shift them with 3 and add them to the register
then when all samples is added I Shift with 1 (a little scale)
and then clip them..

kashiwa wrote:

I think that Interpolation (linear or cubic spline or...) takes much change.
How about doing incidentally when scaling it from 16 to 8 bits?


how do you mean?

#37196 - poslundc - Tue Mar 08, 2005 8:25 pm

Downshifting your sample data before multiplying the volume could easily be causing significant loss of sound quality.

Observe a random example:

Code:
Sample value S = 151
Volume level V = 30

(S >> 3) * V = 540
(S * V) >> 3 = 566


In this case, by downshifting early you've suffered a 4.6% loss of precision in the value of your sample.

I would recommend using the MLA instruction instead to multiply your samples-and-volumes and add them together. Then you can clip them when you're done.

Dan.

#37197 - DekuTree64 - Tue Mar 08, 2005 8:28 pm

Mixing more than 4 channels with the 16-bit packing trick will always give you a cut in quality. Ideally, you don't want to shift down at all until the very end. It cuts accuracy and is a pretty big speed hit doing it every sample.
According to my experience, the best quality vs. clipping distortion tradeoff with 4-16 channels is to shift down by 2 and clip. Not sure about 24 channels, but would probably still sound better than shifting down by 3.

What I would suggest for you is mixing 3 batches of 8 channels, and then adding those results up. To get around the overflowing problem, limit your maximum volume to 32. 255smp*8chns*32vol=65280, fits in 16 bits.

However, if you batch your channels intelligently, you can take all the ones that already have volume less than 32, and you won't have to shift their volumes down at all before mixing. Just shift down one more bit when combining up the batches at the end to get them to the same scale as the chopped batch. Good place for dynamic code.
Of course, if you don't have 8 channels (one batch) with volume less than 32, you'll have to chop them all before mixing, but if you had that many channels that loud, you wouldn't be able to make out such fine volume changes very well anyway.


Ok, now I'm inspired to work on my old sound article again. Must get the one on effects finished up tonight so I can get started on mixers. I could go on all day about this stuff :)
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#37210 - ProblemBaby - Tue Mar 08, 2005 10:18 pm

Poslundc:
Yes I know thats why I do like..

((S1 * V) >> 3) + ((S2 * V) >> 3) + ...
and then at the end downsample again.

I tried skip that thing and just mix 8 channels in once, but it doesnt sound much better, Iam starting to think that Ive coded something wrong.
1. Because when I initialize I hear a loud click in the right speaker
but not ive I add 16 to the mixingbuffer.
2. Because it sounds so strange=), its like someone screaming noise in the same pitches as the notes.

Do anyone have a player that supports XM in would be interesting to try how it sounds, in someone elses player.

#37211 - ProblemBaby - Tue Mar 08, 2005 10:22 pm

Wait.. Now I saw something intersesting in ModPlugTracker it is a settings called resampling. My player sounds like does if I select no resampling.
and it sounds good with the other settings Linear, Cubic spline and high quality.
that was what kashiwa mentioned, but what does it mean???

#37215 - DekuTree64 - Wed Mar 09, 2005 12:04 am

Yeah, resampling makes a big difference. It will wreck your performance with 24 channels though, so probably best to skip it.


Is the distortion only on the left ear? From your explanation of what you're doing, it looks like you're not clearing the lower bits of the top sample before shifting down, meaning that the least significant bits of the top sample become the MOST significant bits of the bottom (very bad).

For example, if you have two 16 bit samples together, both 0x7FFF, it looks like 0x7FFF7FFF. If you just shift down by 3, then you have 0x0FFFEFFF. Looking at them seperately again, now the top is 0x0FFF, and the bottom is 0xEFFF. Different, when they should have been the same. To fix that, you have to clear the bottom bits of the top sample before shifting, like
Code:
sample &= ~0x00070000;   // Clear bottom 3 bits
sample >>= 3;


So you get 0x7FFF7FFF & ~0x70000 = 0x7FF87FFF. Shift down 3, and you get 0x0FFF0FFF, now they're the same and good. That extra clearing takes one more cycle for every sample on every channel though, which is a pretty hefty hit with 24 channels. That's why you should aim not to shift down during mixing (in addition to the quality loss).
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#37217 - ProblemBaby - Wed Mar 09, 2005 12:23 am

Yepp Ive done the really important BIC before adding them, its a click noise in the right speaker.

Ive a little idea. right now I mix at 18157 if I start to mix at 36314 instead
but still load as many samples I did with 18157 and in then but a delta value between the two samples, do you think it should work?

something like:
S1, S1+S2/2, S2, S2+S3/2, S3
It would be easy and not so slow to implement
S is the final mix.

Do you think it would sound crap or better? its a kind of linear interpolition isnt it?

#37236 - kashiwa - Wed Mar 09, 2005 5:51 am

Yes, that is the linear interpolation.
Use only the calculated value if you dont wanna change a sampling rate.
ex: (S1+S2)/2, (S2+S3)/2, (S3+S4)/2, ...
However, the effect might be thin.
---
sorry for my unskilled English. I say "AYBABTU.hahaha."

#37322 - tepples - Thu Mar 10, 2005 2:26 pm

ProblemBaby wrote:
Wait.. Now I saw something intersesting in ModPlugTracker it is a settings called resampling. My player sounds like does if I select no resampling.

Most sound engines do. I'd suggest composing with "no resampling" turned on and most of the bass (below 500 Hz) EQ'd down so that you can predict what your song is going to sound like on the hardware.

kashiwa: Your technique looks the same as applying a low-pass filter (namely FIR[0.5 0.5]) to all samples before mixing them; it won't do much.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.