Archived

This topic is now archived and is closed to further replies.

PlaySound() in Windows

This topic is 5403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I go about playing a wave file from memory? I am using PlaySound() with the winmm.lib and everytime I hit space to fire guns and have a sound play the game stops due to the PlaySound()? I am assuming its playing the wave from the harddrive? Is it even possible with that function or anyother way to load the wave file into memory so its faster? I am not using DirectX. Thanks

Share this post


Link to post
Share on other sites
Have a look on MSDN it'll tell you.
I can't remember the exact flags you need, but it'll be something like:

PlaySound(pWavBuffer, blah, ASYNC | MEMORY);

[edit] I looked it up for you:
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);

ps - I typed mdsn.microsoft.com into my web browser + then typed PlaySound into the search box...

[edited by - poontardis on March 3, 2003 3:37:01 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Poontardis
Have a look on MSDN it'll tell you.
I can't remember the exact flags you need, but it'll be something like:

PlaySound(pWavBuffer, blah, ASYNC | MEMORY);

[edit] I looked it up for you:
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);

ps - I typed mdsn.microsoft.com into my web browser + then typed PlaySound into the search box...

[edited by - poontardis on March 3, 2003 3:37:01 AM]


Ok, now from what I see of your example you must be using a function to load the .wav file into a memory location? What function is that? pWavbuffer neds to be a string. So when I change my flag to SND_MEMORY I get nothing? My other problem is how many sounds can be played at once with PlaySound()? I am making shootem up and I am seeing when I have my guns firing and explosions going only one plays at a time? Is their a limitation on PlaySOund()?




[edited by - Mars_999 on March 3, 2003 12:44:19 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by MARS_999
Original post by Poontardis
[edit] I looked it up for you:
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);

ps - I typed mdsn.microsoft.com into my web browser + then typed PlaySound into the search box...


Ok, now from what I see of your example you must be using a function to load the .wav file into a memory location? What function is that? pWavbuffer neds to be a string. So when I change my flag to SND_MEMORY I get nothing? My other problem is how many sounds can be played at once with PlaySound()? I am making shootem up and I am seeing when I have my guns firing and explosions going only one plays at a time? Is their a limitation on PlaySOund()?



Which part of the RTFM subtext didn't you catch onto?

Use fopen,fread,fclose to read the wav into memory.
And if you'd actually bothered to look it up on MDSN (I did only give you the web address after all so I suppose that's perfectly understandable) you would know that the first parameter can be a variety of things depending on the value of the third parameter. In this case the third parameter includes SND_MEMORY thus the first parameter will be a pointer to the memory location containing the read in wav.

For future reference:
PlaySound reference on MSDN

[edited by - poontardis on March 3, 2003 4:00:58 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don''t listen to this prick whose being a prick.

Just change SND_ASYNC to SND_SYNC and you''re done.

ASYNC waits for the wav to finish before running, and SND_SYNC does not.

Share this post


Link to post
Share on other sites
quote:
Original post by Poontardis
[quote]Original post by MARS_999
Original post by Poontardis
[edit] I looked it up for you:
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);

ps - I typed mdsn.microsoft.com into my web browser + then typed PlaySound into the search box...


Ok, now from what I see of your example you must be using a function to load the .wav file into a memory location? What function is that? pWavbuffer neds to be a string. So when I change my flag to SND_MEMORY I get nothing? My other problem is how many sounds can be played at once with PlaySound()? I am making shootem up and I am seeing when I have my guns firing and explosions going only one plays at a time? Is their a limitation on PlaySOund()?



Which part of the RTFM subtext didn''t you catch onto?

Use fopen,fread,fclose to read the wav into memory.
And if you''d actually bothered to look it up on MDSN (I did only give you the web address after all so I suppose that''s perfectly understandable) you would know that the first parameter can be a variety of things depending on the value of the third parameter. In this case the third parameter includes SND_MEMORY thus the first parameter will be a pointer to the memory location containing the read in wav.

For future reference:
PlaySound reference on MSDN

[edited by - poontardis on March 3, 2003 4:00:58 PM]


Well dumbass I don''t want to have to code a wav loader I asked if their is a function that windows has already like PlaySound() to load the wave into a resource so it can be in memory like textures and not stutter when I have 50 waves played at the same time or access the hard drive. Anyone else who isn''t illiterate I would welcome some help!!

Share this post


Link to post
Share on other sites
playsound supports at most one asynchnonous sound. the moment you start a second sound the first one stops playing, regardless of whether it''s finished or not. an easy way to get multiple sounds playing at the same time is to use mci if you want to go the windows way; it''s certainly easier than doing stuff with winmm.dll. using bass/fmod/other third-party library may also be easy.

Share this post


Link to post
Share on other sites
quote:
Original post by MARS_999
Well dumbass I don''t want to have to code a wav loader I asked if their is a function that windows has already like PlaySound() to load the wave into a resource so it can be in memory like textures and not stutter when I have 50 waves played at the same time or access the hard drive. Anyone else who isn''t illiterate I would welcome some help!!


throwing insults at people is a bad idea especially when said people answer your questions.
quote:
Original post by Poontardis
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);
...
Use fopen,fread,fclose to read the wav into memory.
...
And if you''d actually bothered to look it up on MDSN (I did only give you the web address after all so I suppose that''s perfectly understandable) you would know that the first parameter can be a variety of things depending on the value of the third parameter. In this case the third parameter includes SND_MEMORY thus the first parameter will be a pointer to the memory location containing the read in wav.


and the inevitable, i''m sure you were waiting for this: don''t act like a loser.

Share this post


Link to post
Share on other sites
quote:
Original post by niyaw
[quote]Original post by MARS_999
Well dumbass I don't want to have to code a wav loader I asked if their is a function that windows has already like PlaySound() to load the wave into a resource so it can be in memory like textures and not stutter when I have 50 waves played at the same time or access the hard drive. Anyone else who isn't illiterate I would welcome some help!!


throwing insults at people is a bad idea especially when said people answer your questions.
quote:
Original post by Poontardis
PlaySound(pWavBuffer, hModule, SND_ASYNC | SND_MEMORY);
...
Use fopen,fread,fclose to read the wav into memory.
...
And if you'd actually bothered to look it up on MDSN (I did only give you the web address after all so I suppose that's perfectly understandable) you would know that the first parameter can be a variety of things depending on the value of the third parameter. In this case the third parameter includes SND_MEMORY thus the first parameter will be a pointer to the memory location containing the read in wav.


and the inevitable, i'm sure you were waiting for this: don't act like a loser.

I guess you need to read the post closer. This was said before I made my reply.
quote:

Which part of the RTFM subtext didn't you catch onto?



So who is starting the agression? If I knew all this stuff I sure wouldn't be asking for help.



[edited by - Mars_999 on March 3, 2003 10:41:53 PM]

Share this post


Link to post
Share on other sites
erm, no. you posted a boatload of "what''s this? what''s that? what''s that other thing? and what''s this thing here? how about over here?" questions that show that you''ve made zero effort to find the information you were looking for. even then, you got a post giving you the outline of what to do, and you, in your infinite grace and wisdom, flamed the poster. i wouldn''t want to help you again if i was Poontardis. now, today i feel nice, which is why i answered this only valid question of yours:
quote:

Is their a limitation on PlaySOund()?


which can''t be easily answered from a google search.

might i suggest you stop digging deep holes for yourself?

Share this post


Link to post
Share on other sites
Hey Mars if u think u r so "smart" coming in here insulting people, u might as well just find the answers to ur questions urself, since no one appreciates that kind of attitude in here, besides u should be thankful that people even bother looking over the internet for information and stuff and post some replies, when u could have done it easily urself as niyaw pointed out.

Share this post


Link to post
Share on other sites
You two can say what you want I don't care for your attitudes at all and don't care for when I get told to read the FUCKING manual!! So if I got to be swore at to get a point across then back at you.

[edited by - Mars_999 on March 3, 2003 12:29:11 AM]

Share this post


Link to post
Share on other sites