SID
Commodore 64 SID Library
Classes | Public Member Functions | List of all members
SIDVoice Class Reference

Public Member Functions

 SIDVoice (int address)
 
void setBase (int address)
 
void setNote (int note, boolean active)
 
void setFreq (int freq)
 
void setPWLo (byte dutyCycle)
 
void setPWHi (byte dutyCycle)
 
void setGate (boolean active)
 
void setSync (boolean active)
 
void setRingMod (boolean active)
 
void setTest (boolean active)
 
void setTriangle (boolean active)
 
void setSawtooth (boolean active)
 
void setSquare (boolean active)
 
void setSquare (boolean active, int pwm)
 
void setNoise (boolean active)
 
void setEnvelopeAttack (byte rate)
 
void setEnvelopeDecay (byte rate)
 
void setEnvelopeSustain (byte level)
 
void setEnvelopeRelease (byte rate)
 
void setInstrument (const char *name, byte attack, byte decay, byte sustain, byte release, bool noise, bool square, bool sawtooth, bool triangle, int pwm)
 
void loadInstrument (byte instrument)
 
void handleCC (byte number, byte value)
 
void reset ()
 
int getCurrentFreq ()
 

Member Function Documentation

int SIDVoice::getCurrentFreq ( )
Description
Return what the current frequency is set to.
Syntax
int frequency = sid.V1.getCurrentFreq()
Returns
the frequency of the voice (int)


void SIDVoice::reset ( )
Description
Reset a specific voice to zeroes.
Syntax
sid.V1.reset() sid.V2.reset() sid.V3.reset()
Parameters
none
Example
#include "SID.h"
SID sid;
void setup()
{
sid.V1.reset();
sid.V2.reset();
sid.V3.reset();
}
void loop() {}

void SIDVoice::setEnvelopeAttack ( byte  rate)
Description
Sets the Attack bits
Datasheet
From Datasheet
Select 1 of 16 ATTACK rates for the Voice 1 Envelope Generator. The ATTACK rate determines how rapidly the output of Voice 1 rises from zero to peak amplitude when the Envelope Generator is Gated. The 16 ATTACK rates are listed in Table 2 in the datasheet.
Syntax
sid.V1.setEnvelopeAttack(rate)
Parameters
rateAttack Rate as defined in datasheet


void SIDVoice::setEnvelopeDecay ( byte  rate)
Description
Sets the Decay bits
Datasheet
From Datasheet
Select 1 of 16 DECAY rates for the Envelope Generator. The DECAY cycle follows the ATTACK cycle and the DECAY rate determines how rapidly the output falls from the peak amplitude to the selected SUSTAIN level. The 16 DECAY rates are listed in Table 2 of the datasheet.
Syntax
sid.V1.setEnvelopeDecay(rate)
Parameters
rateDecay Rate as defined in datasheet


void SIDVoice::setEnvelopeRelease ( byte  rate)
Description
Sets the Release bits
Datasheet
From Datasheet
Select 1 of 16 RELEASE rates for the Envelope Generator. The RELEASE cycle follows the SUSTAIN cycle when the Gate bit is reset to zero. At this time, the output of Voice 1 will fall from the SUSTAIN amplitude to zero amplitude at the selected RELEASE rate. The 16 RELEASE rates are identical to the DECAY rates. NOTE: The cycling of the Envelope Generator can be altered at any point via the Gate bit. The Envelope Generator can be Gated and Released without restriction. For example, if the Gate bit is reset before the envelope has finished the ATTACK cycle, the RELEASE cycle will immediately begin, starting from whatever amplitude had been reached. If the envelope is then Gated again (before the RELEASE cycle has reached zero amplitude), another ATTACK cycle will begin, starting from whatever amplitude had been reached. This technique can be used to generate complex amplitude envelopes via real-time software control.
Syntax
sid.V1.setEnvelopeRelease(rate)
Parameters
rateRelease Rate as defined in datasheet


void SIDVoice::setEnvelopeSustain ( byte  level)
Description
Sets the Sustain bits
Datasheet
From Datasheet
Select 1 of 16 SUSTAIN levels for the Envelope Generator. The SUSTAIN cycle follows the DECAY cycle and the output of Voice 1 will remain at the selected SUSTAIN amplitude as long as the Gate bit remains set. The SUSTAIN levels range from zero to peak amplitude in 16 linear steps, with a SUSTAIN value of 0 selecting zero amplitude and a SUSTAIN value of 15 (#F) selecting the peak amplitude. A SUSTAIN value of 8 would cause Voice 1 to SUSTAIN at an amplitude one-half the peak amplitude reached by the ATTACK cycle.
Syntax
sid.V1.setEnvelopeSustain(level)
Parameters
levelSustain Level as defined in datasheet


void SIDVoice::setFreq ( int  freq)
Description
Set the frequency of the SID voice
Datasheet
From Datasheet
Together these registers form a 16-bit number which linearly controls the Frequency of Oscillator 1. The frequency is determined by the following equation: Fout = (Fn * Fclk/16777216) Hz Where Fn is the 16-bit number in the Frequency registers and Fclk is the system clock applied to the 2 input (pin 6). For a standard 1.0 Mhz clock, the frequency is given by: Fout = (Fn * 0.0596) Hz A complete table of values for generating 8 octaves of the equally-tempered musical scale with concert A (440 Hz) tuning is provided in Appendix A. It should be noted that the frequency resolution of SID is sufficient for any tuning scale and allows sweeping from note to note (portamento) with no discernible frequency steps.
Syntax
sid.V1.setFreq(freq)
sid.V2.setFreq(freq)
sid.V3.setFreq(freq)
Parameters
freqThe frequency to use, refer to the datasheet for the note equivalent
Example
#include "SID.h"
SID sid;
void setup()
{
sid.V1.setFreq(6207)
sid.V2.setFreq(6577)
sid.V3.setFreq(6968)
}
void loop() {}

void SIDVoice::setGate ( boolean  active)
Description
Control the voice gate
Datasheet
From Datasheet
The GATE bit controls the Envelope Generator for the Voice. When this bit is set to a one, the Envelope Generator is Gated (triggered) and the ATTACK/DECAY/SUSTAIN cycle is initiated. When the bit is reset to a zero, the RELEASE cycle begins. The Envelope Generator controls the amplitude of Oscillator 1 appearing at the audio output, therefore, the GATE bit must be set (along with suitable envelope parameters) for the selected output of Oscillator 1 to be audible. A detailed discussion of the Envelope Generator can be found in Appendix B.
Syntax
sid.V1.setGate(active)
Parameters
active1 to trigger the gate 0 to reset


void SIDVoice::setInstrument ( const char *  name,
byte  attack,
byte  decay,
byte  sustain,
byte  rel,
bool  noise,
bool  square,
bool  sawtooth,
bool  triangle,
int  pwm 
)
Description
Define an instrument for the Voice
Syntax
setInstrument(name, attack, decay, sustain, rel, noise, square, sawtooth, triangle, pwm)
Parameters
nameName of Instrument to be shown on LCD
attackAttack for instrument
decayDecay for instrument
sustainSustain for instrument
relRelease for instrument
noiseNoise bit for instrument
squareSquare bit for instrument
sawtoothSawtooth bit for instrument
triangleTriangle bit for instrument
pwmPWM value for instrument
Example
#include "SID.h"
SID sid;
void setup()
{
sid.V1.setInstrument("Calliope",0,0,15,0,0,0,0,1,0); //Calliope
sid.V2.setInstrument("Accordian",12,0,12,0,0,0,1,0,0); //Accordian
sid.V3.setInstrument("Harpsicord",0,9,0,0,0,1,0,0,512); //Harpsicord
}
void loop() {}

void SIDVoice::setNoise ( boolean  active)
Description
Sets the Noise bit of the control register
Datasheet
From Datasheet
When set to a one, the Noise output waveform of Oscillator 1 is selected. This output is a random signal which changes at the frequency of Oscillator 1. The sound quality can be varied from a low rumbling to hissing white noise via the Oscillator 1 Frequency registers. Noise is useful in creating explosions, gunshots, jet engines, wind, surf and other un-pitched sounds, as well as snare drums and cymbals. Sweeping the Oscillator frequency with Noise selected produces a dramatic rushing effect. One of the output waveforms must be selected for Oscillator 1 to be audible, however it is NOT necessary to deselect waveforms to silence the output of Voice 1. The amplitude of Voice 1 at the final output is a function of the Envelope Generator only. NOTE: The oscillator output waveforms are NOT additive. If more than one output waveform is selected simultaneously, the result will be a logical ANDing of the waveforms. Although this technique can be used to generate additional waveforms beyond the four listed above, it must be used with care. If any other waveform is selected while Noise is on, the Noise output can “lock up”. If this occurs, the Noise output will remain silent until reset by the TEST bit or by bringing /RES (pin 5) low.
Syntax
sid.V1.setNoise(active)
Parameters
active1 on 0 turns off


void SIDVoice::setNote ( int  note,
boolean  active 
)
Description
Set a voice to a MIDI Note
Syntax
sid.V1.setNote(note, active)
sid.V2.setNote(note, active)
sid.V3.setNote(note, active)
Parameters
noteThe MIDI note to use
activeWhether to activate the gate and play the note. 1 plays the note 0 does not
Example
#include "SID.h"
SID sid;
void setup()
{
sid.V1.setNote(51, 1)
sid.V2.setNote(52, 1)
sid.V3.setNote(53, 1)
}
void loop() {}

void SIDVoice::setPWHi ( byte  dutyCycle)
Description
Sets the high register PW Register
Datasheet
From Datasheet
Together these registers form a 12-bit number (bits 4-7 of PW Hi are not used) which linearly controls the Pulse Width (duty cycle) of the Pulse waveform on Oscillator 1. The pulse width is determined by the following equation: PWout = (PWn/40.95) % Where PWn is the 12-bit number in the Pulse Width registers. The pulse width resolution allows the width to be smoothly swept with no discernible stepping. Note that the Pulse waveform on Oscillator 1 must be selected in order for the Pulse Width registers to have any audible effect. A value of 0 or 4095 ($FFF) in the Pulse Width registers will produce a constant DC output, while a value of 2048 ($800) will produce a square wave.
Syntax
sid.V1.setPWHi(dutyCycle)
Parameters
dutyCyclePulse Width


void SIDVoice::setPWLo ( byte  dutyCycle)
Description
Sets the low register PW Register
Datasheet
From Datasheet
Together these registers form a 12-bit number (bits 4-7 of PW Hi are not used) which linearly controls the Pulse Width (duty cycle) of the Pulse waveform on Oscillator 1. The pulse width is determined by the following equation: PWout = (PWn/40.95) % Where PWn is the 12-bit number in the Pulse Width registers. The pulse width resolution allows the width to be smoothly swept with no discernible stepping. Note that the Pulse waveform on Oscillator 1 must be selected in order for the Pulse Width registers to have any audible effect. A value of 0 or 4095 ($FFF) in the Pulse Width registers will produce a constant DC output, while a value of 2048 ($800) will produce a square wave.
Syntax
sid.V1.setPWLo(dutyCycle)
Parameters
dutyCyclePulse Width


void SIDVoice::setRingMod ( boolean  active)
Description
Sets the Ring Mod bit of the control register
Datasheet
From Datasheet
The RING MOD bit, when set to a one, replaces the Triangle waveform output of Oscillator 1 with a “Ring Modulated” combination of Oscillators 1 and 3. Varying the frequency of Oscillator 1 with respect to Oscillator 3 produces a wide range of non-harmonic overtone structures for creating bell or gong sounds and for special effects. In order for ring modulation to be audible, the Triangle waveform of Oscillator 1 must be selected and Oscillator 3 must be set to some frequency other than zero. No other parameters of Voice 3 have any effect on ring modulation.
Syntax
sid.V1.setRingMod(active)
Parameters
active1 Ring Mod on 0 turns Ring Mod off


void SIDVoice::setSawtooth ( boolean  active)
Description
Sets the Sawtooth bit of the control register
Datasheet
From Datasheet
When set to a one, the Sawtooth waveform of Oscillator 1 is selected. The sawtooth waveform is rich in even and odd harmonics and has a bright, brassy quality.
Syntax
sid.V1.setSawtooth(active)
Parameters
active1 on 0 turns off


void SIDVoice::setSquare ( boolean  active)
Description
Sets the Square bit of the control register
Datasheet
From Datasheet
When set to a one, the Pulse waveform output of Oscillator 1 is selected. The harmonic content of this waveform can be adjusted by the Pulse Width registers, producing tone Qualities ranging from a bright, hollow square wave to a nasal, reedy pulse. Sweeping the pulse width in real-time produces a dynamic “phasing” effect which adds a sense of motion to the sound. Rapidly jumping between different pulse widths can produce interesting harmonic sequences.
Syntax
sid.V1.setSquare(active)
Parameters
active1 on 0 turns off


void SIDVoice::setSquare ( boolean  active,
int  pwm 
)
Description
Sets the Square bit of the control register and the PWM at the same time
Datasheet
From Datasheet
When set to a one, the Pulse waveform output of Oscillator 1 is selected. The harmonic content of this waveform can be adjusted by the Pulse Width registers, producing tone Qualities ranging from a bright, hollow square wave to a nasal, reedy pulse. Sweeping the pulse width in real-time produces a dynamic “phasing” effect which adds a sense of motion to the sound. Rapidly jumping between different pulse widths can produce interesting harmonic sequences.
Syntax
sid.V1.setSquare(active, pwm)
Parameters
active1 on 0 turns off
pwmset the pwm register for the voice


void SIDVoice::setSync ( boolean  active)
Description
Sets the Sync bit of the control register
Datasheet
From Datasheet
The SYNC bit, when set to a one, Synchronizes the fundamental frequency of Oscillator 1 with the fundamental frequency of Oscillator 3, producing “Hard Sync” effects. Varying the frequency of Oscillator 1 with respect to Oscillator 3 produces a wide range of complex harmonic structures from Voice 1 at the frequency of Oscillator 3. In order for sync to occur Oscillator 3 must be set to some frequency other than zero but preferably lower than the frequency of Oscillator 1. No other parameters of Voice 3 have any effect on sync.
Syntax
sid.V1.setSync(active)
Parameters
active1 syncs 0 turns sync off


void SIDVoice::setTest ( boolean  active)
Description
Sets the Test bit of the control register
Datasheet
From Datasheet
The TEST bit, when set to a one, resets and locks Oscillator 1 at zero until the TEST bit is cleared. The Noise waveform output of Oscillator 1 is also reset and the Pulse waveform output is held at a DC level. Normally this bit is used for testing purposes, however, it can be used to synchronize Oscillator 1 to external events, allowing the generation of highly complex waveforms under real-time software control.
Syntax
sid.V1.setTest(active)
Parameters
active1 Test on 0 turns Test off


void SIDVoice::setTriangle ( boolean  active)
Description
Sets the Triangle bit of the control register
Datasheet
From Datasheet
When set to a one, the Triangle waveform output of Oscillator 1 is selected. The Triangle waveform is low in harmonics and has a mellow, flute-like quality.
Syntax
sid.V1.setTriangle(active)
Parameters
active1 on 0 turns off



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