![]() |
MD_SN76489 Library
0.1
Library for SN76489 sound generator
|
#include <MD_SN76489.h>
Classes | |
struct | adsrEnvelope_t |
Public Types | |
enum | noiseType_t { PERIODIC_0 = 0x0, PERIODIC_1 = 0x1, PERIODIC_2 = 0x2, PERIODIC_3 = 0x3, WHITE_0 = 0x4, WHITE_1 = 0x5, WHITE_2 = 0x6, WHITE_3 = 0x7 } |
Public Member Functions | |
MD_SN74689 (const uint8_t *D, uint8_t WE, bool clock) | |
~MD_SN74689 (void) | |
void | begin (void) |
Hardware control basics. | |
void | setVolume (uint8_t chan, uint8_t v) |
void | setVolume (uint8_t v) |
void | setFrequency (uint8_t chan, uint32_t freq) |
void | setNoise (noiseType_t noise, uint8_t shiftRate) |
Methods for notes and tones. | |
void | tone (uint8_t chan, uint32_t freq, uint8_t volume=VOL_MAX) |
void | note (uint8_t chan, uint32_t freq) |
void | noise (noiseType_t noise, uint8_t shiftRate) |
bool | setADSR (uint8_t chan, adsrEnvelope_t *padsr) |
bool | setADSR (adsrEnvelope_t *padsr) |
bool | isIdle (uint8_t chan) |
void | play (void) |
Static Public Attributes | |
static const uint8_t | MAX_CHANNELS = 4 |
Number of available sound channels. | |
static const uint8_t | NOISE_CHANNEL = 3 |
The channel for periodic/white noise. | |
static const uint8_t | NOISE_OFF = 0xf |
Convenience constant for NOISE_CHANNEL stop. | |
static const uint8_t | VOL_OFF = 0x0 |
Convenience constant for volume off. | |
static const uint8_t | VOL_MAX = 0xf |
Convenience constant for volume on. | |
Core object for the MD_SN76489 library
Noise type enumerated definitions The NOISE_CHANNEL can produce either white or periodic noise. This enumerated type is used to define the setting for the channel.
MD_SN74689::MD_SN74689 | ( | const uint8_t * | D, |
uint8_t | WE, | ||
bool | clock | ||
) |
Class Constructor.
Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware. Multiple instances may co-exist.
The D array is arranged to correspond to the IC pins (ie, pin D[0] is connected to IC pin D0, D[1] to D1, etc). D0 is the MSB in the data byte, D7 the LSB.
D | pointer to array of 8 pins number used to interface to IC pins D0 to D7 in that order. |
WE | pin number used as write enable for the IC |
clock | if true the 4MHz clock signal is generated using MCU timers (hardware dependency) |
MD_SN74689::~MD_SN74689 | ( | void | ) |
Class Destructor.
Does the necessary to clean up once the object is no longer required.
void MD_SN74689::begin | ( | void | ) |
Initialize the object.
Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.
The I/O pins are initialized and the 4MHz clock signal is started.
bool MD_SN74689::isIdle | ( | uint8_t | chan | ) |
Return the idle state of a channel.
Used to check if a channel is currently idle (ie, not playing a note).
chan | channel to check [0..MAX_CHANNELS-1] |
void MD_SN74689::noise | ( | noiseType_t | noise, |
uint8_t | shiftRate | ||
) |
Play a noise using ADSR.
Output a noise as specified on NOISE_CHANNEL, using the ADSR envelope curently defined for the channel. If another noise is playing on NOISE_CHANNEL it will be immediately replaced by the new noise.
If shiftRate is NOISE_OFF, the noise is turned off.
This method is ONLY supported by the NOISE_CHANNEL.
noise | one of the valid noise types in noiseType_t. |
shiftRate | modifies the sound output, one of the values [0..3] or NOISE_OFF. |
void MD_SN74689::note | ( | uint8_t | chan, |
uint32_t | freq | ||
) |
Play a note on using ADSR.
Output a sound with frequency freq on the specified channel using the ADSR envelope curently defined for the channel. If another note or tone is playing on the channel this will be immediately replaced by the new note.
If a freq is 0, the note is turned off.
This method is not supported by the NOISE_CHANNEL.
chan | channel number on which to play this note [0..MAX_CHANNELS-2]. |
freq | frequency to play. |
void MD_SN74689::play | ( | void | ) |
Play the music machine.
Runs the ADSR finite state machine for all channels. This should be called from the main loop() as frequently as possible to allow the library to execute the note required timing for the note envelopes.
bool MD_SN74689::setADSR | ( | adsrEnvelope_t * | padsr | ) |
Set the same ADSR envelope for all channels.
Sets the same ADSR envelope for all channels.
padsr | pointer to the ADSR structure to be used. |
bool MD_SN74689::setADSR | ( | uint8_t | chan, |
adsrEnvelope_t * | padsr | ||
) |
Set the ADSR envelope for a channel.
Sets the ADSR envelope for a channel. The envelope is defined in a structure of type adsrEnvelope_t. The envelope definition is not copied and must remain in scope while it is in use.
A null pointer changes the ADSR definition back to the library default. The ADSR profile cannot be changed while it is in use (ie, channel not idle).
chan | channel number on which to play this note [0..MAX_CHANNELS-1]. |
padsr | pointer to the ADSR structure to be used. |
void MD_SN74689::setFrequency | ( | uint8_t | chan, |
uint32_t | freq | ||
) |
Set the frequency for a channel.
Set the frequency output for a channel to be the value specified.
This method is not supported by the NOISE_CHANNEL.
chan | channel number on which to play this note [0..MAX_CHANNELS-2]. |
freq | frequency to set for the specified channel. |
void MD_SN74689::setNoise | ( | noiseType_t | noise, |
uint8_t | shiftRate | ||
) |
Set the noise channel parameters.
Set the noise parameters for NOISE_CHANNEL. This channel cannot play notes. Noise may be one of the noiseType_t types and the shift rate modifies the output of the select noise type.
New settings will immediately replace old settings for for NOISE_CHANNEL.
noise | one of the valid noise types in noiseType_t. |
shiftRate | modifies the sound output, one of the values [0..3]. |
void MD_SN74689::setVolume | ( | uint8_t | chan, |
uint8_t | v | ||
) |
Set the volume for a channel.
Set the volume for a channel to be the value specified. Valid values are all the values in the range [VOL_MIN..VOL_MAX].
chan | channel number on which to play this note [0..MAX_CHANNELS-1]. |
v | volume to set for the specificed channel in range [VOL_MIN..VOL_MAX]. |
void MD_SN74689::setVolume | ( | uint8_t | v | ) |
Set the volume for all channels.
Set the volume for all channels to be the speified value. Valid values are all the values in the range [VOL_MIN..VOL_MAX].
v | volume to set for all channels in range [VOL_MIN..VOL_MAX]. |
void MD_SN74689::tone | ( | uint8_t | chan, |
uint32_t | freq, | ||
uint8_t | volume = VOL_MAX |
||
) |
Play a tone without ADSR.
Output a sound with frequency freq on the specified channel. If another note or tone is playing on the channel this will be immediately replaced by the new tone.
If a freq is 0, the tone is turned off.
This method is not supported by the NOISE_CHANNEL.
chan | channel number on which to play this note [0..MAX_CHANNELS-1]. |
freq | frequency to play. |
volume | volume to play, default to VOL_MAX, in the range [0..VOL_MAX] |