Jump to content
  • Advertisement
Sign in to follow this  
kurdt

Wave sample volume changes

This topic is 4836 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

Hello all, I hope this is the right place to ask about a simple question relating to wave volume. I have a wave file, 44100 hz, 16 bit, 2 channel. It is recorded at a certain volume. I wish to play it through the wave device at 50% of it's volume without touching the volume control. So I load the entire wave file into a buffer, iterate over the samples, multiply each sample by .5 and then put it another buffer and play it. But all I get is garbage and sheer noise. If I do the above, but multiply it with 1.0 instead of .5, it plays clearly, just as if it was the original. Mutiplying with 2.0 or 3.0 makes it louder and introduces distortion. I'm wondering if anyone can tell me why multiplying it with a number < 1 introduces garbage/noise. I hope my theory is correct, if I'm doing something totally wrong, please let me know. :(

Share this post


Link to post
Share on other sites
Advertisement
Get yourself a wave file editor (even Sound Recorder will do *shudder*) and alter the sound that way. It's much easier, unless you want to do it dynamically, in which case why not use an API to do it?

Share this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
I think 16 bit wave data is usually signed, so my first throught would be to make sure it's not unsigned.


Hi, I checked and it was signed, and so are my samples. A quick check shows that all the positive samples are reduced to 60% of their value, but the negative ones are not, that's something to go on, I guess.

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo_E_49
Get yourself a wave file editor (even Sound Recorder will do *shudder*) and alter the sound that way. It's much easier, unless you want to do it dynamically, in which case why not use an API to do it?


Can you suggest an API that handles changing the amplitude of a wave file the way I want it? I'd appreciate it.

thanks,
kurdt

Share this post


Link to post
Share on other sites
When multiplying by 0.5 is the same as dividing by 2. If you divide all your samples by 2 do you still get garbabe/noise?

I heard OpenAL is a good API for sound but never used it.

Share this post


Link to post
Share on other sites
Yes I did.

I fixed it, I don't quite know why, but the only change I made was to use a signed long as a temporary variable and then assign back. I think this may have eliminated the overflow, if any at all.

Thanks for all your help guys, it certainly helped me jog my mind.

Share this post


Link to post
Share on other sites
try using a float as a tempuary variable(or do all calculations as floats) and see if it gives better results. Also after the calculation check if the number is too big to be stored in a short, if yes just set the short the largest number it can be for + or -.

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!