🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
6 messages
6 total messages Started by Jeff Douglass Mon, 31 Mar 2003 19:12
PlaySound() API fuction control?
#17245
Author: Jeff Douglass
Date: Mon, 31 Mar 2003 19:12
15 lines
1795 bytes
I have a BCB 5 app that when a condition occures plays a .wav file every
second to notify the user that the condition has occured. It continues this
untill the user acknowledges the condition via a menu item. It is
implemented by placing the PlaySound() call inside the Ontimer event of a
TTimer componenet with the interval set to 1000. Easy enough. Here is the
problem. Sometimes, due to the app doing something else like loading a form
with data the trigger interval is inconsistant which results in the sound
getting played with a second and a half interval followed by a half second
interval. I am looking for a way to make the interval more reliable so no
mater what is going on the sound is played every second. I thought about
moving the PlaySound call to a seperate thread that has a higher priority
than the actual app, but wanted to get some feedback and other ideas from
other people. Thanks for any advice.

Jeff
Re: PlaySound() API fuction control?
#17246
Author: Remy Lebeau (TeamB)
Date: Mon, 31 Mar 2003 19:49
20 lines
1821 bytes
"Jeff Douglass" <.> wrote in message
news:3e8894b1$1@newsgroups.borland.com...
> Here is the problem. Sometimes, due to the app doing something
> else like loading a form with data the trigger interval is inconsistant
> which results in the sound getting played with a second and a half
> interval followed by a half second interval.

TTimer uses the WM_TIMER message and as such is directly tied to the
application's message queue.  Anything that delays processing of messages is
going to effect the timer.

You don't need a timer at all, though.  PlaySound() supports looping sounds.
Simply pass the SND_ASYNC and SND_LOOP flags when calling PlaySound() the
first time, and then pass NULL as the pszSound parameter a second time to
stop the playing.  You don't need to keep calling PlaySound() repeatedly
over and over manually.


Gambit
Re: PlaySound() API fuction control?
#17249
Author: Jeff Douglass
Date: Mon, 31 Mar 2003 20:20
9 lines
1179 bytes
Thanks, but the problem with the LOOP method is that the sound is
continuous. What I want is
BEEP 1 sec of no sound BEEP 1 sec of no sound ...........

Not a continuous BEEEEEEEEEEEEEEEEEEEEEP.

Make sense?

Thanks
Re: PlaySound() API fuction control?
#17250
Author: Remy Lebeau (TeamB)
Date: Mon, 31 Mar 2003 20:50
21 lines
1900 bytes
The sound is not continous.  It is played over and over from start to end
each time.  If you're getting continuous sound, then your sound itself
doesn't have any pauses in it.  Try making a sound that has a 1 second pause
at the end.  The LOOP will do what you ask while still not requiring any
timer.

The alternative is as you already know - just make a separate thread, have
it call PlaySound() in a while(!Terminated) loop with the SYNC flag instead,
and then Sleep() for 1000 milliseconds between callings.  You don't need to
adjust the thread priority, though.


Gambit

"Jeff Douglass" <.> wrote in message
news:3e88a4af$1@newsgroups.borland.com...
> Thanks, but the problem with the LOOP method is that
> the sound is continuous. What I want is BEEP 1 sec of
> no sound BEEP 1 sec of no sound ...........
>
> Not a continuous BEEEEEEEEEEEEEEEEEEEEEP.
Re: PlaySound() API fuction control?
#17251
Author: Jeff Douglass
Date: Mon, 31 Mar 2003 21:14
5 lines
1291 bytes
Thanks. Yea, I thought of the adding a pause to the actual sound file but
since the users can set their own sound I did not want them to have to deal
with this so I figured that the seperate thread idea was more robust.

Thanks again.
Re: PlaySound() API fuction control?
#17254
Author: Rodolfo Frino - Stargate Softwar...
Date: Tue, 01 Apr 2003 00:17
50 lines
2734 bytes
You could define a new constant such as SND_NODEFAULT_AND_SILENCE
whose value is not used by any of the existing constants (fdwSound)
and play your sound and then a Silence_1S.wav file which would be a silence
"sound". Then you could loop to get the BEEP-1S Silence- BEEP 1S
Silence -...

bool Play_Sound(LPCSTR FileName, DWORD PlayMode)
{
    switch(PlayMode)
    {
        case SND_APPLICATION:
             // The sound is played using an the sound associated with
             // the application.
             return PlaySound(FileName, NULL, SND_APPLICATION);

        case SND_SYNC:
             // Return after finishing playing the sound.
             return PlaySound(FileName, NULL, SND_SYNC);

        case SND_ASYNC:
             // Return immediately after beginning playing the sound.
             return PlaySound(FileName, NULL, SND_ASYNC);

        case SND_LOOP:
             // Play sound repeatedly.
             return PlaySound(FileName, NULL, SND_LOOP | SND_ASYNC);

        case SND_NODEFAULT:
             // If the sound cannot be found, PlaySound returns
             // without playing the default sound.
             return PlaySound(FileName, NULL, SND_NODEFAULT);

        case SND_NODEFAULT_AND_SILENCE:
             if (!PlaySound(FileName, NULL, SND_NODEFAULT))
                 return false;
                    // Play Silence_1S.wav Sound
             return Play_Sound("C:\\Directory\\Silence_1S.wav",
SND_NODEFAULT);

       default: // Error: Illegal Play Mode
             return false;
    }
}

Rodolfo

"Jeff Douglass" <.> wrote in message
news:3e8894b1$1@newsgroups.borland.com...
> I have a BCB 5 app that when a condition occures plays a .wav file every
> second to notify the user that the condition has occured.
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