1 /*-------------------------------------------------------------
2 
3 audio.h -- Audio subsystem
4 
5 Copyright (C) 2004
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
8 
9 This software is provided 'as-is', without any express or implied
10 warranty.  In no event will the authors be held liable for any
11 damages arising from the use of this software.
12 
13 Permission is granted to anyone to use this software for any
14 purpose, including commercial applications, and to alter it and
15 redistribute it freely, subject to the following restrictions:
16 
17 1.	The origin of this software must not be misrepresented; you
18 must not claim that you wrote the original software. If you use
19 this software in a product, an acknowledgment in the product
20 documentation would be appreciated but is not required.
21 
22 2.	Altered source versions must be plainly marked as such, and
23 must not be misrepresented as being the original software.
24 
25 3.	This notice may not be removed or altered from any source
26 distribution.
27 
28 -------------------------------------------------------------*/
29 
30 #ifndef __AUDIO_H__
31 #define __AUDIO_H__
32 
33 /*! \file audio.h
34 \brief AUDIO subsystem
35 
36 */
37 
38 #include <gctypes.h>
39 
40 /*!
41  * \addtogroup ai_stream_mode AI streaming modes
42  * @{
43  */
44 
45 #define AI_STREAM_STOP			0x00000000		/*!< Stop streaming audio playback */
46 #define AI_STREAM_START			0x00000001		/*!< Start streaming audio playback */
47 
48 /*!
49  * @}
50  */
51 
52 /*!
53  * \addtogroup ai_sample_rates AI sampling rates
54  * @{
55  */
56 
57 #define AI_SAMPLERATE_32KHZ		0x00000000		/*!< AI sampling rate at 32kHz */
58 #define AI_SAMPLERATE_48KHZ		0x00000001		/*!< AI sampling rate at 48kHz */
59 
60 /*!
61  * @}
62  */
63 
64 #ifdef __cplusplus
65    extern "C" {
66 #endif /* __cplusplus */
67 
68 /*!
69  * \typedef void (*AIDCallback)(void)
70  * \brief function pointer typedef for the user's Audio DMA interrupt callback
71  *
72  * \param none
73  */
74 typedef void (*AIDCallback)(void);
75 
76 /*!
77  * \typedef void (*AISCallback)(u32 smp_cnt)
78  * \brief function pointer typedef for the user's Audio Streaming interrupt callback
79  *
80  * \param smp_cnt AI sample count
81  */
82 typedef void (*AISCallback)(u32 smp_cnt);
83 
84 /*!
85  * \fn AISCallback AUDIO_RegisterStreamCallback(AISCallback callback)
86  * \brief Register a user callback function for the AUDIO streaming interface
87  *
88  * \param[in] callback pointer to the function which to call when AIS interrupt has triggered.
89  *
90  * \return pointer to old callback function or NULL respectively.
91  */
92 AISCallback AUDIO_RegisterStreamCallback(AISCallback callback);
93 
94 /*!
95  * \fn void AUDIO_Init(u8 *stack)
96  * \brief Initialize the AUDIO subsystem
97  *
98  * \param[in] stack pointer to a memory area to work as stack when calling the callbacks. May be NULL
99  *
100  * \return none
101  */
102 void AUDIO_Init(u8 *stack);
103 
104 /*!
105  * \fn void AUDIO_SetStreamVolLeft(u8 vol)
106  * \brief Set streaming volume on the left channel.
107  *
108  * \param[in] vol level of volume 0<= vol <=255
109  *
110  * \return none
111  */
112 void AUDIO_SetStreamVolLeft(u8 vol);
113 
114 /*!
115  * \fn u8 AUDIO_GetStreamVolLeft()
116  * \brief Get streaming volume of the left channel.
117  *
118  * \return level of volume.
119  */
120 u8 AUDIO_GetStreamVolLeft();
121 
122 /*!
123  * \fn void AUDIO_SetStreamVolRight(u8 vol)
124  * \brief set streaming volume of the right channel.
125  *
126  * \param[in] vol level of volume 0<= vol <=255
127  *
128  * \return none
129  */
130 void AUDIO_SetStreamVolRight(u8 vol);
131 
132 /*!
133  * \fn u8 AUDIO_GetStreamVolRight()
134  * \brief Get streaming volume of the right channel.
135  *
136  * \return level of volume.
137  */
138 u8 AUDIO_GetStreamVolRight();
139 
140 /*!
141  * \fn void AUDIO_SetStreamSampleRate(u32 rate)
142  * \brief Set streaming sample rate
143  *
144  * \param[in] rate streaming \ref ai_sample_rates "sample rate"
145  *
146  * \return none
147  */
148 void AUDIO_SetStreamSampleRate(u32 rate);
149 
150 /*!
151  * \fn u32 AUDIO_GetStreamSampleRate()
152  * \brief Get streaming sample rate
153  *
154  * \return \ref ai_sample_rates "sample rate"
155  */
156 u32 AUDIO_GetStreamSampleRate();
157 
158 /*!
159  * \fn AIDCallback AUDIO_RegisterDMACallback(AIDCallback callback)
160  * \brief Register a user callback function for the audio DMA interface.
161  *
162  *        This callback will be called whenever the audio DMA requests new data.<br>
163  *        Internally the DMA buffers are double buffered.
164  *
165  * \param[in] callback pointer to the function which to call when AID interrupt has triggered.
166  *
167  * \return pointer to old callback function or NULL respectively.
168  */
169 AIDCallback AUDIO_RegisterDMACallback(AIDCallback callback);
170 
171 /*!
172  * \fn void AUDIO_InitDMA(u32 startaddr,u32 len)
173  * \brief Initialize an audio DMA transfer
174  *
175  * \param[in] startaddr start address of the memory region to load into the audio DMA. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery!
176  * \param[in] len lenght of data to load into the audio DMA. <b><i>NOTE:</i></b> Should be a multiple of 32
177  *
178  * \return none
179  */
180 void AUDIO_InitDMA(u32 startaddr,u32 len);
181 
182 /*!
183  * \fn u16 AUDIO_GetDMAEnableFlag()
184  * \brief Get the audio DMA flag
185  *
186  * \return state of the current DMA operation.
187  */
188 u16 AUDIO_GetDMAEnableFlag();
189 
190 /*!
191  * \fn void AUDIO_StartDMA()
192  * \brief Start the audio DMA operation.
193  *
194  *        Starts to transfer the data from main memory to the audio interface thru DMA.<br>
195  *        This call should follow the call to AUDIO_InitDMA() which is used to initialize DMA transfers.
196  *
197  * \return none
198  */
199 void AUDIO_StartDMA();
200 
201 /*!
202  * \fn void AUDIO_StopDMA()
203  * \brief Stop the previously started audio DMA operation.
204  *
205  * \return none
206  */
207 void AUDIO_StopDMA();
208 
209 /*!
210  * \fn u32 AUDIO_GetDMABytesLeft()
211  * \brief Get the count of bytes, left to play, from the audio DMA interface
212  *
213  * \return count of bytes left to play.
214  */
215 u32 AUDIO_GetDMABytesLeft();
216 
217 /*!
218  * \fn u32 AUDIO_GetDMALength()
219  * \brief Get the DMA transfer length configured in the audio DMA interface.
220  *
221  * \return length of data loaded into the audio DMA interface.
222  */
223 u32 AUDIO_GetDMALength();
224 
225 /*!
226  * \fn u32 AUDIO_GetDMAStartAddr()
227  * \brief Get the main memory address for the DMA operation.
228  *
229  * \return start address of mainmemory loaded into the audio DMA interface.
230  */
231 u32 AUDIO_GetDMAStartAddr();
232 
233 /*!
234  * \fn void AUDIO_SetStreamTrigger(u32 cnt)
235  * \brief Set the sample count for the stream trigger
236  *
237  * \param[in] cnt count of samples when to trigger the audio stream.
238  *
239  * \return none
240  */
241 void AUDIO_SetStreamTrigger(u32 cnt);
242 
243 /*!
244  * \fn void AUDIO_ResetStreamSampleCnt()
245  * \brief Reset the stream sample count register.
246  *
247  * \return none
248  */
249 void AUDIO_ResetStreamSampleCnt();
250 
251 /*!
252  * \fn void AUDIO_SetDSPSampleRate(u8 rate)
253  * \brief Set the sampling rate for the DSP interface
254  *
255  * \param[in] rate sampling rate to set for the DSP (AI_SAMPLERATE_32KHZ,AI_SAMPLERATE_48KHZ)
256  *
257  * \return none
258  */
259 void AUDIO_SetDSPSampleRate(u8 rate);
260 
261 /*!
262  * \fn u32 AUDIO_GetDSPSampleRate()
263  * \brief Get the sampling rate for the DSP interface
264  *
265  * \return DSP sampling rate (AI_SAMPLERATE_32KHZ,AI_SAMPLERATE_48KHZ)
266  */
267 u32 AUDIO_GetDSPSampleRate();
268 
269 /*!
270  * \fn void AUDIO_SetStreamPlayState(u32 state)
271  * \brief Set the play state for the streaming audio interface
272  *
273  * \param[in] state playstate of the streaming audio interface (AI_STREAM_STOP,AI_STREAM_START)
274  *
275  * \return none
276  */
277 void AUDIO_SetStreamPlayState(u32 state);
278 
279 /*!
280  * \fn u32 AUDIO_GetStreamPlayState()
281  * \brief Get the play state from the streaming audio interface
282  *
283  * \return playstate (AI_STREAM_STOP,AI_STREAM_START)
284  */
285 u32 AUDIO_GetStreamPlayState();
286 
287 #ifdef __cplusplus
288    }
289 #endif /* __cplusplus */
290 
291 #endif
292