How can I put a full length song (3-4 Minutes) in a game. Please list the code needed and the headers that I need to add. Thank You Very Much!
How can I put a full length song (3-4 Minutes) in a game. Please list the code needed and the headers that I need to add. Thank You Very Much!
Eh?
There is [I presume] no difference between playing a 2 second, 20 second or 3-4 minute .WAV file.
Perhaps this article will explain what you need to do:
http://www.microsoft.com/msj/0698/sound/sound.aspx
This assumes you are using Windows. If you are using Linux/Unix to write your game, I can't help, and you'll need to explain this to us.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks for the response, but I was looking for something more like the playsound function.
Thanks
And why do you think you can't use the PlaySound function in the first place - the above was just what I found when searching for "Play DirectSound" - if you are not using DirectSound bur prefer to use the multimedia functions, then I don't see a problem with that.
So, what is it you are after, a full example version of PlaySound?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks, I have looked on the internet and I have been unable to figure out how to use playsound. I am looking for a example on how to use it. Im very confused on how to use playsound.
Thanks
So, why don't you post a small piece of the code you are working on, with suitable questions on the bits you don't understand/can't get to work.
It looks to me like the PlaySound is really simple to use - something like:
I haven't tried that, and of course, the "name" has to be a valid wave-file of some sort.Code:#include <Windows.h> int main() { TCHAR name = "c://blah.wav"; BOOL f; f = PlaySound(name, NULL, SND_FILENAME); if (!f) { printf("Error\n"); } return 0; }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Here is the CodeThat was the best I could do (and it wont complile)Code:#include <iostream> #include <string> #include <windows> #include <cstdlib> #include <mmsystem.h> #pragma comment(lib,"Winmm.lib") using namespace std; int main() { cout << "Hello world" << endl; system ("PAUSE"); PlaySoundA("fanfare.wav", 0, SND_RESOURCE | SND_NODEFAULT); return 0; return 0; }
Thanks
What compiler errors do you get?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I updated to Visual 2008 and no longer get compiler erros. Unfortunately I am unable to hear the sound file. Please help. Thanks
Are you sure that the red code is correct?Code:PlaySoundA("fanfare.wav", 0, SND_RESOURCE | SND_NODEFAULT);
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
no. Do you know what the right code is? Thanks.
I thought "SND_FILENAME" would make more sense from the parameters you use - but I'm not sure at all.
I don't think "fanfare.wav" is a resource, but rather a filename.Originally Posted by MSDN
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Please explain by posting code. I do not understand. Thanks Very Much
For PlaySound(), there is a limit to the WAV file size. When I once tried to play a full song with PlaySound() I got an error.How can I put a full length song (3-4 Minutes) in a game.
MSDN says:I assume "available physical memory" depends on how much RAM you have, how much RAM is being used by Windows and other applications.... And maybe how much physical RAM Windows is willing to allocate to your program....Remarks
The sound specified by pszSound must fit into available physical memory and be playable by an installed waveform-audio device driver....
codeproject.com has a DirectSound example that can play a whole song.
You mean, my example that I posted earlier isn't good enough? It does exactly what I said you should change, using SND_FILENAME as the documentation says. I'm sorry, I'm not going to write the same thing again. Of course, you WILL have to change [or copy a file to match] blah.wav. But I think you are capable of that.
But since I wanted to make sure I wasn't telling porkies, I produced this, that runs on my machine:
Of course, I missed the note about the wav file fitting in memory, so if you want to play 4 minutes of 40 KHz samples, you are looking at needing 40MB or thereabouts. (40 KHz * 2 channels * 2 bytes per sampel * 240 seconds)Code:#include <windows.h> #include <stdio.h> int main(int argc, char **argv) { BOOL f; f = PlaySound("c:\\winnt\\media\\tada.wav", 0, SND_FILENAME); if (!f) printf("Error\n"); else printf("Done!\n"); return 0; }
--
Mats
Last edited by matsp; 10-29-2007 at 04:49 PM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.