0

I am a newbie here. I am looking to know about any tool/quick way to convert a 24bit PCM raw(headerless) file, having 3 byte PCM samples, into a 32 bit PCM raw file which has 4 bytes per sample, with the MSByte of the 4 byte data as sign/zero extension of the 3byte sample.

Apart from the 24bit raw file, I have its corresponding WAVE file as well if it helps.

When tried in audacity, although it converted 24 bit to 32bit, it did not sign/zero extend, but it left shifted by 8, the 24 bit sample. So in effect the 24 bit sample was sitting in the left aligned 24 bits of the 32 bit , which is not what was desired.

Thanks.

goldenmean
  • 18,376
  • 54
  • 154
  • 211
  • are you starting with signed or unsigned 24 bit ? ... also you said right shifted by 8 when I believe you mean left shifted by 8 – Scott Stensland Apr 28 '17 at 20:30

2 Answers2

0

I'm going to assume you meant shifted left by 8 instead of shifted right by eight.

In this case the notion of sign extension is unnecessary. Imagine you have a negative 24-bit value 0x800000. Then the left shifted version would be 0x80000000. No sign extension but it still has the correct negative sign.

In summary I think audacity is doing exactly as it should, which is to simply shift the bits up. Unless for some reason your data is unsigned which would be exceptionally unusual.

jaket
  • 9,140
  • 2
  • 25
  • 44
  • I agree, its left shifted by 8, instead of right. Audacity is doing what is should - but volume of the sample is increased by 48dB, which is what I am trying to avoid and instead have a 24 bits in 32 bits, i.e. 24 bits right aligned within the 32 bits. – goldenmean May 02 '17 at 09:01
  • That is not correct. The volume is not increase by increasing the bit depth and then shifting left by the same number of bits. If you have a 16-bit signal with a positive peak of 0x7fff that is the reference known as 0 dBFS. Likewise if you have a 32-bit signal with a positive peak of 0x7fffffff then that is also 0dBFS. Fine if you want to attenuate the signal down for whatever reason but don't confuse that with converting bit-depths. – jaket May 03 '17 at 05:41
  • Thanks for the clarification. – goldenmean May 11 '17 at 09:54
0

Upon more search was pointed a way to do this is using sox - on linux.

sox -t s24 --endian little input.pcm -t s32 output.pcm vol 0.00390625

It worked fine. the vol 0.00390625 is to reduce the volume by 48dB because conversion of raw PCM sample from 24bit to 32bit, by default left shifts by 8 bit, but I want it to be down-shifted back by 8 bits which is reduction in volume by 48dB

goldenmean
  • 18,376
  • 54
  • 154
  • 211