A 4-channel synthesizer for the LameStation.
audio : "LameAudio"
Demos for this object can be found in the
/demos/audio/ folder of the SDK.
- Load a new patch.
- Play sound on the specified channel.
- Set all parameters of the ADSR envelope shape.
- Toggle the ADSR envelope generator on the given audio channel.
- Set the frequency increment of the given audio channel.
- Set the note of the given audio channel.
- Manually set a parameter of the audio channel.
- Load a new sample.
- Set the volume of the given channel.
- Set the waveform of the given audio channel.
- Initialize the LameAudio library.
- Trigger start of envelope on the specified channel.
- Immediately stop all sound on all channels.
- Trigger end of envelope on the specified channel.
- Stop sound on the specified channel.
audio.LoadPatch- Load a new patch.
audio.PlaySound- Play sound on the specified channel.
audio.SetADSR- Set all parameters of the ADSR envelope shape.
audio.SetEnvelope- Toggle the ADSR envelope generator on the given audio channel.
audio.SetFrequency- Set the frequency increment of the given audio channel.
audio.SetNote- Set the note of the given audio channel.
audio.SetParam- Manually set a parameter of the audio channel.
audio.SetSample- Load a new sample.
audio.SetVolume- Set the volume of the given channel.
audio.SetWaveform- Set the waveform of the given audio channel.
audio.Start- Initialize the LameAudio library.
audio.StartEnvelope- Trigger start of envelope on the specified channel.
audio.StopAllSound- Immediately stop all sound on all channels.
audio.StopEnvelope- Trigger end of envelope on the specified channel.
audio.StopSound- Stop sound on the specified channel.
Before LameAudio can be used,
audio.Start must be called once and only once at the start of a program. LameAudio is designed so that only one synthesizer is ever running, and any object may call it.
Each channel has its own parameters that affect the sound it makes.
audio.SetParam can control any parameter in the Channel parameter constant list. You can change all parameters at once with the
audio.LoadPatch command, which is good if you change instruments often.
This is what a patch looks like.
DAT patch byte $F, 127, 10, 100, 10, audio#_SAW
Each channel has a waveform and an envelope.
The waveform generator is what actually creates the sound. Call
audio.SetFrequency to play any frequency, or call
audio.SetNote to play specific notes like on a piano.
audio.SetWaveform to load one of the following waveforms.
The Sample waveform is a 512B block of audio data, enough for one cycle. Call
audio.SetSample with the address of a sample to load it. Only one sample can be used at a time.
A collection of ready-made samples can be found in the
/media/samples/ folder of the SDK.
The envelope controls the volume of the sound over time, allowing you to create sounds that hit sharply like bells, or have a long hold time like a wind instrument. You can control how it sounds with the ADSR parameters of the envelope.
ADSR stands for Attack, Decay, Sustain, and Release. You can configure ADSR settings with
- Attack (
0-127) - The time from silence to full volume.
- Decay (
0-127) - The time from the max value to…
- Sustain (
0-127) - The volume at which the note is held while pressed.
- Release (
0-127) - The time from sustain to silence.
The envelope can be toggled with
If enabled, you can play and stop notes with the
If disabled, you can control channel volume manually using
audio.SetVolume, which is useful for creating sound effects. You can also manually start and stop the envelope with
To silence all audio, use the
LameStation songs consist of two main sections: pattern and sequence data.
A LameAudio sample is a 512-byte sequence of arbitrary data. It can be anything you want as long as its 512 bytes.
Example pattern section
DAT wav_data byte <512 bytes...>
Since it’s possible to use any address in memory, the running system can also create samples on the fly.
The address of sample data can be passed directly to
audio.SetSample, unless stored in another object. If so, use this interface:
PUB Addr return @wav_data