Play RAW data with playsound()?

Nov 21, 2009 at 4:12pm
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);

So is it possible?
Nov 21, 2009 at 6:05pm
There are a few problems with your question:

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 )
{
  static const char* 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?
Last edited on Nov 21, 2009 at 6:07pm
Nov 21, 2009 at 6:57pm
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?
Last edited on Nov 21, 2009 at 6:59pm
Nov 21, 2009 at 8:24pm
You can have a .wav as a resource in either your .exe or a separate .dll. All you need is a handle to the DLL.

PlaySound's documentation lays it out mostly:

http://msdn.microsoft.com/en-us/library/aa909766.aspx

It even links to a how-to for playing resource files:

http://msdn.microsoft.com/en-us/library/aa910369.aspx


1
2
3
4
5
6
7
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
     );
Nov 21, 2009 at 8:32pm
PlaySound(
MAKEINTRESOURCE( IDD_YOURWAVFILEASARESOURCE ),
mydll, // or NULL if resource is in the exe
SND_ASYNC | SND_RESOURCE
);

And how do you play it back?
Nov 21, 2009 at 10:32pm
errr... that is how you play it back
Last edited on Nov 21, 2009 at 10:32pm
Nov 22, 2009 at 7:58am
that just plays back the .wav file i have, if i delete the file then no more sound
Nov 22, 2009 at 11:48am
What compiler are you using?

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.
Nov 22, 2009 at 3:23pm
im using dev-c++,
Last edited on Nov 22, 2009 at 3:34pm
Nov 22, 2009 at 4:04pm
BUMP! Anyone? please!!!
Nov 22, 2009 at 5:18pm
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)
Nov 22, 2009 at 5:58pm
i HAVEN'T done anything yet, couse i dont even know where to start.
Nov 22, 2009 at 6:51pm
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.
Nov 22, 2009 at 6:58pm
how do i add the file as a resource?
Nov 22, 2009 at 7:29pm
I've never used Dev C++, so I can't say for sure.

Googling seems to suggest that you can add resource files (*.rc) to projects in Dev C++, but it doesn't offer any way to create *.rc files.

Googling for *.rc file edtiors turned up this link:

http://www.softrecipe.com/Software-Development/Editors-Tools/source_editor.html


Try making an .rc with that program, and adding the .wav to it.

Once you have the .rc, add it to your project in Dev-C++ (look in the menus for a "Add Resource File" option)
Topic archived. No new replies allowed.