osAiSetNextBuffer osAiSetNextBuffer (function)

osAiGetStatus, osAiGetLength, osAiSetFrequency, osAiSetNextBuffer

AI (audio interface) function


#include <ultra64.h>     /* ultra64.h */
u32 osAiGetStatus(void);
u32 osAiGetLength(void);
s32 osAiGetFrequency(u32 frequency);
s32 osAiSetNextBuffer(void *vaddr, u32 nbytes);


These routines provide basic control for the AI (audio interface).

osAiGetStatus returns the hardware status of the audio interface. In this 32-bit value, only bits AI_STATUS_FIFO_FULL and AI_STATUS_DMA_BUSY contain useful information. AI_STATUS_FIFO_FULL is set when both audio DMA registers have been programmed. AI_STATUS_DMA_BUSY is set when DMA is in progress.

Based on the input requested frequency (in Hz), the osAiSetFrequency function calculates the correct values for the internal divisors and returns the actual frequency generated by these divisors. The requested frequency should fall between 3000 Hz and 368000 Hz on NTSC systems, or between 3050 Hz and 376000 Hz on PAL systems.

osAiSetNextBuffer sets up the next DMA transfer from RDRAM to the audio interface buffer. The vaddr argument points to the buffer in RDRAM, and the nbytes argument specifies the number of bytes to transfer. Note that the buffer address vaddr must be 64-bit aligned and that nbytes must be a multiple of 8 bytes. A maximum transfer size of 262144 bytes is supported. If the interface is busy (that is, AI_STATUS_FIFO_FULL is set), osAiSetNextBuffer returns -1 and stops the DMA operation.

osAiGetLength returns the number of bytes remaining in the current DMA buffer.


For hardware version 1.0, the audio DMA length register is only 15-bit long and thus supports a maximum transfer size of 32 Kbytes. In the final release, this register is extended to 18 bits to support a transfer of 256 Kbytes.

Known Issue

It is worth noting that a previous hardware bug has been fixed by a software patch in osAiSetNextBuffer. This bug occurred when the address of the end of the buffer specified by osAiSetNextBuffer was at a specific value. This value occurred when the following was true:

(vaddr + nbytes) & 0x00003FFF == 0x00002000

(when the buffer ends with address of lower 14 bits 0x2000) In this case, the DMA transfer does not complete successfully. This can cause clicks and pops in the audio output. This bug no longer requires special handling by the application because it is now patched by osAiSetNextBuffer.

See Also

osAiGetStatus, osAiGetLength, osAiSetFrequency, and osTvType

Revision History

1999/04/30 Changed Format