Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Converting RAW 24bit Signed PCM to 32bit PCM raw (Read 4560 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Converting RAW 24bit Signed PCM to 32bit PCM raw

Hi,
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 right 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.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #1
Is there a reason you can't use a WAV file?    I have to assume Audacity makes a valid WAV file, although I've never used 32-bit integer.

Quote
but it right 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 ,
Those are opposites...

A WAV file would be left-shifted and "left aligned" with zeros in the rightmost (least significant) byte.  

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #2
Mmm... I believe that what you want is "24-in-32"bits. I.e. that the content is still ranged in 24bits, but the size of the sample is 32bits.
That format is mostly used in software to send data to the soundcard, but not for storage.
I'm not sure which application could do that, but implementing it on your own is not too difficult:
https://sourceforge.net/p/psycle/code/HEAD/tree/trunk/psycle-audiodrivers/src/psycle/audiodrivers/asiointerface.cpp#l437
You would do what is shown in that "ASIOSTInt24LSB" case. That way you would have an 32bit int with a 24bit ranged value, out of a 3 byte value.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #3
It should be zero padded to the least significant bits.  If that isnt what you want just lower the gain 48 dB.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #4
Like this:
Code: [Select]
sox -t s24 --endian little input.pcm -t s32 output.pcm vol 0.00390625
Depending on your file format you need to change --endian option.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #5
Like this:
Code: [Select]
sox -t s24 --endian little input.pcm -t s32 output.pcm vol 0.00390625
Depending on your file format you need to change --endian option.
Thanks a lot . First I missed mentioning the volume Sox conversion did the same thing as Audacity which is not what is desired. It Left shifted the 24 bit sample by 8, and filled zeros in the least significant byte. But then when I did mention what you said, it works fine.
I guess  0.00390625 setting for volume coming from reducing the volume by 48dB to shift the samples right by 8 bits again.
Many thanks.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #6
Like this:
Code: [Select]
sox -t s24 --endian little input.pcm -t s32 output.pcm vol 0.00390625
Depending on your file format you need to change --endian option.
Thanks a lot . First I missed mentioning the volume Sox conversion did the same thing as Audacity which is not what is desired. It Left shifted the 24 bit sample by 8, and filled zeros in the least significant byte. But then when I did mention what you said, it works fine.
I guess  0.00390625 setting for volume coming from reducing the volume by 48dB to shift the samples right by 8 bits again.
Just curious- How does come with exact volume setting to get the desired effect of right shifting the 32 bit sample and leaving the sample values unchanged.
When i tried with vol setting 0.00398107 the sample values differed slightly buy 1/2 bits in LSBit.
Many thanks.

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #7
Copy and paste the following string in google:
Code: [Select]
log10(2) * 20 * 8

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #8
I guess  0.00390625 setting for volume coming from reducing the volume by 48dB to shift the samples right by 8 bits again.
Just curious- How does come with exact volume setting to get the desired effect of right shifting the 32 bit sample and leaving the sample values unchanged.
To align samples to LSB, you want to right shift each samples by 8 bits, which just means multipling by 1/256 (= 0.00390625).
This sox command line happens to work because sox internally uses 32bit integer sample format, and vol effect accepts simple linear scale which allows us to specify exact 1/256 in decimal form (which is then parsed into double and simply multiplied to each samples).

Re: Converting RAW 24bit Signed PCM to 32bit PCM raw

Reply #9
I guess  0.00390625 setting for volume coming from reducing the volume by 48dB to shift the samples right by 8 bits again.
Just curious- How does come with exact volume setting to get the desired effect of right shifting the 32 bit sample and leaving the sample values unchanged.
To align samples to LSB, you want to right shift each samples by 8 bits, which just means multipling by 1/256 (= 0.00390625).
This sox command line happens to work because sox internally uses 32bit integer sample format, and vol effect accepts simple linear scale which allows us to specify exact 1/256 in decimal form (which is then parsed into double and simply multiplied to each samples).

Thanks. got it.
In the logarithmic scale to linear scale conversion formula, I  tried -48dB , which is incorrect - correct value is -48.1647993062.