Jump to content
  • Advertisement
Sign in to follow this  
Dospro

Mixing sound

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have a doubt. I have 2 samples and i want them to be listen together at the same time. Someone told me that adding the 2 of them and then dividing them by 2 will result in the final sample. Is there another better algorith to make this?

Share this post


Link to post
Share on other sites
Advertisement
Simply adding them together is the normal and physically way of doing it. I suppose that you could divide the results by a constant factor (probably the maximum number of simultaneous channel) to keep them in range, but scaling by the number of active channels would be very weird..
However to improve the quality you might want to consider keeping the mixed values from overflowing (i.e. clipping) and maybe also use a temporary work buffer with higher precision than the final output buffer.

Share this post


Link to post
Share on other sites
Huuhh???

Well, the problem is that if i add them i got a terribly disturbed sound. I must mention im working with 8 bit sound at 44100.
So, i get all the channels samples(4) and then add them together and finally dived it by 4. This still gives me distoricioned sound. Thats why im searching for a better way.

Share this post


Link to post
Share on other sites
Make sure that you're using at least 16-bit mixing, even if the output is 8-bit, and that there's proper sign extension going on when converting the input bytes to the new precision.

Are the input samples signed or unsigned? To handle unsigned samples properly you'll still have to convert them into a signed format in the work-buffer and not convert them back into the unsigned format until after the division.

Share this post


Link to post
Share on other sites
Lets consider what happens if you simply add unsigned samples together.
Unsigned 8-bit samples use a range between 0 and 255, with 128 as the "mid" point (sorry, but I really don't know the correct terminology).
Naturally you'd expect that mixing in such a sample won't affect the final output.

However that adding the biased null value to of an unsigned sample as is really does change things, adding 128 to a value gives different results than not adding anything at all.

Instead you'll first have to convert all samples to a signed format by "unbiasing" them (subtracting -128), mix them all together, divide the result by four, and finally add the bias back again before writing the results.

I'm a bit too tired to write up a decent explanation right now. Try googling a little if you're still unsure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!