24 bit signed integer binary conversion help needed

  • Thread starter Robert Somerville
  • Start date
R

Robert Somerville

hi;
I am trying to read 24bit signed WAV format (little endian) data from a
WAV file and convert it to 32 bit little endian integer format ... can
anybody please tell me how to do the conversion from 24 bit to 32 bit
with a snippet of Python code ???

Thanks so much
Robert Somerville
 
G

Grant Edwards

I am trying to read 24bit signed WAV format (little endian) data from a
WAV file and convert it to 32 bit little endian integer format ... can
anybody please tell me how to do the conversion from 24 bit to 32 bit
with a snippet of Python code ???

def sext24(d):
if ord(d[2]) & 0x80:
return d+'\xff'
else:
return d+'\x00'
 
G

Grant Edwards

I am trying to read 24bit signed WAV format (little endian) data from a
WAV file and convert it to 32 bit little endian integer format ... can
anybody please tell me how to do the conversion from 24 bit to 32 bit
with a snippet of Python code ???

def sext24(d):
if ord(d[2]) & 0x80:
return d+'\xff'
else:
return d+'\x00'


I guess I assumed you knew how to read 3 bytes of data from a
file:

f = open('datafile','rb')
d = f.read(3)
 
I

Irmen de Jong

hi;
I am trying to read 24bit signed WAV format (little endian) data from a
WAV file and convert it to 32 bit little endian integer format ... can
anybody please tell me how to do the conversion from 24 bit to 32 bit
with a snippet of Python code ???

Thanks so much
Robert Somerville

Are you using the standard wave module?
I guess that will produce a string of 3-byte audio frames with readframes().

Won't it work to chop this up in individual 3-byte frames,
then appending a '\0' char to every frame,
and then writing the frames to the target wave ?

-irmen
 
G

Grant Edwards

Are you using the standard wave module? I guess that will
produce a string of 3-byte audio frames with readframes().

Won't it work to chop this up in individual 3-byte frames,
then appending a '\0' char to every frame, and then writing
the frames to the target wave ?

Not if the 3-byte values are signed two's compliment values.
 
I

Irmen de Jong

Not if the 3-byte values are signed two's compliment values.

Meh. The wave module is pretty useless for format conversion then until
it grows some utility methods.

-irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top