SpecDrum/DAC

From SpecNext official Wiki
Revision as of 22:21, 15 May 2024 by Danboid (talk | contribs) (Add ffmpeg wav encoding command)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Spectrum Next has 4 8-bit DAC ports which you can use for playing audio. Driving the DAC is done by outputting a byte of audio data to one of the ports below. The Next also supports slight improvements over the original SpecDrum which only had one output. SoundDrive is a term that means 4 8-bit DAC channels, 2 x Left 2 x Right and some Russian software supports this mode.

Data can be sent to the DACs either via NextRegs or OUTTING to a port.

Panning Port DAC
Left 0x1f DAC A
Left 0xf1 DAC A
Left 0x3f DAC A
Left 0x0f DAC B
Left 0xf3 DAC B
Centre 0xdf DAC A,D
Centre 0xfb DAC A,D
Centre 0xb3 DAC B,C
Right 0x4f DAC C
Right 0xf9 DAC C
Right 0x5f DAC D
 NumberReadableWritableDescription
DAC B (left) mirror Register$2CYesYesDAC B mirror, read current I2S left MSB
DAC A+D (mono) mirror Register$2DYesYesSpecDrum port 0xDF / DAC A+D mirror, read current I2S LSB
DAC C (right) mirror Register$2EYesYesDAC C mirror, read current I2S right MSB
... further results

The frequency that the DAC can play audio is based upon the rate at which audio data is sent to the port. For most purposes you will likely want to be running other code along with driving sound so a way to off-load feeding the DACs can be done with either the DMA, the COPPER or CTC interrupts. Depending on your base code the most suitable method will need to be analysed.

DMA play back is possibly the simplest method but this also requires exclusive use of the DMA and a section of memory for the DMA to play.

- Example of DMA audio playback https://github.com/em00k/zxnext-simple-dma

COPPER has the least CPU requirements but a more complicated to set up. The COPPER will need to be fed each frame.

- Example of COPPER audio playback TBC

CTC timers are a good mix of easy setup and drive leaving the DMA and COPPER free for other purposes.

- Example of settings up the CTC timers to playback audio https://github.com/em00k/playwav32

Encoding wav files using ffmpeg

The Next is capable of playing 8 bit mono or stereo wav files at up to 32 KHz sample rate.

The following ffmpeg command can be used to convert an audio file of any format that ffmpeg can decode into a stereo wav file playable on the Next. Change ac (Audio Channels) to 1 to encode a mono file.

ffmpeg -i input.wav -f wav -acodec pcm_u8 -ac 2 -ar 32000 output.wav