The Beep function generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes. - from the SDK.
I want an asynchronous function.
This was easy in DOS because there were separate io commands to turn the tone on and off - you could turn it on, then hook the timer tick interrupt to turn it off if enough time had elapsed.
Does anyone know a way to do this from inside a windows program?
MessageBeep is asynchronous but is unsuitable for several reasons.
There is a working Win32 app that uses the system speaker here:
http://www.masm32.com/board/index.php?topic=1789.0
MichaelW: "There is a working Win32 app that uses the system speaker here:
http://www.masm32.com/board/index.php?topic=1789.0"
Neat program.
But since it's built on beep, it doesn't suggest a solution to the synchronous problem.
Short of a driver, I suspect there is no solution.
MichaelW: "Short of a driver, I suspect there is no solution."
XPs dos emulator works OK for this, but is there a way to call a dos program [command shell or some such] from within a windows program?
In Windows the corect solution for this is to use DirectX / DirectSound:
- Create a directSound Object
- create primary buffer and a secondary buffer
- fill the secondary buffer with the desired sound data
- setup a callback notification at the end of secondary buffer
- start the Play of the secondary buffer
... zzz ...
perform other actions asynchronously
... zzz ...
- you should receive the notification callback when the sound is over
- create a new sound and/or stop playing
Of course this will not use the "speaker/beeper". Instead it will use the audio hardware / sound board of the PC
raleeper,
Perhaps a separate thread to do the Beep? Ratch
Thanks for all the suggestions.
I've decided to live with the delay for now, but I've filed all the messages for future reference.
Sound is a subsystem on XP. All it takes is a high priorty thread to start the sound event, after that the cpu is free, because the sub-processor on the sound system will execute the sound event independent of the OS, unless something clears or cancels the sound system sound event.
AFAIK, It should be doable.
Regards, P1 :8)
Provided your heart isn't set on using the PC speaker, MessageBeep should be perfect :)
Ehtyar.
Quote from: Ehtyar on May 17, 2007, 09:42:31 PM
Provided your heart isn't set on using the PC speaker, MessageBeep should be perfect :)
Ehtyar.
messagebeep doesnt allow variable tones though...
best approach would be to make a 'script' for the tones, and execute a seperate thread to run from the script in a loop doing the beep stuff, then exiting... you could then also include mutex/semaphore/event to pause the thread (or even use suspendthread) if needed...
It's not hard to play a midi string.
Regards, P1 :8)
FYI, invoke Beep,nFrequency,nMillliseconds is no longer supported in 64-bit WinXP & Vista (http://msdn.microsoft.com/en-us/library/ms679277(VS.85).aspx). How ironic that it "fails silently." :bg [size=0pt]Windows XP x64[/size]
bad pun - lol ::)
i wonder why
why it isn't supported i mean (not why is that a bad pun)
Maybe MS want to gradually phaze it out of existence. Does it work on Win7 32 ?
i was thinking it may be more related to a hardware issue, somehow
Beep works fine in x64, I just tried it.
They must be saying the sc config beep start= disabled command is not supported. ??
Which x64? I'm using XP Pro x64, and Beep() definitely is not working. The driver is apparently there and started (Beep.sys), but calling the function makes no sound.
i don't mean this as an insult, Mark
are the speaker wires connected ?
the reason i say that is, it seems to me that if the OS did not support the function, it would burp at you and say so
That's a logical conclusion Dave, but this mainboard has a built-in piezo device. (And the function worked in XP x32 prior.) :wink
ok - just checkin - lol
i was trying to figure out what is different about your machine that makes it nonfunctional
wires are a good place to start (you be surprised how many "no sound" problems are related to wiring)
because these newer OS's don't allow direct i/o with hardware, it makes it harder to troubleshoot
but, isolating the problem is a little like playing sherlock holmes
when you have excluded the impossible, whatever remains, however improbable, must be the truth
Mark,
Windows 7 Beta x64. I used Pelle's C and created an x64 executable.
32-bit code in 64-bit Windows 7 works too - the beep comes through the soundcard
include \masm32\include\masm32rt.inc
.code
start:
invoke Beep,750,300
exit
end start
The beep came through the sound card on Windows 7 x64 too.
I remember something when I was coding in basic in 3rd grade, when I had win98 the PC speaker worked fine, however with XP (x32) needed an additional .sys file that was included within the installation. Maybe you need something similar here. :toothy I'm not really sure about that, it was 5 years ago lol.
Under device manager, hidden devices, there is a Beep driver, enabled, started, in both x32 and x64 WinXP, however no sound is coming from the latter.
This is not an isolated incident:
https://forums.codegear.com/thread.jspa?threadID=14706 <--- no solution
http://forums.silverfrost.com/viewtopic.php?t=1234 <--- no solution
http://www.autohotkey.com/forum/topic44614.html <--- no solution
http://www.eggheadcafe.com/forumarchives/NETvc/Jul2005/post23278925.asp <--- no solution
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=356978 <--- solution: not supported.
This was meant to be informative, not a question. :wink
so, their solution is to change the documentation rather than releasing a hotfix
talk about friggen lazy
After reading those links Mark posted, it looks like it doesn't work on Vista x64 but does on Windows 7 x64. So ... they fixed it on Windows 7.
That's great news ! The beep will live on !!
(http://www.freesmileys.org/emoticons/tuzki-bunnys/tuzki-bunny-emoticon-018.gif)