PlaySound() in Windows
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
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]
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]
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]
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]
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.
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.
quote:Original post by PoontardisOriginal 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!!
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.
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.
quote:Original post by niyawOriginal 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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement