Link to home
Start Free TrialLog in
Avatar of jrepetto
jrepetto

asked on

Emitting a beep on the internal speaker

Hi all,
I'm looking for a way to emit a beep on the internal speaker no matter
what the multimedia configuration is (sound card installed or not).
Under Windows NT, there is Beep() that does the job nicely, but under
Win95/98, it doesn't work the same.
Is there a way to achieve this on all Windows platforms?
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi jrepetto,

Try MessageBeep( -1 );

ZOPPO
Avatar of jrepetto
jrepetto

ASKER

Unfortunately, MessageBeep(-1) only produces a small click, not a beep ...

Jean-Claude
Beep(Tone, Length);
Tone is the number of hertz(what KIND of noise) and Length is how long you want it to play.  If the computer does NOT have a sound card, it does the standard beep.

~Aaron

The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes.

BOOL Beep( DWORD dwFreq,
 // sound frequency, in hertz
 
DWORD dwDuration
 // sound duration, in milliseconds
 
);
 


Parameters
dwFreq

Windows NT:

Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).

Windows 95:

The parameter is ignored.

dwDuration

Windows NT:

Specifies the duration, in milliseconds, of the sound.

Windows 95:

The parameter is ignored.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Windows 95:

The Beep function ignores the dwFreq and dwDuration parameters. On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.
Hey BudWeezer, re-read the question carefully:

>I'm looking for a way to emit a beep on the internal speaker no matter
>what the multimedia configuration is (sound card installed or not).

So, just a copy of MSDN description for Beep is not a solution!


jrepetto: Unfortunately I have neither Win9x nor a soundcard, so I think I can't help you out of this :(
I agree with Zoppo's comment. I am looking for a solution for Win95/98.

Jean-Claude
I have the same problem. The Microsofties seem to assume that each PC has a soundcard with connected speakers ...
Yes, but keep in mind, it WILL work for a computer with speakers or without.  I guess I don't understand why it must be on just the internal speaker...

~Aaron
oops, I meant sound card instead of speakers.  ;-)
what about
for j1 := 1 to 1000 do MessageBeep( $FFFFFFFF );

?

;-)

Alisher_N

who knows what MessageBeep() does in future versions of windows.
Maybe you get 1000 beeps ... 15 minutes beep beep beep beep ...
when working with windows you never know what will happen 'in next version', you even can not be sure 100% how it works in your current version ;-), if you want to have always_stable, always_clean, always_reliable code move to anoither OS ;-)))

I would tend to agree, I hear BeOS is going to be killer.  =)  I seem to recall something like SysBeep or something pretty close to it a LONG time ago...  One thing you might try is a LOW LEVEL beep, from assembly.  If there aren't any API to make the beep, ya get to do it yourself.  ;-P

~Aaron
maybe you can buy a ActiveX-Control from Micro$oft which beeps for you ...
: )
can you hear the correct beep when you do following:

open a dosbox and enter:
echo [CTRL-G][ENTER]

if so, you could write a char 0x07 to a console's standard output handle...

ZOPPO
In a dosbox, when I enter [CTRL-G] [ENTER], I get the message : Bad command or file name :-)

But if I fill the command line until the buffer overflow, I can hear the windows standard sound, like the Beep() function.

echo (followed by CTRL+G followed by ENTER)
Zoppo, I had a look at this a while ago and according to MS docs ascii 0x07 (amongst others) isn't a supported character *sigh*. I remember it used to work on Win 3.1 though....
It also works in NT console apps ...
This seems a little late to mention, but did you try the other MessageBeep() values that are possible?

MB_ICONASTERISK
MB_ICONEXCLAMATION
MB_ICONHAND
MB_ICONQUESTION
MB_OK ( <- system default )

You mentioned that you do get the normal beep through your speaker in some cases.  Those instances are probably the result of one of the above cases.

When it comes to versatility this excerpt from the MessageBeep reference says it all:
"If it cannot play the specified alert sound, MessageBeep attempts to play the system default sound. If it cannot play the system default sound, the function produces a standard beep sound through the computer speaker."

The reference does mention that:
"The user can disable the warning beep by using the Control Panel Sound application."  So there's at least one "multimedia configuration" that you won't be able to handle.
'system default' is $FFFFFFFF or -1 we have discussed before....

And there was a reason I said use MessageBeep...so your answer is nothing new...

~Aaron
From win.h

#define MB_OK      0  // not 0xFFFFFFFF

Complete quote:

Value              Sound
0xFFFFFFFF      Standard beep using the computer speaker
MB_ICONASTERISK      SystemAsterisk
MB_ICONEXCLAMATION      SystemExclamation
MB_ICONHAND      SystemHand
MB_ICONQUESTION      SystemQuestion
MB_OK              SystemDefault

If he hasn't tried the other options then there is something new.

Adjusted points to 200
I think you didn't understand exactly what I want to do. There are lots of PCs with sound cards but no loudspeakers connected to them. That is why I want to send a beep to the internal loudspeaker, even if there is a sound card installed.
Yeah, which MessageBeep does...  If there aren't any speakers attached to the computer, then it will send it to the internal speaker.  And I guess I still don't understand why you would always want it to go to the internal, even if there are external speakers.  Please, keep in mind, the answer you don't want to hear is still an answer, and we've had numerous people come up with the same thing for you...  I think you either get to use MessageBeep, or like I said earlier, come up with your own low level function that does it.  There aren't any more clear ways to do it...  Sorry!

~Aaron
BudWeezer wrote:
"If there aren't any speakers attached to the computer, then it will send it to the internal speaker".
I don't agree, since Windows doesn't know if there are external speakers attached or not ...

But I agree on your last sentence, I think there is no simple way to do that, except writing a low level function.
Windows does too know if there are speakers attached.  If there are speakers attached, the the multimedia functions will automatically take the information from the drivers to determine where to send the sound.  If there are external speakers plugged into the computer, then when the drivers send the request to the external speakers, the sound goes there.  If the request fails, then it defaults to the internal speaker.  If Windows didn't know the speakers were there, NO sound would go to the external speakers...  As for writing a low level functions, best of luck....well beyond my scope.  ;-)

~Aaron
hey, budweezer!
you are mixing 'sound card' and 'extrenal speakers' !
if you don't know the difference just post new question for.... let's say 200 points we are ready to explain that ;-))

hey Alisher_N, I DO know the difference between the two, but do YOU know how the one interfaces with the other?  ;-/  If you don't, I'll explain it to you for free.  Here's a hint, without the one, the other does work too well.  ;-)  And the neat thing is, one polls the status of the other, and when it doesn't find it, it will poll a different device, say possibly the internal speaker.  Hence the reason why MessageBeep will go with whatever happens to be around.  If you have a computer with external speakers, but you want all your beeps through the internal speaker, not only are you off your rocker, but you can specify it in the multimedia control panel under preferred device.  All that for free.  =P

~Aaron
I am talking about usual speakers, connected via 'Audio Out' socket on sound card (with a small round plug ;) and NONE of known to me sound cards can detect if SUCH speakers (or headphones) connected to sound card or no. The card just outputs the singnal, but can you hear it or no - it is problem of user.

yes, you can do whatever you want with multimedia configurations, but with sound cards, NOT with external speakers ;-//

if you are talking about some super-puper vacuum-proof advanced quadro Dolby-surround multimedia system connected via USB (or other proprietary interface of your particular sound card) wich costs $XXXX that might be a true, but I thought we are talking about average user here...

::grins::ya know what, I was wrong, and I admit it, and I sure shouldn't have been as cocky as I was.  Lack of sleep prohibited my brain from working properly, and I apologize.  But, assuming my brain has started up again(I'm still not sure it has), where would MessageBeep go wrong?  I guess I find it odd that a beep MUST go to an internal speaker if there are externals attached...  And now that I think about it, how WOULD MessageBeep know that no external is attached?  Ya know how it says if no external then will default to internal.  There MUST be a way of polling that little round plug.  ;-)  Ah well...I'll keep digging in my resources and see if I can't find something else.

~Aaron
;-))
....but you was so confident, that I even started to think that I probably behind the technical progress ;-)

ok, it happens...

ASKER CERTIFIED SOLUTION
Avatar of Faustic
Faustic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial