The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: raleeper on May 16, 2007, 10:47:03 PM

Title: beep
Post by: raleeper on May 16, 2007, 10:47:03 PM
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.



Title: Re: beep
Post by: MichaelW on May 16, 2007, 10:51:49 PM
There is a working Win32 app that uses the system speaker here:

http://www.masm32.com/board/index.php?topic=1789.0

Title: Re: beep
Post by: raleeper on May 16, 2007, 11:27:59 PM
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.
Title: Re: beep
Post by: MichaelW on May 16, 2007, 11:42:19 PM
Short of a driver, I suspect there is no solution.
Title: Re: beep
Post by: raleeper on May 17, 2007, 01:19:25 AM
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?
Title: Re: beep
Post by: BogdanOntanu on May 17, 2007, 02:19:30 AM
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
Title: Re: beep
Post by: Ratch on May 17, 2007, 03:19:07 AM
raleeper,

     Perhaps a separate thread to do the Beep?  Ratch
Title: Re: beep
Post by: raleeper on May 17, 2007, 10:01:01 AM
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.
Title: Re: beep
Post by: P1 on May 17, 2007, 02:07:46 PM
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)
Title: Re: beep
Post by: 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.
Title: Re: beep
Post by: evlncrn8 on May 17, 2007, 10:40:50 PM
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...
Title: Re: beep
Post by: P1 on May 17, 2007, 11:51:35 PM
It's not hard to play a midi string.

Regards,  P1   :8)
Title: Re: beep
Post by: Mark Jones on June 08, 2009, 04:43:48 AM
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]
Title: Re: beep
Post by: dedndave on June 08, 2009, 04:50:33 AM
bad pun - lol  ::)
i wonder why
why it isn't supported i mean (not why is that a bad pun)
Title: Re: beep
Post by: BlackVortex on June 08, 2009, 05:37:58 PM
Maybe MS want to gradually phaze it out of existence. Does it work on Win7 32 ? 
Title: Re: beep
Post by: dedndave on June 08, 2009, 05:46:56 PM
i was thinking it may be more related to a hardware issue, somehow
Title: Re: beep
Post by: GregL on June 08, 2009, 11:57:36 PM
Beep works fine in x64, I just tried it.

They must be saying the sc config beep start= disabled command is not supported. ??




Title: Re: beep
Post by: Mark Jones on June 10, 2009, 02:43:09 AM
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.
Title: Re: beep
Post by: dedndave on June 10, 2009, 02:50:46 AM
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
Title: Re: beep
Post by: Mark Jones on June 10, 2009, 02:54:33 AM
That's a logical conclusion Dave, but this mainboard has a built-in piezo device. (And the function worked in XP x32 prior.) :wink
Title: Re: beep
Post by: dedndave on June 10, 2009, 03:02:33 AM
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
Title: Re: beep
Post by: GregL on June 10, 2009, 05:05:43 PM
Mark,

Windows 7 Beta x64.  I used Pelle's C and created an x64 executable.





Title: Re: beep
Post by: sinsi on June 11, 2009, 12:42:31 AM
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

Title: Re: beep
Post by: GregL on June 11, 2009, 01:15:30 AM
The beep came through the sound card on Windows 7 x64 too.

Title: Re: beep
Post by: ThexDarksider on June 11, 2009, 01:37:36 AM
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.
Title: Re: beep
Post by: Mark Jones on June 11, 2009, 06:09:05 PM
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
Title: Re: beep
Post by: dedndave on June 11, 2009, 06:21:44 PM
so, their solution is to change the documentation rather than releasing a hotfix
talk about friggen lazy
Title: Re: beep
Post by: GregL on June 11, 2009, 09:39:05 PM
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.

Title: Re: beep
Post by: BlackVortex on June 11, 2009, 09:41:47 PM
That's great news !  The beep will live on !!

(http://www.freesmileys.org/emoticons/tuzki-bunnys/tuzki-bunny-emoticon-018.gif)