How can I converto a 4 bit/sample raw audio file to an 8 bit/sample file?
Convert 4 bit to 8 bit audio
Started by ●February 8, 2007
Reply by ●February 8, 20072007-02-08
clayton.aa@gmail.com wrote:> How can I converto a 4 bit/sample raw audio file to an 8 bit/sample > file?Extend each nibble to a byte. Do you need to be told how? Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply by ●February 8, 20072007-02-08
Jerry Avins wrote:> clayton.aa@gmail.com wrote: > >> How can I converto a 4 bit/sample raw audio file to an 8 bit/sample >> file? > > Extend each nibble to a byte. Do you need to be told how?Jerry, your answer may just be that simple, but I have never seen a 4 bit per sample format that was not some type of ADPCM. So clayton.aa may need to provide more details about the software or hardware that produced those samples. -- Phil Frisbie, Jr. Hawk Software http://www.hawksoft.com
Reply by ●February 8, 20072007-02-08
clayton.aa@gmail.com wrote:> How can I converto a 4 bit/sample raw audio file to an 8 bit/sample > file?Four bit won't sound very good, but if you have signed four bit data use (C/C++ code): signed_eight_bit_data_value = signed_four_bit_value << 4 ; if you have unsigned 4 bit data and want signed eight bit data use: signed_eight_bit_data_value = (signed_four_bit_value - 2) << 4 ; and so on. I repeat, 4 bit data is going to sound really bad whatever you do. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ A Microsoft Certified System Engineer is to computing what a MacDonalds Certified Food Specialist is to fine cuisine.
Reply by ●February 8, 20072007-02-08
On Feb 8, 6:29 pm, Erik de Castro Lopo <e...@mega-nerd.com> wrote:> clayton...@gmail.com wrote: > > How can I converto a 4 bit/sample raw audio file to an 8 bit/sample > > file? > > Four bit won't sound very good, but if you have signed four bit data > use (C/C++ code): > > signed_eight_bit_data_value = signed_four_bit_value << 4 ;Problem with this is that the maximum 4-bit value does not map to the maximum 8-bit value. In the unsigned case, it makes sense that the value 15 should map to 255. Shifting right by 4 gives 240, not 255. Instead, multiply by 17. Scott
Reply by ●February 9, 20072007-02-09
On 2007-02-09, Scott L <scott-sp02@neuralnw.com> wrote:>> >> signed_eight_bit_data_value = signed_four_bit_value << 4 ; > > Problem with this is that the maximum 4-bit value does not map to the > maximum 8-bit value. In the unsigned case, it makes sense that the > value 15 should map to 255. Shifting right by 4 gives 240, not 255. > > Instead, multiply by 17.The OP could google 'dynamic range expansion'. Multiplying by 17 is the same as: signed_eight_bit_data_value = (signed_four_bit_value << 4) | signed_four_bit_value; which generalizes to replicating the MSBs over and over until you have as many bits as you want. Eg if you have 565 RGB and a 666 device such as an LCD panel, you'd connect the R and B channels LSB's to the MSB as well. -- Ben Jackson AD7GD <ben@ben.com> http://www.ben.com/
Reply by ●February 9, 20072007-02-09
Phil Frisbie, Jr. wrote:> Jerry Avins wrote: >> clayton.aa@gmail.com wrote: >> >>> How can I converto a 4 bit/sample raw audio file to an 8 bit/sample >>> file? >> >> Extend each nibble to a byte. Do you need to be told how? > > Jerry, your answer may just be that simple, but I have never seen a 4 > bit per sample format that was not some type of ADPCM. So clayton.aa may > need to provide more details about the software or hardware that > produced those samples.ADPCM is in effect a form of modulation or coding, and of course needs to be to decoded before simple PCM can be constructed from it. I answered quickly and simply, remembering a 4-bit A2D I once built to prove that speech could be at least intelligible at 4 bits. Some of my recordings were converted to 8 bits (offset binary) for portability. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply by ●February 9, 20072007-02-09
Scott L wrote:> On Feb 8, 6:29 pm, Erik de Castro Lopo <e...@mega-nerd.com> wrote: >> clayton...@gmail.com wrote: >>> How can I converto a 4 bit/sample raw audio file to an 8 bit/sample >>> file? >> Four bit won't sound very good, but if you have signed four bit data >> use (C/C++ code): >> >> signed_eight_bit_data_value = signed_four_bit_value << 4 ; > > Problem with this is that the maximum 4-bit value does not map to the > maximum 8-bit value. In the unsigned case, it makes sense that the > value 15 should map to 255. Shifting right by 4 gives 240, not 255. > > Instead, multiply by 17.Does half a dB really matter? Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply by ●February 9, 20072007-02-09
On Feb 8, 8:30 pm, Jerry Avins <j...@ieee.org> wrote:> Scott L wrote: > > Problem with this is that the maximum 4-bit value does not map to the > > maximum 8-bit value. In the unsigned case, it makes sense that the > > value 15 should map to 255. Shifting right by 4 gives 240, not 255. > > > Instead, multiply by 17. > > Does half a dB really matter?It's critical when dealing with images -- you want white to map to white. It's invertible (just shift right four bits), like your method, and involves only a shift-add, which on many platforms is no more expensive than a shift. There's nothing inherently wrong with just shifting left, as long as its acceptable for the application. Scott
Reply by ●February 9, 20072007-02-09
Phil Frisbie, Jr. wrote:> Jerry, your answer may just be that simple, but I have never seen a 4 > bit per sample formatI think the GameBoy used 4 bit PCM samples which is why I didn't think it was taht unsual.> that was not some type of ADPCM.Thats another possibility or rather bunch of possibilities. There a many dozen ADPCM format which result in 4 bits per sample. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "Linux is produced to be used, whereas the others are produced to be sold" -- Bobby D. Bryant