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!
Printable View
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!
> 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.
fopen, fclose, fread, fscanf, fgets, fwrite, fprintf, ...
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.
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. )
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).
That is C, I don't think it would work in my compilier.
> 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?
C++*. Mistyped it. The function on the page was C++.
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.
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.
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.
> 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.