Hey!
I wanted to ask, is it possible to use PlaySound() function with somehow stored in an integer 3-8 sec sound?
i mean it would be something like this, you use some sort of program that could take the .wav file, convert it to something like ("101010101000101010010101"),
you store it like this:
int wSound = "100101010010010100101010";
and you could play it using PlaySound something like this:
PlaySound(wSound,NULL,SND_FILENAME|SND_ASYNC);
OR:
PlaySound((1001010100001111011),NULL,SND_FILENAME|SND_ASYNC);
1) an integer cannot contain a string. int wSound = "11001001001" makes no sense.
2) a sound is much bigger than an individual integer (1 'int' is typically 4 bytes). Take a look at a 3 second .wav file once. You'll notice (depending on the quality/samplerate) it'll be over 100 KB. There's no way you'll fit all of that into a single integer... although you could fit it into a memory buffer.
However -- if I get what I think you mean... then what you want to do is possible. You're just going about it the wrong way.
You can certainly use an integer to index/reference a sound file. something like this could be easily put in a program:
1 2 3 4 5 6 7 8 9 10 11 12
void PlayMySound( int sound )
{
staticconstchar* soundfilenames[] = { "foo.wav", "bar.wav" };
PlaySound( soundfilenaes[sound], NULL, SND_FILENAME|SND_ASYNC );
}
int main()
{
PlayMySound(0); // plays "foo.wav"
PlayMySound(1); // plays "bar.wav"
}
EDIT: or maybe that's not what you mean? Are you looking to play a sound without using an external .wav file?
Yes, you were wrong. I know how to play .wav files using playsound(), or how to put them in a variable, i need to play it without an external .wav file. I know that an int cant contain a string, i just wrote fast so i did a mistake. Well i guess that a wav file wont fit into a variable, but isnt there a way to integrate it inside the main.exe that you compile, so that ther would be only the executable, not the executable and the sound.
Or is it possible to put it inside a dll or something, so that you couldn't listen to it without the program.
P.S.- is it possible to check if there's a file in the folder named example.txt, and if there isn't one it would return a false boolean?
HMODULE mydll = /*whatever function to load a DLL. I can't remember the name of it*/
PlaySound(
MAKEINTRESOURCE( IDD_YOURWAVFILEASARESOURCE ),
mydll, // or NULL if resource is in the exe
SND_ASYNC | SND_RESOURCE
);
If you're using VS, just add the .wav file as a resource, and #include resource.h. Once you do that, VS will compile the .wav file into the program (you'll notice your exe will get a lot bigger) and you should be able to play the sound without having the external wav file.
I tried googling for how-tos on resources in Dev-C++ but I haven't found anything substantial. It would help to have more information.
What are you trying?
- What steps did you take to add the .wav file as a resource?
- How did you name your resource?
- Does the .wav file appear anywhere among the files in your project in Dev C++?
- Does your exe jump up in file size when you compile? (your exe should be however big it was + the size of the .wav file at least)
1) Add the file to your project as a resource.
2) #include "resource.h" or whatever header file declares the resources identifiers
3) Call PlaySound with SND_RESOURCE as per my previous post.