Like Tree2Likes
  • 1 Post By Salem
  • 1 Post By stahta01

How do you handle sound and music files in C?

This is a discussion on How do you handle sound and music files in C? within the C Programming forums, part of the General Programming Boards category; I do not know any of the functions to do this, and when I looked on the internet all the ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    55

    How do you handle sound and music files in C?

    I do not know any of the functions to do this, and when I looked on the internet all the functions I saw were mainly non-standard. I would appreciate it if someone helped me find functions for this!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > when I looked on the internet all the functions I saw were mainly non-standard.
    All sound and music APIs are non-standard, so you need to say which OS/Compiler you're using if you want more specific advice.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    fopen, fclose, fread, fscanf, fgets, fwrite, fprintf, ...

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    333
    Quote Originally Posted by BatchProgrammer View Post
    I do not know any of the functions to do this, and when I looked on the internet all the functions I saw were mainly non-standard. I would appreciate it if someone helped me find functions for this!
    It's non-standard, and it's difficult to play audio. The speaker needs to be fed samples at a constant rate of 1 every 1/44,000 of a second. And the files are often big.
    So you usually have several layers or architecture, with a top-level "play", and lower-level tick functions that manage the flow of samples to buffers, mixers, secondary buffers, and finally the digital to analogue converter.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    55
    Os:

    Microsoft Windows [Version 6.1.7601] ( Windows 7, 64 bit, premium version )

    Compilier: Code::Blocks minGW minimalist package for windows, full version with plugins

    Also, does the C syntax have anyway to handle this then if there is no standard function for it? Or is it more nessecary to have unstandard libraries for such a task? ( I don't like using other people's code to write my programs. )

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    The simplest is probably this
    PlaySound function (Windows)

    But windows has several different audio / game / multimedia API's to choose from (and probably several 3rd party ones as well).
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    55
    That is C, I don't think it would work in my compilier.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > That is C, I don't think it would work in my compilier.
    Duh!?
    Why the ........ did you title your thread "How do you handle sound and music files in C?" then?
    loserone+_+ likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jan 2013
    Posts
    55
    C++*. Mistyped it. The function on the page was C++.

  10. #10
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    Guess what? You can use C in a C++ program.

    Sounds like you should spend some more time learning the language(s) before jumping into more complex things like sound and music.

  11. #11
    Registered User
    Join Date
    Jan 2013
    Posts
    55
    I know the C language and syntax, but I do not know C++. Yes, I'm aware that you can use C in C++. I have heard many times though that some C functions in C++ are not recommended for use in C++, not to mention that I've also heard that you have to do something different with the preprocessor directives.

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    2,778
    You do realize the examples on msdn.microsoft.com normally say C++; can work in most cases in both C and C++.

    This is because the API for MS Windows is almost (if not all) all written in C.

    Tim S.
    Salem likes this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > I have heard many times though that some C functions in C++ are not recommended for use in C++
    When you start seeing classes and namespaces in the API, then you know it's a C++ API.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Music in C++ and external files
    By yucaplan in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 12:00 PM
  2. Play music files in C#
    By redintegra in forum C# Programming
    Replies: 1
    Last Post: 04-08-2005, 10:57 AM
  3. Music and sound
    By Shadow12345 in forum Game Programming
    Replies: 7
    Last Post: 04-16-2003, 08:41 PM
  4. Music files to a program
    By y2jasontario in forum C Programming
    Replies: 9
    Last Post: 04-05-2002, 02:22 AM
  5. Can I Load A Sound or Music Into My Win32 Application ?
    By SonicWave in forum Windows Programming
    Replies: 8
    Last Post: 09-21-2001, 08:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21