Thread: How To open wav file with c

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    5

    Unhappy How To open wav file with c

    i get task form my lecturer to open wav file with c (borland C 3.1)....
    can you tell me how to do that....
    thanks.....

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    FILE * f = fopen("wav_file.wav", "r");
    Probably not what you want. More information on exactly what you want pleez.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could use a windows function to do so, but not with Borland C 3.1. At least, I don't think so.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    I got task for you to ask your lecturer why he's still teaching with stone-age tools.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Hey guys, i've got a related question here too.. is it possible to play a raw wav using just the standard libraries?? i think BASIC can do that using "beep" or "sound" command i think...

    so, is there a way to do that or do i need a whole lot of libraries and custom header files for that?
    It is not who I am inside but what I do that defines me.

  6. #6
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Quote Originally Posted by Salem
    I got task for you to ask your lecturer why he's still teaching with stone-age tools.
    Hey Mr. Salem, i dont mean any disrespect ok? my teacher also uses "antique" styles like "void main(void)" and compilers like "turbo C by borland". but since ur not from my place, and in no way can understand the situation which led to this little "breach of standards". Im also hesitant to "correct" my teacher in those aspects that you've already mentioned becoz im still learning the language.

    so, please dont judge me (and others like me) too harshly ok? thanks
    It is not who I am inside but what I do that defines me.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    It's your up-hill struggle, not mine.

    What are you going to do when you use a more modern compiler - re-learn the language from scratch - I've done it (sadly), and it sucks.
    If you thought learning C was hard, you should try unlearning a bunch of crap.

    Lemme guess, your OS is XP and you use Turbo C?
    Geez, get with the program, there are at least half a dozen FREE compilers which are readily available which wipe the floor with TC.

    Nobody outside your teacher uses that - any job you'll likely get will use something much more up to date.

    The only reason I can think of for teaching that old crap is that the teacher knows they don't have a clue about modern ANSI-C so they stick to what they know year after year after year after year after year after year after year after year after year after......

    Do you have to wait for them to all die off before you get an upgrade?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    hmmm, i can see your point crystal clear. but as i've said, im still a newbie: meaning i rely on my teacher and some occasional self-studies and helpful hints from the helpful people on the net to learn C. So, what im trying to do is this: learn the basics and the core in programming first, then learn the advanced thingys (differences in versions and OS's, new updates and features) later on. if i try to do both at the same time, i wont be able to master none.

    but about my question, which i will re-iterate:

    Hey guys, i've got a related question here too.. is it possible to play a raw wav using just the standard libraries?? i think BASIC can do that using "beep" or "sound" command i think...

    so, is there a way to do that or do i need a whole lot of libraries and custom header files for that?
    It is not who I am inside but what I do that defines me.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Standard C has no notion of sound or sound cards.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    but can C "receive" a wav stream (from an external source such as streaming on the net) and "write" it as a "filename.wav" file? im talking bout raw wav here, no compressions or codecs whatsoever..
    It is not who I am inside but what I do that defines me.

  11. #11
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by sangken
    but can C "receive" a wav stream (from an external source such as streaming on the net) and "write" it as a "filename.wav" file? im talking bout raw wav here, no compressions or codecs whatsoever..
    It most certainly can. You'll probably need to open the stream as a pipe (make first character of the filename a vertical bar, i.e. "|").

    And, btw, I agree with you that learning C is different from, and rather more important than, learning some specific implementation or environment.

    EDIT: now see what I've done, got all heated about the rubbish written about old compilers and written some rubbish myself about the question.

    Rather than the concept of a pipe, which would be appropriate for script languages like perl or korn shell, you are more likely to find what you want as far as reading streamed data if you investigate socket programming.
    Last edited by risby; 09-06-2006 at 08:00 AM.

  12. #12
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I think it's a trick question, and Tonto's solution is probably correct. He just asks you to open it, right? He doesn't ask you to play it? Unless he does ... could you give the complete task so we can see if this is the case.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You might just have to open a file with fopen(), read every character in it, writing the characters to a new file. See getc(). The sample code in this FAQ might actually be part of what you need:
    Code:
    int c;
      
    while ((c = fgetc(fp)) != EOF)
    {
      putchar (c);
    }
    Just open the file pointer fp, and use putc() instead of putchar() so you can write to a file and not the screen.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    For your teacher....
    Q1: What is ANSI-C?
    Q2: Are you teaching ANSI-C?
    Q3: Why not when it's industry standard practice?

    I assume you're paying money for this course (one way or another), so you should be looking to get some value out of it in return.

    > but can C "receive" a wav stream (from an external source such as streaming on the net)
    You'll find it very hard to establish a network connection using that fossil compiler. Yet another reason to upgrade.

    If you have a WAV file already, then start with http://www.wotsit.org/ to learn about the file format.
    Then figure out whatever low-level API you might have to the actual sound card you have, which is compatible with the compiler you have (this won't be easy either).
    Then just open the file in binary mode (dead easy), and interpret the data (not so easy) and pass that onto your sound card (dead easy, if you've figured out all the other steps).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Salem
    Then just open the file in binary mode (dead easy), and interpret the data (not so easy) and pass that onto your sound card (dead easy, if you've figured out all the other steps).
    I don't know how it is in Windows, but in linux steps one and two are the easy part (as you can find the wav header information on the web). . . but step three is rough. Maybe Windows has an eaiser interface for sound cards than ALSA?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  2. Replies: 12
    Last Post: 03-10-2005, 07:48 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM