MD_SN76489 Library  1.1
Library for SN76489 sound generator
Using the Library

Defining the object

The object definition include a list of all the I/O pins that are used to connect the MCU to the SN76489 IC.

setup()

The setup() function must include the begin() method. All the I/O pins are initialized at this time.

loop()

ADSR envelopes and/or automatic note off events (see below) are managed by the library. For this to happen in a timely manner, the loop() function must invoke play() every iteration through loop(). The play() method executes very quickly if the library has nothing to process, imposing minimal overheads on the user application.

Playing a Note

A note starts with the note on event and ends with a note off event. If an ADSR envelope is active, the Release phase starts at the note off event. The note on event is generated when the note(), tone() or noise() method is invoked in the application code.

Note On and Off Events

The library provides flexibility on how the note on and note off events are generated.

Invoking the tone(), note() or noise() methods without a duration parameter means the user code needs to generate the note off (this depends on the channel type and is explained in the specific method reference). This method is suited to applications that directly link a physical event to playing the note (eg, switch on for note on and switch off for note off), or where the music being played includes its own note on and off events (eg, a MIDI score).

Invoking the the tone(), note() or noise() methods with a duration parameter causes the library to generate a note off event at the end of the specified total duration. If an ADSR envelope is active, the note duration encompasses the time between initial Attack phase (note on) to the end of the Release phase (ie, the Sustain time is calculated from the given duration). This method suits applications where the sound duration is defined by the music being played (eg, RTTTL tunes). In this case the user code can determine if the sound has completed playing by using the isIdle() method.