Skip to content
Phosphoricwiki
Contents

Sound

Phosphoric’s PSG runs at the chip’s pace, not the sound card’s. It took measuring the signal, rather than comparing bytes, to discover an envelope twice too slow.

On this page

The chip

The Oric makes its sound with an AY-3-8912, a PSG (programmable sound generator):

  • three voices of square wave, each with its frequency and volume;
  • a noise generator, mixable into any voice;
  • sixteen envelope shapes, to raise, lower or repeat the volume;
  • an input/output port (port A), which the Oric uses for the keyboard and the joystick.

The processor does not talk to the PSG directly: it goes through the VIA’s port A and its CA2 and CB2 control lines.

Clocked at hardware rate

Since version 2.0, Phosphoric’s PSG runs at clock/8 = 125 kHz, the chip’s real internal step, and no longer at the audio output rate. The formulas are those of the datasheet:

GeneratorFrequency
voice (period TP)clock / (16 · TP)
noise (period NP)clock / (16 · NP)
envelope (period EP)clock / (8 · EP)

Integrated output

Each audio sample averages the PSG steps it covers. Above the Nyquist frequency, a signal fades instead of folding back. Before, a tone programmed at 62.5 kHz came out at 18.4 kHz, at full amplitude: a ghost whistle.

make test-audio checks, by measuring the signal produced:

  • a voice’s frequency within 0.1% of the datasheet formula;
  • the envelope’s duration within 2%;
  • a balanced noise, whose shift register never gets stuck at zero.

Writes to the PSG’s registers are timestamped in processor cycles. “Digidrums”, those sampled sounds played by changing the volume at full speed, therefore come out at the right moment.

From the PSG to the speaker

From the PSG to the speaker: what the schematic saysThe three outputs of the AY-3-8912 are tied together on a 1 kΩ resistor: the mix averages the channels. A 4.7 kΩ / 470 Ω divider with a 10 nF capacitor forms a 37 kHz low-pass, above what we hear. A coupling capacitor blocks DC, then an LM386 drives the speaker. Phosphoric models the average and the DC blocking; the exact value of the coupling capacitor is unreadable on the schematic.The Oric's audio output stageAY-3-8912channel Achannel Bchannel CmixingR4 = 1 kΩlow-passR2, R3, C5couplingC4LM386to the speakertied channelsmake an averagecuts at 37 kHz:outside the bandblocks DC,value unreadablenot modelled:LM386, speakerModelled: the average of the three channels (sum / 3) and DC blocking (cut-off near 1.7 Hz).Measured after the fix: DC of +15 instead of +8188, symmetric signal.
The Oric’s output stage, from its schematic: a mix, a low-pass, a coupling, an amplifier.

The output stage was read from an Oric-1 and Atmos schematic reconstructed in KiCad (revision “Issue 6.1”). It removed two uncertainties and left one:

  1. The mix averages the channels. The three outputs are tied together on one 1 kΩ resistor: two idle channels “pull” on the one that plays. A measurement published on an Oric forum confirms it: one channel alone at 1 V gives about 0.33 V at the mixing point. The model, which takes the sum divided by 3, was therefore right; the “deviation” attributed to it was wrong.
  2. The low-pass cuts at 37 kHz. C5 (10 nF) sees R2 and R3 in parallel (427 Ω): the cut-off is above what can be reproduced at 44.1 kHz. Nothing to model.
  3. The coupling blocks DC. The PSG signal never goes below zero. Three channels at full volume gave a DC offset of +8188, half the amplitude. Phosphoric now blocks DC, with a cut-off near 1.7 Hz, inaudible. Measured afterwards: DC of +15, symmetric signal (−8232 to +8252 instead of 0 to +16383).

Recording the sound

NeedOption
Capture sound to a 16-bit stereo 44.1 kHz WAV, even with no display--audio-wav FILE
Log every write to a PSG register, with its cycle--psg-trace FILE
Stream sound live (WAV stream)--cast-server, path /audio

Since --audio-wav works without a display, sound is tested in the CI just like the picture.

Other sound sources

Expansion cards add their own sound, mixed with the PSG’s along the same path (window, WAV capture, AVI video, streaming):

  • SP0256-AL2 (General Instrument), allophone speech synthesis from the Mageco card, at $03F1, with its 2 KB ROM;
  • MEA 8000 (Philips), formant synthesis from the TMPI card, at $03FE-$03FF;
  • MIDI: the original Mageco card or its ORICON remake drive a host synthesiser (FluidSynth, a music program) through a real MIDI port, and a MIDI keyboard can play into the Oric. See Page 3 and the cards.

Sources in the repository : docs/ACCURACY.md, docs/architecture/oric-audio-output.md, docs/articles/v2-cycle-stepped.md, README.md.