Python: What Are the Nearest Linux and Osx Equivalents of Winsound.Beep

Beep with custom frequency and duration

On the Mac, the system alert sound is a sampled (prerecorded) sound that the user chooses. It often sounds nothing like a beep—it may be a honk, thunk, blare, or other sound that can't be as a simple constant waveform of fixed shape, frequency, and amplitude. It can even be a recording of the user's voice, or a clip from a TV show or movie or game or song.

It also does not need to be only a sound. One of the accessibility options is to flash the screen when an alert sound plays; this happens automatically when you play the alert sound (or a custom alert sound), but not when you play a sound through regular sound-playing APIs such as NSSound.

As such, there's no simple way to play a custom beep of a specified and constant shape, frequency, and amplitude. Any such beep would differ from the user's selected alert sound and may not be perceptible to the user at all.

To play the alert sound on the Mac, use NSBeep or the slightly more complicated AudioServicesPlayAlertSound. The latter allows you to use custom sounds, but even these must be prerecorded, or at least generated by your app in advance using more Core Audio code than is worth writing.

I recommend using NSBeep. It's one line of code to respect the user's choices.

Can the function Beep() from Win damage my Audio card?

Short answer - no. If the sound is not correct, it is probably down to the sound card driver or perhaps out-of-range parameters.

You have not revealed your input data, but very short time periods with rapidly changing frequencies is likely to be less than musical, and generate uncontrolled harmonics from incomplete cycles of the tone. This is especially true when the period is less than 1/F, but any abrupt frequency switch will introduce a discontinuity that will produce harmonics, and doing this rapidly will be clearly audible.

It seems that Beep() is clearly well defined to work with sound-cards since Windows 7 at least; prior to that it will have either not been supported, or will have driven the speaker directly from the timer chip.

From MSDN Beep documentation:

A long time ago, all PC computers shared a common 8254 programmable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.
On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep

sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.

Prevent 'not allowed' beep after keystroke in NSView

I think (but am not 100% certain, it's been a bit of time since I did this) you also need to override the NSView and/or NSResponder performKeyEquivalent: method. There, you'll return a YES to indicate to the caller that you did indeed handle the event.

And that will keep the "dooonk" sound from happening.

Play sound on internal speakers and possibility to use old xp api function?

No. The function is implemented in a Kernel32.dll, which is loaded at runtime from whatever version of the OS you're currently running. Since the code isn't there in either your executable or in a system DLL, you can't run it (don't even think about copying over Kernel32.dll from a different OS version, that's just screaming for trouble).

You can try using MessageBeep instead of Beep, but that gives you less control over the output and will probably still use your sound card instead of the internal

For an interesting history of the MessageBeep function, see Larry Osterman's blog.



Related Topics



Leave a reply



Submit