Wave sample volume changes
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. :(
I think 16 bit wave data is usually signed, so my first throught would be to make sure it's not unsigned.
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?
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.
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
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.
I heard OpenAL is a good API for sound but never used it.
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.
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.
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 -.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement