Tridora-CPU/doc/tdraudio.md
2025-10-07 01:16:25 +02:00

3.7 KiB

Audio Controller

The audio controller provides four channels of 16-bit PCM audio playback.

It uses multiple registers starting at address $A00.

Each of the four channels has three registers.

For the first channel the register addresses are:

Address Description
$A00 Control Register
$A01 Clock Divider Register
$A02 Amplitude Register

The register addresses for the second channel start at $A04, the third channel at $A08 and the fourth channel at $A0C.

Reading the control register

bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Value - - - - - - - - - - - - - - - -
bit 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Value - - - - - - - - - - - i f e p c
Bitfields Description
i interrupt is enabled for this channel when 1
f sample buffer is full when 1
e sample buffer is empty when 1
p changes from 0 to 1 and vice versa on each sample clock
c channel is enabled if 1

Writing the control register

bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Value - - - - - - - - - - - - - - - -
bit 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Value - - - - - - - - - - - i - - - c
Bitfields Description
c enable channel if 1, disable if 0
i enable channel interrupt if 1, disable if 0

Writing the clock divider register

bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Value d d d d d d d d d d d d d d d d
bit 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Value d d d d d d d d d d d d d d d d
Bitfields Description
d an unsigned 32-bit value for the clock divider

Writing the amplitude register

bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Value - - - - - - - - - - - - - - - -
bit 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Value a a a a a a a a a a a a a a a a
Bitfields Description
a an unsigned 16-bit value for the amplitude (sample) value with a bias of 32768

Notes

The clock divider specifies the number of CPU clock ticks between two samples.

Writing to the amplitude register adds the sample value to the sample buffer. The sample buffer is organized as a FIFO with 16 elements.

Amplitude (sample) values are represented as unsigned, biased 16-bit numbers. The bias is 32768, so given an amplitude range of 1.0 to -1.0, a 1.0 is represented by 65535, 0.0 by 32768 and -1.0 by 0.

Interrupt processing needs to be enabled for each channel if required.

An interrupt on any channel will be signalled to the interrupt controller as IRQ 2. The interrupt service routine should check all running channels for an emtpy buffer.

If an audio interrupt has occured on a channel, the interrupt enable flag is cleared for that channel. It needs to be re-enabled in the interrupt service routine.

Interrupts also need to be enabled on the interrupt controller, and re-enabled there after each interrupt.