Thread View: borland.public.cppbuilder.multimedia
7 messages
7 total messages
Started by Professor Chuck Kelly
Wed, 26 Mar 2003 23:35
PlaySound from memory is misbehaving
Author: Professor Chuck Kelly
Date: Wed, 26 Mar 2003 23:35
Date: Wed, 26 Mar 2003 23:35
37 lines
2057 bytes
2057 bytes
I am attempting to play several wav files from memory using PlaySound. Usually the first time I attempt to play the sounds I only hear the last sound. On some computers there is a random delay between playing each sound. Sometimes only the last sound plays.
I am using the following function to play the sounds:
void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
{
result = PlaySound(wavemem[waveIndex], NULL,
SND_ASYNC | SND_NOSTOP | SND_MEMORY);
}
The function is called as follows:
// attempt to play all 4 sounds asynchronously
void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
{
bool status;
playSoundMemAsync(0, status);
do{
playSoundMemAsync(1, status);
}while(status == false);
do{
playSoundMemAsync(2, status);
}while(status == false);
do{
playSoundMemAsync(3, status);
}while(status == false);
}
A complete program using the above functions is available at http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
Any suggestions would be appreciated.
Prof. Chuck Kelly
Monroe County Community College
Re: PlaySound from memory is misbehaving
Author: Marcelo R. Lopez, Jr.
Date: Tue, 15 Apr 2003 15:41
Date: Tue, 15 Apr 2003 15:41
56 lines
2967 bytes
2967 bytes
Chuck,
What leads you to believe that your target audio device can have more than
one MCI audio instance open at a time. Remember, DirectX's sound interface
is NOT like the MCI ( which is what PlaySound() uses ). You can only have
more than one audio instance open, IFF your device supports it ( many do
not ). If you need this sort of functionality, look around on the web, I
think there are a couple of ( at least semi ) freeware VCL's that will allow
you to open a DirectX sound device and play multiple streams.
Marcelo R. Lopez, Jr.
"Professor Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
news:3e823943$1@newsgroups.borland.com...
>
> I am attempting to play several wav files from memory using PlaySound.
Usually the first time I attempt to play the sounds I only hear the last
sound. On some computers there is a random delay between playing each sound.
Sometimes only the last sound plays.
>
> I am using the following function to play the sounds:
>
> void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
> {
> result = PlaySound(wavemem[waveIndex], NULL,
> SND_ASYNC | SND_NOSTOP | SND_MEMORY);
> }
>
> The function is called as follows:
>
> // attempt to play all 4 sounds asynchronously
> void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
> {
> bool status;
>
> playSoundMemAsync(0, status);
> do{
> playSoundMemAsync(1, status);
> }while(status == false);
> do{
> playSoundMemAsync(2, status);
> }while(status == false);
> do{
> playSoundMemAsync(3, status);
> }while(status == false);
>
> }
>
> A complete program using the above functions is available at
http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
>
> Any suggestions would be appreciated.
>
> Prof. Chuck Kelly
> Monroe County Community College
>
Re: PlaySound from memory is misbehaving
Author: Prof. Chuck Kelly
Date: Wed, 23 Apr 2003 21:14
Date: Wed, 23 Apr 2003 21:14
66 lines
3333 bytes
3333 bytes
I'm not trying to play the sounds simultaneously. I want to play them sequentially. According to the documentation on PlaySound the following code should return 'false' if a sound is currently being played but it should not stop the current sound.
result = PlaySound(wavemem[waveIndex], NULL,
SND_ASYNC | SND_NOSTOP |
"Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> wrote:
>Chuck,
>
>What leads you to believe that your target audio device can have more than
>one MCI audio instance open at a time. Remember, DirectX's sound interface
>is NOT like the MCI ( which is what PlaySound() uses ). You can only have
>more than one audio instance open, IFF your device supports it ( many do
>not ). If you need this sort of functionality, look around on the web, I
>think there are a couple of ( at least semi ) freeware VCL's that will allow
>you to open a DirectX sound device and play multiple streams.
>
>Marcelo R. Lopez, Jr.
>
>"Professor Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
>news:3e823943$1@newsgroups.borland.com...
>>
>> I am attempting to play several wav files from memory using PlaySound.
>Usually the first time I attempt to play the sounds I only hear the last
>sound. On some computers there is a random delay between playing each sound.
>Sometimes only the last sound plays.
>>
>> I am using the following function to play the sounds:
>>
>> void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
>> {
>> result = PlaySound(wavemem[waveIndex], NULL,
>> SND_ASYNC | SND_NOSTOP | SND_MEMORY);
>> }
>>
>> The function is called as follows:
>>
>> // attempt to play all 4 sounds asynchronously
>> void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
>> {
>> bool status;
>>
>> playSoundMemAsync(0, status);
>> do{
>> playSoundMemAsync(1, status);
>> }while(status == false);
>> do{
>> playSoundMemAsync(2, status);
>> }while(status == false);
>> do{
>> playSoundMemAsync(3, status);
>> }while(status == false);
>>
>> }
>>
>> A complete program using the above functions is available at
>http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
>>
>> Any suggestions would be appreciated.
>>
>> Prof. Chuck Kelly
>> Monroe County Community College
>>
>
>
Re: PlaySound from memory is misbehaving
Author: Marcelo R. Lopez, Jr.
Date: Tue, 29 Apr 2003 03:28
Date: Tue, 29 Apr 2003 03:28
83 lines
3945 bytes
3945 bytes
Chuck,
I agree with you that "in theory" the snippet of code that you're quoting,
shouldn't cause the sound to stop.
Just the same, Why is it that you are remiss with using the MCI and causing
the notifications from one to trigger playback of the next.
"Prof. Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
news:3ea70237$1@newsgroups.borland.com...
>
> I'm not trying to play the sounds simultaneously. I want to play them
sequentially. According to the documentation on PlaySound the following code
should return 'false' if a sound is currently being played but it should not
stop the current sound.
>
> result = PlaySound(wavemem[waveIndex], NULL,
> SND_ASYNC | SND_NOSTOP |
>
>
> "Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> wrote:
> >Chuck,
> >
> >What leads you to believe that your target audio device can have more
than
> >one MCI audio instance open at a time. Remember, DirectX's sound
interface
> >is NOT like the MCI ( which is what PlaySound() uses ). You can only have
> >more than one audio instance open, IFF your device supports it ( many do
> >not ). If you need this sort of functionality, look around on the web, I
> >think there are a couple of ( at least semi ) freeware VCL's that will
allow
> >you to open a DirectX sound device and play multiple streams.
> >
> >Marcelo R. Lopez, Jr.
> >
> >"Professor Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
> >news:3e823943$1@newsgroups.borland.com...
> >>
> >> I am attempting to play several wav files from memory using PlaySound.
> >Usually the first time I attempt to play the sounds I only hear the last
> >sound. On some computers there is a random delay between playing each
sound.
> >Sometimes only the last sound plays.
> >>
> >> I am using the following function to play the sounds:
> >>
> >> void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
> >> {
> >> result = PlaySound(wavemem[waveIndex], NULL,
> >> SND_ASYNC | SND_NOSTOP | SND_MEMORY);
> >> }
> >>
> >> The function is called as follows:
> >>
> >> // attempt to play all 4 sounds asynchronously
> >> void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
> >> {
> >> bool status;
> >>
> >> playSoundMemAsync(0, status);
> >> do{
> >> playSoundMemAsync(1, status);
> >> }while(status == false);
> >> do{
> >> playSoundMemAsync(2, status);
> >> }while(status == false);
> >> do{
> >> playSoundMemAsync(3, status);
> >> }while(status == false);
> >>
> >> }
> >>
> >> A complete program using the above functions is available at
> >http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
> >>
> >> Any suggestions would be appreciated.
> >>
> >> Prof. Chuck Kelly
> >> Monroe County Community College
> >>
> >
> >
>
Re: PlaySound from memory is misbehaving
Author: Prof. Chuck Kelly
Date: Tue, 29 Apr 2003 18:15
Date: Tue, 29 Apr 2003 18:15
96 lines
4506 bytes
4506 bytes
Marcelo,
First let me say I appreciate your help.
I do not want the program to require DirectX so that's out. I
want to be able to play sounds from memory. I don't want the program to wait for the sound to complete before continuing execution. The code which I have written works on most computers but not all. Do you have any suggestions.
Chuck
"Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> wrote:
>Chuck,
>
>I agree with you that "in theory" the snippet of code that you're quoting,
>shouldn't cause the sound to stop.
>Just the same, Why is it that you are remiss with using the MCI and causing
>the notifications from one to trigger playback of the next.
>
>"Prof. Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
>news:3ea70237$1@newsgroups.borland.com...
>>
>> I'm not trying to play the sounds simultaneously. I want to play them
>sequentially. According to the documentation on PlaySound the following code
>should return 'false' if a sound is currently being played but it should not
>stop the current sound.
>>
>> result = PlaySound(wavemem[waveIndex], NULL,
>> SND_ASYNC | SND_NOSTOP |
>>
>>
>> "Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> wrote:
>> >Chuck,
>> >
>> >What leads you to believe that your target audio device can have more
>than
>> >one MCI audio instance open at a time. Remember, DirectX's sound
>interface
>> >is NOT like the MCI ( which is what PlaySound() uses ). You can only have
>> >more than one audio instance open, IFF your device supports it ( many do
>> >not ). If you need this sort of functionality, look around on the web, I
>> >think there are a couple of ( at least semi ) freeware VCL's that will
>allow
>> >you to open a DirectX sound device and play multiple streams.
>> >
>> >Marcelo R. Lopez, Jr.
>> >
>> >"Professor Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
>> >news:3e823943$1@newsgroups.borland.com...
>> >>
>> >> I am attempting to play several wav files from memory using PlaySound.
>> >Usually the first time I attempt to play the sounds I only hear the last
>> >sound. On some computers there is a random delay between playing each
>sound.
>> >Sometimes only the last sound plays.
>> >>
>> >> I am using the following function to play the sounds:
>> >>
>> >> void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
>> >> {
>> >> result = PlaySound(wavemem[waveIndex], NULL,
>> >> SND_ASYNC | SND_NOSTOP | SND_MEMORY);
>> >> }
>> >>
>> >> The function is called as follows:
>> >>
>> >> // attempt to play all 4 sounds asynchronously
>> >> void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
>> >> {
>> >> bool status;
>> >>
>> >> playSoundMemAsync(0, status);
>> >> do{
>> >> playSoundMemAsync(1, status);
>> >> }while(status == false);
>> >> do{
>> >> playSoundMemAsync(2, status);
>> >> }while(status == false);
>> >> do{
>> >> playSoundMemAsync(3, status);
>> >> }while(status == false);
>> >>
>> >> }
>> >>
>> >> A complete program using the above functions is available at
>> >http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
>> >>
>> >> Any suggestions would be appreciated.
>> >>
>> >> Prof. Chuck Kelly
>> >> Monroe County Community College
>> >>
>> >
>> >
>>
>
>
Re: PlaySound from memory is misbehaving
Author: Ted Lyngmo
Date: Sat, 17 May 2003 11:32
Date: Sat, 17 May 2003 11:32
59 lines
2961 bytes
2961 bytes
Prof. Chuck Kelly wrote:
> Marcelo,
>
> First let me say I appreciate your help.
>
> I do not want the program to require DirectX so that's out. I
> want to be able to play sounds from memory. I don't want the program to
> wait for the sound to complete before continuing execution. The code
> which I have written works on most computers but not all.
> Do you have any suggestions.
You could always play the sound synchronically in a thread instead. I haven't
tested the code I've written, but you'll get the picture I think.
Kind regards,
Ted Lyngmo
#include <mmsystem.h>
#include <list>
using namespace std;
class WavePtrList : public list<char *> {
// extend the WavePtrList class here if you need it
};
class PlaySoundThread : public TThread {
private:
WavePtrList Waves;
public:
__fastcall PlaySoundThread() : TThread(true) {
// do any initialization here
}
__fastcall ~PlaySoundThread() {
Terminate();
PlaySound(NULL,NULL,SND_PURGE|SND_SYNC);
WaitFor();
}
void AddWave( char *Wave ) {
Waves.push_back(Wave);
if( Suspended ) Resume();
}
void RemoveWave( char *Wave ) {
Suspend();
Waves.remove(Wave);
if( Waves.size()!=0 ) Resume();
}
void __fastcall Execute() {
WavePtrList::iterator wav=Waves.begin();
while(!Terminated) {
PlaySound( *wav, NULL, SND_SYNC | SND_NOSTOP | SND_MEMORY );
if( ++wav == Waves.end() ) wav = Waves.begin();
}
}
};
--
Replace MY_FIRST_NAME in my email address with my first name to send a private
email to me.
Re: PlaySound from memory is misbehaving
Author: Alec Yu
Date: Sun, 09 Nov 2003 13:18
Date: Sun, 09 Nov 2003 13:18
67 lines
3151 bytes
3151 bytes
Excuse me, can you tell me where i can get VCL for DirectX controls?
Thanks
Alec
Marcelo R. Lopez, Jr. wrote:
> Chuck,
>
> What leads you to believe that your target audio device can have more than
> one MCI audio instance open at a time. Remember, DirectX's sound interface
> is NOT like the MCI ( which is what PlaySound() uses ). You can only have
> more than one audio instance open, IFF your device supports it ( many do
> not ). If you need this sort of functionality, look around on the web, I
> think there are a couple of ( at least semi ) freeware VCL's that will allow
> you to open a DirectX sound device and play multiple streams.
>
> Marcelo R. Lopez, Jr.
>
> "Professor Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
> news:3e823943$1@newsgroups.borland.com...
>
>>I am attempting to play several wav files from memory using PlaySound.
>
> Usually the first time I attempt to play the sounds I only hear the last
> sound. On some computers there is a random delay between playing each sound.
> Sometimes only the last sound plays.
>
>>I am using the following function to play the sounds:
>>
>>void __fastcall TForm1::playSoundMemAsync(int waveIndex, bool &result)
>>{
>> result = PlaySound(wavemem[waveIndex], NULL,
>> SND_ASYNC | SND_NOSTOP | SND_MEMORY);
>>}
>>
>>The function is called as follows:
>>
>>// attempt to play all 4 sounds asynchronously
>>void __fastcall TForm1::PlayAsyncClick(TObject *Sender)
>>{
>> bool status;
>>
>> playSoundMemAsync(0, status);
>> do{
>> playSoundMemAsync(1, status);
>> }while(status == false);
>> do{
>> playSoundMemAsync(2, status);
>> }while(status == false);
>> do{
>> playSoundMemAsync(3, status);
>> }while(status == false);
>>
>>}
>>
>>A complete program using the above functions is available at
>
> http://www.monroeccc.edu/ckelly/Files/SoundTest.zip
>
>>Any suggestions would be appreciated.
>>
>>Prof. Chuck Kelly
>>Monroe County Community College
>>
>
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads