| MD_SN76489 Library 0.1 Library for SN76489 sound generator

Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
MD_SN74689 Class Reference

`#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.

## Detailed Description

Core object for the MD_SN76489 library

## Member Enumeration Documentation

## ◆ noiseType_t

enum MD_SN74689::noiseType_t

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.

Enumerator
PERIODIC_0 | Periodic noise, output/512.
PERIODIC_1 | Periodic noise, output/1024.
PERIODIC_2 | Periodic noise, output/2048.
PERIODIC_3 | Periodic noise, output/(Channel 3 freq)
WHITE_0 | White noise, output/512.
WHITE_1 | White noise, output/1024.
WHITE_2 | White noise, output/2048.
WHITE_3 | White noise, output/(Channel 3 freq)

## Constructor & Destructor Documentation

## ◆ MD_SN74689()

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.

Parameters

  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::~MD_SN74689 | ( | void |  | ) |

Class Destructor.

Does the necessary to clean up once the object is no longer required.

## Member Function Documentation

## ◆ begin()

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.

## ◆ isIdle()

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).

Parameters

  chan | channel to check [0..MAX_CHANNELS-1]

Returns
  true if the channel is idle, false otherwise.

## ◆ noise()

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.

Parameters

  noise | one of the valid noise types in noiseType_t.
  shiftRate | modifies the sound output, one of the values [0..3] or NOISE_OFF.

## ◆ note()

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.

See also
  tone()

Parameters

  chan | channel number on which to play this note [0..MAX_CHANNELS-2].
  freq | frequency to play.

## ◆ 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.

## ◆ setADSR() [1/2]

bool MD_SN74689::setADSR | ( | adsrEnvelope_t * | padsr | ) |

Set the same ADSR envelope for all channels.

Sets the same ADSR envelope for all channels.

See also
  setADSR()

Parameters

  padsr | pointer to the ADSR structure to be used.

Returns
  true if all changes were possible, false otherwise.

## ◆ setADSR() [2/2]

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).

See also
  isIdle()

Parameters

  chan | channel number on which to play this note [0..MAX_CHANNELS-1].
  padsr | pointer to the ADSR structure to be used.

Returns
  true if the change was possible, false otherwise.

## ◆ setFrequency()

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.

See also
  setNoise()

Parameters

  chan | channel number on which to play this note [0..MAX_CHANNELS-2].
  freq | frequency to set for the specified channel.

## ◆ setNoise()

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.

Parameters

  noise | one of the valid noise types in noiseType_t.
  shiftRate | modifies the sound output, one of the values [0..3].

## ◆ setVolume() [1/2]

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].

Parameters

  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].

## ◆ setVolume() [2/2]

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].

Parameters

  v | volume to set for all channels in range [VOL_MIN..VOL_MAX].

## ◆ tone()

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.

See also
  note()

Parameters

  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]

The documentation for this class was generated from the following files:

- src/MD_SN76489.h
- src/MD_SN76489.cpp