1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="Microsoft FrontPage 5.0">
6<META http-equiv="Content-Style-Type" content="text/css">
7<LINK rel="stylesheet" type="text/css" href="../CSS/revolution.css">
8<TITLE>Audio Interface (AI) Library</TITLE>
9</HEAD>
10<BODY>
11
12<H1>Audio Interface (AI) API</H1>
13
14<P>
15<A href="#Introduction" target="_self">Introduction</A><BR> <A href="#HW_components" target="_self">Audio Hardware Configuration</A><BR> <A href="#AI_DMA" target="_self">AI DMA</A><BR>
16</P>
17
18<H2><A name="Introduction">Introduction</A></H2>
19<P>The Wii's Audio Interface (AI) manages the transfer of audio data from the DSP (specifically, main memory) to an external digital-analog converter (DAC).</P>
20
21<P>The AI Library API (AI API) provides the following related AI services.</P>
22
23<UL>
24<LI>Sets the sampling frequency for audio data input (DSP output) to the AI.
25<LI>AI DMA control.
26</UL>
27
28<P>This manual is intended for those who design low-level software for the Nintendo Revolution audio subsystem. Readers must have knowledge about the Revolution hardware architecture, especially the features that pertain to the audio subsystem.</P>
29
30<P>Refer to the <a href="AI_API_Menu.html" target="contents">AI API Menu</a> for detailed descriptions of the library functions.</P>
31
32<H2><A name="HW_components">Audio Hardware Configuration</A></H2>
33
34<P>The Wii's audio hardware consists of an audio subsystem, AI, and DAC.</P>
35
36<P><IMG src="AI_blocks.gif" width="808" height="461" alt="Audio Hardware"></P>
37
38<H3>Audio Subsystem</H3>
39
40<P>The audio subsystem consists of a DSP for audio synthesis, a DSP DMA for controlling data transfer between the DSP and main memory, and an AI DMA/FIFO for controlling data transfer from main memory to the AI.</P>
41
42<P>First, the DSP DMA places the audio data that the DSP synthesizes in main memory. Next, the audio data is passed to the AI via the AI DMA/FIFO. At this time, AI API is used for AI DMA control.</P>
43
44<H3>Main Memory</H3>
45
46<P>The audio hardware can access both internal and external main memory.</P>
47
48<H3>AI</H3>
49
50<P>The AI consists of a hardware sampling rate converter (SRC) and a DAC interface.</P>
51
52<P>SRC converts the sampling frequency from 32 kHz (fixed) to 48 kHz (fixed) for the audio data that DSP synthesizes. The AI API turns SRC ON/OFF. If the sampling frequency of the audio data is already 48 kHz, SRC is OFF because the sampling frequency doesn't need to be converted.</P>
53
54<H3>DAC</H3>
55
56<P>The DAC is an external 16-bit stereo DAC that processes audio data at a sampling frequency of 48 kHz (fixed).</P>
57
58<H2><A name="AI_DMA">AI DMA</A></H2>
59
60<P>The AI DMA transfers audio data from the main memory to the AI via the AI FIFO.</P>
61
62<H3>Basic Operations</H3>
63
64<P>The AI DMA controller sets the audio data length and registers the main memory address. The AI DMA transfers the audio data from the main memory address to the AI via the AI FIFO (in fact, it transfers 32 Bytes each (=DMA block size) from the main memory via the AI FIFO). The <code>AIInitDMA</code> function is used to register the main memory address and DMA size.</P>
65
66<P>Audio data registered for the AI DMA controller is transferred from main memory to the AI according to the sampling frequency that the <code>AISetDSPSampleRate</code> function sets.</P>
67
68<P>The <code>AISetDSPSampleRate</code> function also turns the AI SRC on and off. SRC is ON if the sampling frequency for audio data AI input (DSP output) is set to 32 kHz using the <code>AISetDSPSampleRate</code> function. SRC is OFF if the sampling frequency for data is set to 48 kHz.</P>
69
70<P>When audio data (with the length that the <code>AIInitDMA</code> function registers) is transferred to the AI, the AI DMA issues a DMA interrupt (<code>AIDINT</code>) to the host CPU (Broadway). The AI library manages this AI DMA interrupt. The <code>AIRegisterDMACallback</code> function can be used to register a callback function to call every time an AI DMA interrupt occurs.</P>
71
72<P>The following is an example of a triple audio buffer.</P>
73
74<P><IMG src="AI_flow.gif" width="627" height="948" alt="Triple Audio Buffer"></P>
75
76<H3>Data Format</H3>
77
78<P>The AI DMA transfers audio data in stereo 16-bit PCM (big endian) format. For each sample, data must be interleaved from the right to left channel. </P>
79
80<H3>Modifying Data</H3>
81
82<P>Usually the audio library (AX) manages the audio buffer in the main memory that becomes the transmission source of an AI DMA transfer. AI API calls are also handled inside the audio library.</P>
83
84<P>The physical address of the audio buffer that the audio library registers using the <code>AIInitDMA</code> function for the AI DMA controller can be obtained using the <code>AIGetDMAStartAddr</code> function. Be sure to convert the physical address that the <code>AIGetDMAStartAddr</code> function retrieves into a logical address using the <code>OSPhysicalToCached</code> function. Similarly, you can obtain the DMA length that was registered using the <code>AIInitDMA</code> function for the AI DMA controller with the <code>AIGetDMALength</code> function.</P>
85
86<P>You can obtain the callback function for AI DMA interrupts registered by the audio library as the return value of the <CODE>AIRegisterDMACallback</CODE> function.</P>
87
88<P>Using these functions, you can manipulate audio data that the DSP outputs outside of the audio library.</P>
89
90<P>However, an accurate understanding of how the audio library operates is required to correctly manipulate audio data that the DSP outputs. The sample program <CODE>THPSimple</CODE> in the movie library (THP) uses the CPU to mix the movie audio data with the audio data that the audio library (AX) outputs. (File is under the path <code>build/demos/thpdemo/src/THPSimple/THPSimple.c</code>.) Use this example program as a reference for similar processes.</P>
91
92<P>To avoid cache consistency issues, be sure to use the <code>DCInvalidateRange</code> function  to invalidate the cache when referencing the audio data that the DSP outputs from the CPU. If changes are to be made by the CPU to audio data output by the DSP, be sure to flush the cache using the <code>DCFlushRange</code> function after the changes are made.</P>
93
94<p><B>Note: The AX Library calls the <code>AIRegisterDMACallback</code> function from inside the initialization function (for example, inside <code>AXInit</code>). Because of this, any AI DMA interrupt callback set using the <code>AIRegisterDMACallback</code> function before the AX library initialization function was called will be overwritten by the AX callback. If you are using an original AI DMA interrupt callback, be sure to set it using <code>AIRegisterDMACallback</code> only after calling the AX library initialization function.</B></p>
95
96<H3>DSP DMA</H3>
97
98<P>The DSP DMA manages the audio library (AX). The DSP DMA cannot be controlled outside of the audio library.</P>
99
100<H2>Revision History</H2>
101<P>
1022008/12/26 Added a note about the AI DMA interrupt callback.<br>2006/03/01 Initial version.
103</P>
104
105<hr><p>CONFIDENTIAL</p></body>
106</HTML>