|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
BigEndian wav bytesHello!
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 Alexandros Peropulous wrote:
> Hello! I don't know much about endian-ness, but> 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 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 Alexandros Peropulous wrote:
> Hello! The bytes themselves don't have endian-ness. If this is 8-bit data,> 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? 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. 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. >
Show quote
Hide quote
"Alexandros Peropulous" <perop***@gmail.com> wrote in message You need to determine the source format first, if it's 8-Bit, then do 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... 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 Alexandros Peropulous wrote:
> Hello Jim, I don't have any experience playing RIFX files under Windows -- but> > 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 (?). 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 Why do you need to make longs?> of the 16-bit integers. > But I am still fighting with making longs from my bytes. 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. "Alexandros Peropulous" <perop***@gmail.com> wrote in message How exactly are you specifying this change?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 (?). |
|||||||||||||||||||||||