Expand/Shrink

beep

The file builtins\beep.e (not an autoinclude) contains a single and (somewhat painfully) simple beep procedure.

include builtins\beep.e
beep(object frequency=440, duration=500, atom /*volume*/=1)

frequency can be an atom or a sequence of atoms, in Hz
duration can be an atom or a sequence of atoms, in milliseconds
When both are sequences, an error occurs if their lengths don’t match.
When frequency is an atom and duration is a sequence, even-indexed durations are silent.

The volume parameter does nothing on desktop/Phix, but under p2js it should be a floating point value between 0 (muted) and 1 (full)

This routine is fully supported by pwa/p2js. An equivalent is manually implemented in pwa\p2js.js: p2js.exw should cope, and not transpile the desktop\builtin version, even when it is explicitly included.

Note that a web browser will refuse permission to initiate a beep unless triggered by a user action such as clicking on a button.
Consequently you are unlikely to get anywhere under pwa/p2js unless pGUI is also included, or perhaps some other web-compatible UI lib, should another one have been created by the time you read this.

The noise generated, if not mercifully short, is generally rather unpleasant, but I suppose if you need to know something has crashed and needs attention while you’re in the kitchen, say, this’ll just about do.

examples:
demo\rosetta\Audio_frequency_generator.exw
demo\rosetta\Musical_scale.exw