Skip to content

Sound Generation

The YM2149 PSG produces sound through three generators: the square wave generator, the envelope generator and the noise generator. Each channel can combine them in different ways.

A note's pitch, moved by transposition and pitch offsets, drives the active generators; a mixer switches tone and noise on or off, and a volume stage sets the level, either fixed or from the envelope. The MFP timer adds pulse-width modulation, envelope synchronization, envelope volume modulation, wavetables and digitized sample playback.

You set all of this on the steps of an instrument, in the 9. Instrument Editor.

Tone Modes

Each instrument step has a Mode field that sets which generators are active and whether the volume is fixed or comes from the envelope.

Mode Generators Active Volume Description
0 Noise only (if enabled) Fixed All tone and envelope generators disabled. Useful for percussion steps
1 Square wave Fixed Basic tone generation. The default mode for new instruments
2 Envelope Envelope Envelope generator acts as oscillator. Square wave disabled
3 Square wave + Envelope Envelope Square period drives envelope period via the envelope ratio. The classic "hard bass" mode
4 Square wave + Envelope Envelope Envelope period drives square period via the envelope ratio. Produces harmonically-rich overtones
5 Square wave + Envelope Envelope Both generators run independently with their own pitches

Mode Details

Mode 0 — Off: The tone and envelope generators are off. Noise still sounds if the step sets a noise period, at the step's volume; with nothing to sound, the channel is silent.

Mode 1 — Square Only: Only the square wave generator plays, at a fixed volume. This is the default for new instruments.

Mode 2 — Envelope Only: The envelope generator makes the sound. At short envelope periods (1–255) it acts as an oscillator with a metallic, buzzy tone. The envelope sets the level, so the step's volume is ignored.

Drive Modes (3 and 4)

In the drive modes one generator takes its pitch from the other. The envelope ratio, the envelope Ratio column of the step, sets how: each step of the envelope ratio moves the driven side by one octave.

Mode 3 — Square Drives Envelope: The square wave sets the pitch, and the envelope period is the square period divided by 2 to the power of the envelope ratio (by 2, 4, 8, 16 for envelope ratios 1, 2, 3, 4), so a higher envelope ratio puts the envelope higher. This is the classic hard bass sound.

Mode 4 — Envelope Drives Square: The envelope sets the pitch, and the square period is the envelope period multiplied by 2 to the power of the envelope ratio, so a higher envelope ratio puts the square lower. It gives rich overtones, useful for bell-like or metallic sounds.

A period written on the step takes the place of the ratio: the envelope ratio derives only the side whose period you leave unset. With an envelope ratio of 0 there is no coupling: each generator uses its own pitch, so the step plays exactly as mode 5. The step grid marks the tone Mode of such a step as a warning; give it an envelope ratio, or choose mode 5.

Choosing between them: with an envelope ratio above 0 the two modes sound different, even at the same ratio. In Square Drives Envelope the square follows the note and stays in tune, but the envelope period has to be rounded to a whole number, so the envelope is slightly off an exact multiple of the square and the two beat against each other. In Envelope Drives Square the envelope follows the note and the square is derived from it exactly, so the two stay locked and never beat, but the pitch can only move in the envelope's coarser steps, so high notes go noticeably out of tune. Hover either mode in the step grid, the step graphs or the list of tone modes to see the same explanation.

Mode 5 — Square and Envelope: Both generators run independently, each with its own pitch, and the envelope sets the level.

Envelope Tuning

The envelope generator is far less precise about pitch than the square generator. In the bass it sounds in tune; by the fourth octave its nearest pitch may be a quarter-tone off a note, and higher up the gaps grow wider than the notes, so a buzzer lead can sound sour. Hover the envelope Per column to see the pitch a period produces and how far it is from the nearest note.

Three things help:

  • Use a one-way envelope shape. Shapes that ramp in one direction are twice as precise as those that ramp up and down
  • Put the envelope lower. Every octave down roughly halves the error; let the square wave carry the fundamental
  • Use an envelope synchronization. In that timer mode a timer sets the pitch, accurate to a few cents everywhere, at the cost of one of the song's timers. The Envelope Volume Modulation (EVM) timer mode does the same and also gives the buzzer a volume; see Mode 3

Shared Hardware Resources

The three channels share some of the hardware:

  • Envelope Generator: There is one envelope generator (registers R11–R13), used by one channel at a time. A channel that starts an envelope sound, or plays a new note, takes it over; the channel that loses it plays at its step volume, or is silent in Envelope Only mode, until it gets it back. When the owner stops, the channel that has waited longest takes over.
  • Envelope restart: A note written with its instrument number starts the envelope at the beginning of its shape; a note without the number leaves it running, so a slide or tied note continues a buzzer unbroken. The square wave cannot be restarted, so when the envelope repeats at about the square's rate, as in a hard bass, some notes come out quieter; detune the two a little, or drop the envelope an octave.
  • Envelope cut: When a buzzer is cut off, by an OFF, a released key, a mute or Stop, RhYMe silences the channel at the moment its envelope passes zero rather than wherever the ramp happens to be, so the cut makes no click. The exported Atari ST player cuts at the frame, as the machine does, so a buzzer can click there where it does not in RhYMe or in a WAV or MP3 export.
  • Noise Generator: All channels share one noise period register (R6). When channels you can hear set different noise periods at once, the highest-numbered one (C before B, B before A) wins; a channel whose volume is 0 does not count, unless the envelope, a timer effect or a sample keeps it sounding. Give channels that play noise together the same noise period, or let only one use noise at a time.
  • Volume: In the envelope modes (2–5) the envelope sets the level and the step volume is ignored, except in the Envelope Volume Modulation (EVM) timer mode. A step in Wavetable mode never uses the envelope.
  • Timers: Each audio-rate effect (pulse-width modulation, envelope synchronization, envelope volume modulation, wavetables and sample playback) needs one of the machine's timers: three, four when the song adds Timer C, or fewer when the song reserves some for the export's player. A channel that starts an effect while none is free plays without it.

For a quick reference of all modes and step parameters, see 19. Instrument Step Parameter Reference. Its parameter matrix shows which parameter is heard in which mode, and which use a shared sound source.

Timer Modes

Each instrument step can use the hardware timer (MFP 68901) for pulse-width modulation, envelope synchronization, envelope volume modulation or a wavetable at audio rates. The timers are shared; see Shared Hardware Resources.

The timer Mode column in the step grid chooses the mode. The timer rate comes from the channel's square wave period, changed by the step's timer columns:

Field Column Range Description
Mode Mode 0h–4h Timer mode: 0h=Off, 1h=PWM, 2h=ESY (envelope synchronization), 3h=EVM (envelope volume modulation), 4h=WVT (wavetable)
Period Per 0000h–FFFFh Forced timer period. Overrides square period when set
Octave Oct −8h–+8h Timer rate offset in octaves.
Transp. Trans −60h–+60h Semitone offset for the timer rate
Pitch Pitch −FFFh–+FFFh Fine period offset for the timer rate
Volume Vol 0h–Fh PWM volume: the level of the quiet half of a pulse width. - leaves that half silent
Wave Wave 01h–7Fh Wavetable mode: the number of the wavetable to play. -- plays none

Mode 0 — Off

No timer runs; the step's volume and tone mode alone set the sound. This is the default for new steps.

Mode 1 — PWM (Pulse-Width Modulation)

The timer switches the channel's volume between the step's level and silence at an audio rate that follows the square wave, giving a richer, grittier tone.

PWM volume: The Timer group's Vol column gives the quiet half its own level instead of silence; the closer the two levels, the softer the effect. Leave it at - for the classic sound. The volume column and the instrument's volume lower both halves alike. The first quiet half of a note is always silent, as on the Atari ST, and a new PWM volume is heard from the next quiet half on.

Rate calculation: The timer period, from the square period or a forced timer period, is moved by the timer octave, transposition and pitch offset, then rounded to the nearest rate the MFP can produce, since not every rate is available. Rates above about 42 kHz are capped.

Incompatibilities: PWM needs a square wave to switch, so it runs in every tone mode that plays the square, whatever the envelope shape, and does not run in Off or Envelope Only. The step grid shows a warning on such a step's timer mode. Beside the envelope, the loud half follows the envelope and the quiet half stays at the PWM volume.

Mode 2 — Envelope Synchronization (ESY)

The timer restarts the hardware envelope at the timer rate, so the timer, not the envelope period, sets the pitch you hear. The envelope sets the level. The step's envelope retrigger setting (the envelope Ret column) has no effect in this mode. The envelope is only restarted while the channel has the envelope generator, so another channel's envelope sound is not disturbed.

Incompatibilities: Envelope synchronization needs the envelope, so in Off and Square Only the timer does not start, takes no timer, and the step plays as if its timer mode were off. The step grid shows a warning on such a step's timer mode.

Mode 3 — Envelope Volume Modulation (EVM)

This mode gives a buzzer a working volume. The timer restarts a rising envelope at the pitch set by your envelope settings, and RhYMe sets the envelope period so the ramp climbs exactly as far as the step volume asks before each restart. You hear the same buzzer at every volume, only quieter, and in tune everywhere.

Key behavior:

  • Vol works as for a square: 0 is silence and 8 is as loud as a square at 8. The full ramp is only as loud as a square at E, so E and F sound alike. The volume column and volume slides work too
  • The envelope Oct, Trans and Pitch set the pitch, and a buzzer switched to this mode keeps its pitch. RhYMe sets the envelope Per, so it is dimmed, and so are the timer's own Per, Oct, Trans and Pitch
  • Choosing the mode sets the envelope shape to the rising ramp and locks the Shape column, in the step grid and the step graphs, until you change the timer mode
  • Arpeggios, vibratos, vibrato tables, portamento and pitch slides move the buzzer by the same interval they move a square. A square sounding alongside, in Square Drives Envelope or Square and Envelope, is tuned to the timer, unless you write its period yourself
  • The envelope Ret column has no effect, and the envelope is only restarted while the channel has the envelope generator

Limits: Only one buzzer with a volume can play at a time. On high notes the top few volume steps may sound alike; below about a kilohertz every step is distinct. A channel that starts in this mode while no timer is free, or whose pitch is too low for a timer (a buzzer left four octaves below its note, for instance), gets an envelope that rises once and then falls silent, so in Envelope Only mode the note is not heard and the other channels play at their usual loudness. If a timer becomes free later in the note, the buzzer starts from there.

Incompatibilities: As with envelope synchronization, the mode does nothing in Off and Square Only, takes no timer there, and the step grid shows a warning on the timer mode.

Mode 4 — Wavetable (WVT)

The timer plays a wavetable through the channel's volume: a cycle of 2 to 64 volume levels you draw on the Wavetables tab. The step's Wave column sets which one. Each time the timer fires it moves on to the next level, and after the last it starts again from the first.

Pitch: One pass through all the levels is one cycle of the note, so a wavetable plays at the note's pitch whatever its length. As with PWM, the timer Oct, Trans and Pitch columns, the pitch effects and the instrument's tuning and vibrato move it. A 32-level wavetable needs 32 timer ticks per cycle of the note, and an Atari ST serves at most 125,000 ticks a second, so the export refuses a wavetable on a very high note; play it lower or give it fewer levels. Every tick also takes processor time on the Atari ST, so a wavetable twice as long takes twice as much at the same note, and the timer has fewer exact speeds to choose from the faster it runs, so a long wavetable on a high note plays less in tune. Keep a wavetable short unless it plays low, where extra levels give it the most detail.

Volume: The step's Vol, the channel volume and the instrument's volume make the wavetable quieter. They take the same number of chip volume steps off every level rather than scaling the shape; a level below silence is silent. A volume change is heard from the next level on.

Tone modes: A wavetable plays in every tone mode. In Off you hear it on its own; with the square or noise on, it shapes them. It never uses the envelope, so the Envelope group is dimmed on such a step.

Switching wavetables: A wavetable plays on through every following step in the same mode, and a new note on the same wavetable continues from the level it had reached. When a step switches to another wavetable, the instrument's Transition setting (under Wavetables on its Parameters tab) says what happens to the one playing:

  • Continuation, the default, keeps the cycle going: the new wavetable takes over from the next level on, at the place the old one had reached, counted round its own length when the two differ. Nothing restarts, so there is no click and no delay, which makes it the mode for stepping through wavetables of one shape at different levels, such as a sweep or a volume shape drawn as a series of wavetables. In return, the new wavetable is entered part way through its cycle, so its own beginning is not heard, and where the two lengths differ the level it lands on depends on where the old cycle happened to be, which can differ from one note to the next. The cycle is then not kept in step: the new wavetable continues from the same number of levels played, counted round its own length, not from the same point in its cycle, so where a 64-level wavetable is nearly two thirds of the way through, a 32-level one continues from a level under a third of the way through. Between wavetables of the same length the cycle carries on exactly.
  • Restart begins the new wavetable from its first level, as a wavetable entered from another mode does. The switch is heard exactly on the step, and the new wavetable always starts the same way, so a shape with a distinct beginning, such as a percussive attack, sounds the same on every step that reaches it. The cost is the jump from wherever the old cycle was to the new first level, a break in the waveform that can be heard as a click or a thump, most of all on low notes and between wavetables of similar shape.
  • Synchronized lets the old wavetable finish its cycle, and the new one begins from its first level right after the old one's last. Every cycle is played whole, so there is no click, and every wavetable still starts from its beginning: the choice for a sequence of distinct shapes that should each be heard complete. The cost is timing: the switch waits up to one cycle of the note, which is nothing you would notice at an audible pitch but a clear delay on a very low note, and it lands where the cycle ends rather than exactly on the step. While it waits, the old wavetable keeps its pitch and volume, and a volume change or a further switch replaces the one waiting, so steps that switch faster than the cycles finish skip wavetables.

The Atari ST exports switch the same three ways, so a song sounds the same in RhYMe and on the machine.

Hardware Constraints

The MFP 68901 timer can only produce certain rates, so the rate you hear may differ slightly from the ideal one.

Each channel's timer runs on from step to step within a note, and starts over only when a step turns a timer effect on after the timer mode was Off.