Difference between revisions of "SpecDrum/DAC"
(Created page with " 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 al...") |
(Add ffmpeg wav encoding command) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | 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. | + | 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. | Data can be sent to the DACs either via NextRegs or OUTTING to a port. | ||
Line 36: | Line 36: | ||
}} | }} | ||
− | The frequency that the DAC 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 | + | 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. | '''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. | ||
Line 49: | Line 49: | ||
- Example of settings up the CTC timers to playback audio https://github.com/em00k/playwav32 | - 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 |
Latest revision as of 21:21, 15 May 2024
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 |
Number | Readable | Writable | Description | |
---|---|---|---|---|
Keymap High Address Register | $28 | Yes | Yes | PS/2 Keymap address MSB, read (pending) first byte of palette colour |
Keymap Low Address Register | $29 | No | Yes | PS/2 Keymap address LSB. |
Keymap High Data Register | $2A | No | Yes | High data to PS/2 Keymap (MSB of data in bit 0) |
... 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