News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

beep

Started by raleeper, May 16, 2007, 10:47:03 PM

Previous topic - Next topic

raleeper

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.




MichaelW

There is a working Win32 app that uses the system speaker here:

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

eschew obfuscation

raleeper

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.

MichaelW

Short of a driver, I suspect there is no solution.
eschew obfuscation

raleeper

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?

BogdanOntanu

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
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Ratch

raleeper,

     Perhaps a separate thread to do the Beep?  Ratch

raleeper

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.

P1

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)

Ehtyar

Provided your heart isn't set on using the PC speaker, MessageBeep should be perfect :)

Ehtyar.

evlncrn8

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...

P1

It's not hard to play a midi string.

Regards,  P1   :8)

Mark Jones

FYI, invoke Beep,nFrequency,nMillliseconds is no longer supported in 64-bit WinXP & Vista. How ironic that it "fails silently." :bg [size=0pt]Windows XP x64[/size]
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

dedndave

bad pun - lol  ::)
i wonder why
why it isn't supported i mean (not why is that a bad pun)

BlackVortex

Maybe MS want to gradually phaze it out of existence. Does it work on Win7 32 ?