Sunday, November 27, 2022

🆕 _INITAUDIO and 🆕 _FINISHAUDIO and ❇ SOUND

The SOUND statement was previously totally synchronous (i.e the sound had to finish before the program would process any subsequent statements.)  This behaviour is now very different.  (see further below for how SOUND now behaves.)

Also, please refer to the Amazing Grace sample program (it uses all of these statements):


Documentation about _INITAUDIO, _FINISHAUDIO, and SOUND (it kind of ties everything together:

_INITAUDIO

Description:

The _INITAUDIO statement initialises the web audio api for subsequent calls to  and  statements.

Syntax

_INITAUDIO


_FINISHAUDIO

Description:

The _FINISHAUDIO statement delays further execution of the program (including end of the program) until all queued sounds have played. See the  statement for more info.

Syntax

_FINISHAUDIO


SOUND

Description:

SOUND plays a sound of a specified frequency for the specified duration (measured in "ticks").

  • NOTES
    • Sounds in a BASIC Anywhere Machine program will not happen unless the program console window has the "focus"
      • Program Execution Properties: Remove the checkbox on "Autostart this program?"
        • The program will not commence until the user clicks on the program console window
      • Recommended: consider calling the  statement at the beginning of your program
        • This will initialize (a one second delay) the web audio api such that the first instance of SOUND will sound correctly
    • Synchronous and asynchronous behaviour of the SOUND statement
      • A SOUND statement, vis-à-vis other statements in the program flow, is asynchronous: after a program executes a SOUND statement, the program does not wait for completion of the SOUND statement before executing the statements after the SOUND statement
      • A SOUND statement, vis-à-vis other SOUND statements in the program flow, is synchronous: if a previous SOUND statement is still being played, the current SOUND statement will wait for the previous SOUND statement to finish; all SOUND statements go into a queue, and each sound will only happen after the previous sound is done playing
      • Because sounds are asynchronous vis-à-vis the rest of a program, it is very possible for a program to end before all of the sounds in a sound queue are processed. If we want the sound queue to finish playing before program end (or before further program execution), call the  statement
    • To alter the waveform of sound, call the _SNDWAVE statement.

SOUND 0,0 will end any on-going sound.

Syntax

SOUND frequency!, ticks!







No comments:

Post a Comment

🖥 Flower Tesselation: Testing DRAW and recursive SUB's

This BAM program inspired by Richard Russell's "Flower-like tesselation" BBC BASIC program posted on Facebook . Created in ord...