Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > 24 bit signed integer binary conversion help needed

Reply
Thread Tools

24 bit signed integer binary conversion help needed

 
 
Robert Somerville
Guest
Posts: n/a
 
      01-08-2010
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
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      01-08-2010
On 2010-01-08, Robert Somerville <(E-Mail Removed)> wrote:

> 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'

--
Grant Edwards grante Yow! Am I having fun yet?
at
visi.com
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      01-08-2010
On 2010-01-08, Grant Edwards <(E-Mail Removed)> wrote:
> On 2010-01-08, Robert Somerville <(E-Mail Removed)> wrote:
>
>> 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)


--
Grant Edwards grante Yow! I need to discuss
at BUY-BACK PROVISIONS
visi.com with at least six studio
SLEAZEBALLS!!
 
Reply With Quote
 
Irmen de Jong
Guest
Posts: n/a
 
      01-08-2010
On 8-1-2010 22:12, Robert Somerville wrote:
> 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
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      01-08-2010
On 2010-01-08, Irmen de Jong <(E-Mail Removed)> wrote:
> On 8-1-2010 22:12, Robert Somerville wrote:
>> 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 ???

>
> 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.

--
Grant Edwards grante Yow! I feel like I am
at sharing a ``CORN-DOG''
visi.com with NIKITA KHRUSCHEV ...
 
Reply With Quote
 
Irmen de Jong
Guest
Posts: n/a
 
      01-08-2010
On 8-1-2010 22:37, Grant Edwards wrote:
> On 2010-01-08, Irmen de Jong<(E-Mail Removed)> wrote:
>> 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.
>


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

-irmen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a signed binary number into a signed one ? Rob1bureau VHDL 1 02-27-2010 12:13 AM
24 bit signed integer binary conversion help needed Robert Somerville Python 0 01-08-2010 10:25 PM
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
A 64-bit binary returning a value to a 32-bit binary? spammenotplui31@yahoo.ca C Programming 12 04-08-2007 07:02 AM
conversion of signed integer to unsigned integer junky_fellow@yahoo.co.in C Programming 14 06-18-2005 02:29 PM



Advertisments