WAV file question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gordon Burditt

    #16
    Re: WAV file question

    >oh, well yeah, .wav file are in little endian and im doing that on a[color=blue]
    >little-endian machine. so, if i compiled the same code on a Mac it
    >couldn't read a .wav file properly?[/color]

    Write your code properly to use Documented-endian (that is, the
    endianness specified in the document describing the file format)
    in the file, and write it so the Native-endian type does not matter.
    This often involves shifting and masking. It almost certainly does
    NOT involve using fread() to read binary data into a structure with
    multi-byte integers as elements, then using it without further
    adjustment. Oh, yes, you should also use the Documented integer
    size in the file, and write your code so the type used in your code
    is sufficient to hold that integer but won't break if the Native
    integer size is bigger.

    Gordon L. Burditt

    Comment

    • Michel Rouzic

      #17
      Re: WAV file question

      oh yeah sorry i didnt know about that google group reply thing.

      anyways, wow, how do you do then if on a mac you want to read a 32-bit
      ..wav file? i mean, not a long ago i read file byte per byte and then
      doing this like "x = 256*b + a" but when i wanted to read 32-bit .wav
      files, i didn't wanna program anything to read 4 bytes and them put
      them together into 32-bit floats cuz thats way to complicated (so i
      used fread to read floats). is it what mac programmers have to do
      (unless they use some library that does it)?

      Comment

      • Default User

        #18
        Re: WAV file question



        Michel Rouzic wrote:[color=blue]
        > oh yeah sorry i didnt know about that google group reply thing.[/color]

        So why then did you refuse to use in this post? Are you intentionally
        trying to annoy people?




        Brian

        Comment

        • Keith Thompson

          #19
          Re: WAV file question

          "Michel Rouzic" <Michel0528@yah oo.fr> writes:[color=blue]
          > oh yeah sorry i didnt know about that google group reply thing.[/color]

          And now you do, but you still don't provide any context in your
          followup. I don't think it's strictly necessary in this case, but
          it's polite to at least acknowedge whose article you're responding to.
          [color=blue]
          > anyways, wow, how do you do then if on a mac you want to read a 32-bit
          > .wav file? i mean, not a long ago i read file byte per byte and then
          > doing this like "x = 256*b + a" but when i wanted to read 32-bit .wav
          > files, i didn't wanna program anything to read 4 bytes and them put
          > them together into 32-bit floats cuz thats way to complicated (so i
          > used fread to read floats). is it what mac programmers have to do
          > (unless they use some library that does it)?[/color]

          Dealing with floating-point numbers in a binary file written on
          another platform is even trickier than dealing with integers. Most
          systems these days use the IEEE format, or something very similar, but
          there are still a number of other formats out there (Cray, IBM
          mainframe, VAX, etc.). If you know the format used in the file, you
          can write portable code that will extract the fields and
          mathematically construct a floating-point value, though possibly with
          some loss of range and/or precision.

          I'm actually a bit surprised that the WAV format doesn't use just
          integers. (One web page I just read didn't say anything about
          floating-point, but another did mention it). The format specification
          should tell you exactly how the values are represented in the file.
          Extracting the information is left as an exercise.

          I'm sure that plenty of code has already been written to do this.
          Finding it is also left as an exercise.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
          We must do something. This is something. Therefore, we must do this.

          Comment

          • Erik de Castro Lopo

            #20
            Re: WAV file question

            Keith Thompson wrote:[color=blue]
            >
            > Dealing with floating-point numbers in a binary file written on
            > another platform is even trickier than dealing with integers.[/color]

            Yes, and libsndfile ( http://www.mega-nerd.com/libsndfile )
            handles floating point data in WAV, AIFF, AU and a number of
            other file formats correctly, regardless of whether your are
            on Win32, MacOSX or Linux/Unix.
            [color=blue]
            > I'm sure that plenty of code has already been written to do this.
            > Finding it is also left as an exercise.[/color]

            In case you missed it:



            Released under the LGPL so you can even use it in commercial
            apps. Runs on WIn32, MacOS and Linux.

            Erik
            --
            +-----------------------------------------------------------+
            Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid)
            +-----------------------------------------------------------+
            Learning Linux is like joining a cult. Sure it's fun at first but
            you waste time, become brainwashed, and then have to be de-programmed
            by Bill Gates before you can work for Him again.
            - Ray Lopez, in UFhK4.33289$y4. 1192894@newsrea d1.prod.itd.ear thlink.net

            Comment

            • Michel Rouzic

              #21
              Re: WAV file question



              Default User wrote:[color=blue]
              > Michel Rouzic wrote:[color=green]
              > > oh yeah sorry i didnt know about that google group reply thing.[/color]
              >
              > So why then did you refuse to use in this post? Are you intentionally
              > trying to annoy people?
              >
              >
              >
              >
              > Brian[/color]

              no, i didnt understand yet that it was about quoting

              Comment

              • Default User

                #22
                Re: WAV file question



                Michel Rouzic wrote:[color=blue]
                > Default User wrote:[/color]
                [color=blue][color=green]
                > > So why then did you refuse to use in this post? Are you intentionally
                > > trying to annoy people?[/color][/color]
                [color=blue]
                > no, i didnt understand yet that it was about quoting.[/color]


                I see. Keith gave pretty thorough instructions as to what the problem
                was and the solution. However, it seems like you understand now, so you
                should be in good shape from now on.



                Brian

                Comment

                Working...