Home All Groups Group Topic Archive Search About
Author
28 Aug 2010 3:48 PM
Alexandros Peropulous
Hello!
I have some bytes which are from a wav file.
They are without a header.
Normally, I simply add the header, the file size, and I am done, I have
a complete wav file.
But this time, my bytes are from a BigEndian wav file. Does anybody know
how to convert them to LittleEndian?

Thanks a lot for help!
Alex

Author
29 Aug 2010 2:27 AM
Jason Keats
Alexandros Peropulous wrote:
> Hello!
> I have some bytes which are from a wav file.
> They are without a header.
> Normally, I simply add the header, the file size, and I am done, I have
> a complete wav file.
> But this time, my bytes are from a BigEndian wav file. Does anybody know
> how to convert them to LittleEndian?
>
> Thanks a lot for help!
> Alex

I don't know much about endian-ness, but
http://www.cs.umass.edu/~verts/cs32/endian.html
tells me that bytes aren't either big or little endian.

However, longs (etc.) are supposed to be little endian on Wintel
(Windows/Intel).

http://www.xbeat.net/vbspeed/c_SwapEndian.htm
has functions to do endian conversions on longs.

HTH
Author
29 Aug 2010 8:38 AM
Alexandros Peropulous
Okay, thanks!
Author
29 Aug 2010 2:41 PM
Jim Mack
Alexandros Peropulous wrote:
> Hello!
> I have some bytes which are from a wav file.
> They are without a header.
> Normally, I simply add the header, the file size, and I am done, I
> have a complete wav file.
> But this time, my bytes are from a BigEndian wav file. Does anybody
> know how to convert them to LittleEndian?

The bytes themselves don't have endian-ness. If this is 8-bit data,
there's nothing to change. If the file contains 16-bit data, then the
two halves of the 16-bit words are in the opposite order they would
ordinarily be for an Intel platform.

I don't have the RIFF / WAV format handy, but I would think that
there's a flag somewhere in the header that indicates this is a
big-endian WAV file. In theory, then, you'd just have to change this
flag in your header.

If that's not the case then ask again and we can post code for
flipping the halves of 16-bit integers.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
29 Aug 2010 3:03 PM
Alexandros Peropulous
Hello Jim,

I can specifiy "RIFX" instead of "RIFF", but apisndplay won't play it at
all, and my audio editor asks me to specify the format, so I guess that
there is something wrong or RIFX is not supported under Windows (?).

It would be great if you could show me how to flip the halves of the
16-bit integers.
But I am still fighting with making longs from my bytes.

I imagined that I could do something like this

1) Get bytes as usual from the BigEndian source file
2) Convert bytes to longs
3) Flip them as you suggested
4) Put them into the new RIFF wave file

Is that possible or would I have to get the source bytes as longs
instead? That would be difficult for me right now...

Thank you!
Alex

Jim Mack wrote:
Show quoteHide quote
> Alexandros Peropulous wrote:
>> Hello!
>> I have some bytes which are from a wav file.
>> They are without a header.
>> Normally, I simply add the header, the file size, and I am done, I
>> have a complete wav file.
>> But this time, my bytes are from a BigEndian wav file. Does anybody
>> know how to convert them to LittleEndian?
>
> The bytes themselves don't have endian-ness. If this is 8-bit data,
> there's nothing to change. If the file contains 16-bit data, then the
> two halves of the 16-bit words are in the opposite order they would
> ordinarily be for an Intel platform.
>
> I don't have the RIFF / WAV format handy, but I would think that
> there's a flag somewhere in the header that indicates this is a
> big-endian WAV file. In theory, then, you'd just have to change this
> flag in your header.
>
> If that's not the case then ask again and we can post code for
> flipping the halves of 16-bit integers.
>
Author
29 Aug 2010 4:04 PM
Nobody
Show quote Hide quote
"Alexandros Peropulous" <perop***@gmail.com> wrote in message
news:%23da3Su4RLHA.3488@TK2MSFTNGP04.phx.gbl...
> Hello Jim,
>
> I can specifiy "RIFX" instead of "RIFF", but apisndplay won't play it at
> all, and my audio editor asks me to specify the format, so I guess that
> there is something wrong or RIFX is not supported under Windows (?).
>
> It would be great if you could show me how to flip the halves of the
> 16-bit integers.
> But I am still fighting with making longs from my bytes.
>
> I imagined that I could do something like this
>
> 1) Get bytes as usual from the BigEndian source file
> 2) Convert bytes to longs
> 3) Flip them as you suggested
> 4) Put them into the new RIFF wave file
>
> Is that possible or would I have to get the source bytes as longs instead?
> That would be difficult for me right now...

You need to determine the source format first, if it's 8-Bit, then do
nothing. If it's 16 or 32 Bits, then flip the order of bytes. Don't flip the
bits within the byte at all, regardless of format.

http://en.wikipedia.org/wiki/WAV
Author
29 Aug 2010 5:03 PM
Jim Mack
Alexandros Peropulous wrote:
> Hello Jim,
>
> I can specifiy "RIFX" instead of "RIFF", but apisndplay won't play
> it at all, and my audio editor asks me to specify the format, so I
> guess that there is something wrong or RIFX is not supported under
> Windows (?).

I don't have any experience playing RIFX files under Windows -- but
you are aware that ALL values in the file are big-endian, right?
Including the chunk sizes etc. So your header would have to account
for that. Whether such a file plays OK would depend on the
application.


> It would be great if you could show me how to flip the halves
> of the 16-bit integers.
> But I am still fighting with making longs from my bytes.

Why do you need to make longs?

  Dim bTmp as Byte
  Dim hFil As Long
  Dim Byts() As Byte

  hFil = FreeFile
  Open MyFlippedData For Binary As hFil

  Get #hFil, , Byts

  For Idx = 0 to UBound(Byts) Step 2
    bTmp = Byts(Idx + 1)
    Byts(Idx + 1) = Byts(Idx)
    Byts(Idx) = bTmp
  Next

  Put #hFil, 1, Byts

  Close #hFil

Or you could write it back as a different file. Either way, the core
idea is in the For loop and you can adapt it as you like.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
29 Aug 2010 5:48 PM
Alexandros Peropulous
Supercool, thank you!!
Author
29 Aug 2010 5:19 PM
Kevin Provance
"Alexandros Peropulous" <perop***@gmail.com> wrote in message
news:%23da3Su4RLHA.3488@TK2MSFTNGP04.phx.gbl...
: I can specifiy "RIFX" instead of "RIFF", but apisndplay won't play it at
: all, and my audio editor asks me to specify the format, so I guess that
: there is something wrong or RIFX is not supported under Windows (?).

How exactly are you specifying this change?