# DSP Resources

## Maximum Number of Audio Voices

Q: What is the maximum number of audio voices?

A: This is a complex issue. The number of voices available is determined by the sum of all resources used by all the active voices. These include:

- EI, I, and EO memory
- The 512 word instruction, `N', memory
- The thirteen input FIFOs and four output FIFOs
- The 500+ ticks of DSP cycles per frame

Typically the N memory and the number of ticks are the limiting factors. Instrument prioritization and voice stealing provide a good dynamic real-time system that optimizes DSP usage.

The real limits are not known yet, but you can play at least 8 variable rate, 16-bit samples with loudness control. Fixed rate samples are much less expensive than variable rate samples and are limited by the 13 input FIFOs. Resonant filters are cheaper than a variable rate sampler.

## Allocating DSP Resources

Q: After eight loads of `halfmono8.dsp`, the ninth load fails and I receive the error message: "Couldn't allocate DSP resources." Can you explain why?

A: Only eight fit. `Halfmono8.dsp` requires 49 DSP code words, and 38 DSP tick(cycles). For code words, the total is 512. The system takes 70, and a `mixer4x2.dsp` takes 32. That leaves 410 available. Divide that by 49 yields 8.36 `halfmono8` instruments worth of code maximum.

For ticks, the total is 565. The system takes 45, and a `mixer4x2.dsp` takes 32, that leaves 488 available. Dividing that by 38 yields 12.84 `halfmono8` instruments worth of ticks maximum. The code words are the limiting resource.

## DSP DMA

Q: How many DMA channels are used for each DSP program such as `sampler.dsp`? Does the number of channels vary with the instrument?

A: Synthesis instruments such as `svfilter.dsp` and `triangle.dsp` use 0 DMA channels. Mono and stereo sample playing instruments each use one DMA channel. The only instrument that uses two input DMA channels is `sampler3d.dsp`. The `delay1tap.dsp` instrument uses one output DMA channel and one input DMA channel.

Q: How many DMA channels can be allocated for the DSP?

A: There are 13 INPUT DMA channels used for playing samples. There are four OUTPUT DMA channels used for echo and delay effects.

Q: Could you briefly tell me about the relationship between the DSP and DMA controller?

A: The DSP plays audio samples by reading the sample data from a register in the DSP address space. There is a register for each DMA channel. The register connects to a FIFO which can store up to eight 16 bit sample words. When the FIFO is down to two sample words, a DMA request is issued that fills the FIFO from main memory.

## DSP Usage Monitor

Q: It seems to me that I saw a tool somewhere that would give a readout of the current used DSP resources. Can anyone tell me where this is?

A: The tool is called `audiomon` and it resides in `$c` (an alias set to $boot/System/Programs). `audiomon` displays a bar graph of DSP resources on the graphics screen. There is also a tool called `DumpDSPP.c` that prints to the terminal so it can be used when the graphics screen is busy.

## Dynamic Voice Allocation

Q: Is dynamic voice allocation supported?

A: The score playing code in the Music library supports dynamic voice allocation. When a voice is needed, the code attempts the following:

- Adopt an unused instrument of the same type.
- If that fails create a new instrument.
- If that fails adopt another instrument of a different type, kill it and use its resources.
- If that fails scavenge instruments from itself or others.

The code uses the Audio folio calls AbandonInstrument(), `AdoptInstrument()`, ScavengeInstrument(), and GetAudioItemInfo() to implement these functions.

For an example of using the score player as a sound effects manager, see the example program tsc_soundfx.c.