I'm sorry if this is obvious, but did you try simply dividing by 2?
How about right shift one bit, either signed or unsigned? IIRC 8-bit PCM is unsigned while 16-bit is signed.
Multiply by 0.5, divide by 2.. It all compiles to the same thing. :-)
Quote from: Fullstop on 21 November, 2008, 02:05:12 PMMultiply by 0.5, divide by 2.. It all compiles to the same thing. :-)Not necessarily. Integer divide by 2 will prevent any of the floating-point nonsense that you were worried about.
If I have a 16 bit LPCM (WAV) sample, how would I go about adjusting the volume? I had assumed that it was a signed 16 bit value and that I could just multiply by 0.5 to lower the volume. This didn't work for me -- the result was full of static and pops.Before I get too far, I'm decoding this audio on a micro controller without a FPU. I tried it with fixed integer multiplication, but to rule out an error on my part, I used the software floating point support. The result was the same. Am I missing something with PCM? This feels like it should be quite simple! :-)
recordedBytes = frameCount * bytesPerFrameFor ct = 0 To sampleRate/10 Step 3CopyMemory(*recordBuffer + ct, @samp24,3) ;COPY 3 BYTES FROM BUFFER INTO VARIABLEtemp.f = samp24 ;CONVERT 24-BIT SAMPLE TO FLOATtemp.f = temp.f * 1 ;APPLY GAINsamp24 = temp.f ;CONVERT FLOAT TO 24-BIT INTEGERCopyMemory(@samp24,*recordBuffer + ct,3) ;COPY 3 BYTES BACK TO BUFFERNextPa_WriteStream (*outStream, *recordBuffer,recordedBytes / bytesPerFrame) ;WRITE TO PORTAUDIO
By default, when a data type is not indicated, the data is an integer. [...] If you don't assign an initial value to the variable, their value will be 0.
Integer .i 4 bytes (using 32-bit compiler) -2147483648 to +2147483647Integer .i 8 bytes (using 64-bit compiler) -9223372036854775808 to +9223372036854775807