RetroArch
asndlib.h
Go to the documentation of this file.
1 /* ASNDLIB -> accelerated sound lib using the DSP
2 
3 Copyright (c) 2008 Hermes <www.entuwii.net>
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are
7 permitted provided that the following conditions are met:
8 
9 - Redistributions of source code must retain the above copyright notice, this list of
10  conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright notice, this list
12  of conditions and the following disclaimer in the documentation and/or other
13  materials provided with the distribution.
14 - The names of the contributors may not be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
25 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 */
28 
29 
30 #ifndef __ASNDLIB_H__
31 #define __ASNDLIB_H__
32 
33 #define __SNDLIB_H__
34 
41 #define ASND_LIB 0x100
42 #define SND_LIB (ASND_LIB+2)
43 
44 #include <gctypes.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
53 #define SND_OK 0
54 #define SND_INVALID -1
55 #define SND_ISNOTASONGVOICE -2
56 #define SND_BUSY 1
57 
62 #define SND_UNUSED 0
63 #define SND_WORKING 1
64 #define SND_WAITING 2
70 #define VOICE_MONO_8BIT 0
71 #define VOICE_MONO_16BIT 1
72 #define VOICE_MONO_16BIT_BE 1
73 #define VOICE_STEREO_8BIT 2
74 #define VOICE_STEREO_16BIT 3
75 #define VOICE_STEREO_16BIT_BE 3
76 #define VOICE_MONO_8BIT_U 4
77 #define VOICE_MONO_16BIT_LE 5
78 #define VOICE_STEREO_8BIT_U 6
79 #define VOICE_STEREO_16BIT_LE 7
80 
85 #define MIN_VOLUME 0
86 #define MID_VOLUME 127
87 #define MAX_VOLUME 255
88 
93 #define MIN_PITCH 1
94 #define F44100HZ_PITCH 44100
95 #define MAX_PITCH 144000
96 #define INIT_RATE_48000
97 
102 enum
103 {
121 };
122 
123 enum
124 {
142 };
143 
144 #define NOTE(note,octave) (note+(octave<<3)+(octave<<2))
147 /*------------------------------------------------------------------------------------------------------------------------------------------------------*/
148 
153 #define Note2Freq ANote2Freq
154 #define SND_Init ASND_Init
155 #define SND_End ASND_End
156 #define SND_Pause ASND_Pause
157 #define SND_Is_Paused ASND_Is_Paused
158 #define SND_GetTime ASND_GetTime
159 #define SND_GetSampleCounter ASND_GetSampleCounter
160 #define SND_GetSamplesPerTick ASND_GetSamplesPerTick
161 #define SND_SetTime ASND_SetTime
162 #define SND_SetCallback ASND_SetCallback
163 #define SND_GetAudioRate ASND_GetAudioRate
164 #define SND_SetVoice ASND_SetVoice
165 #define SND_AddVoice ASND_AddVoice
166 #define SND_StopVoice ASND_StopVoice
167 #define SND_PauseVoice ASND_PauseVoice
168 #define SND_StatusVoice ASND_StatusVoice
169 #define SND_GetFirstUnusedVoice ASND_GetFirstUnusedVoice
170 #define SND_ChangePitchVoice ASND_ChangePitchVoice
171 #define SND_ChangeVolumeVoice ASND_ChangeVolumeVoice
172 #define SND_ChangeVolumeVoice ASND_ChangeVolumeVoice
173 #define SND_GetTickCounterVoice ASND_GetTickCounterVoice
174 #define SND_GetTimerVoice ASND_GetTimerVoice
175 #define SND_TestPointer ASND_TestPointer
176 
178 /*------------------------------------------------------------------------------------------------------------------------------------------------------*/
179 
181 typedef void (*ASNDVoiceCallback)(s32 voice);
182 
183 /*------------------------------------------------------------------------------------------------------------------------------------------------------*/
184 
190 int ANote2Freq(int note, int freq_base,int note_base);
191 
192 /*------------------------------------------------------------------------------------------------------------------------------------------------------*/
193 
200 void ASND_Init();
201 
204 void ASND_End();
205 
210 void ASND_Pause(s32 paused);
211 
215 
219 u32 ASND_GetTime();
220 
226 
230 
235 void ASND_SetTime(u32 time);
236 
241 void ASND_SetCallback(void (*callback)());
242 
247 
254 // NOTE: I'm keeping this description around because I couldn't fully understand it; if someone else knows exactly what it's doing, they can come around
255 // and make sure the description is correct.
256 /* callback: can be NULL or one callback function is used to implement a double buffer use. When the second buffer is empty, the callback is called sending
257  the voice number as parameter. You can use "void callback(s32 voice)" function to call ASND_AddVoice() and add one voice to the second buffer.
258  NOTE: When callback is fixed the voice never stops and it turn in SND_WAITING status if success one timeout condition.
259 */
260 
278 s32 ASND_SetVoice(s32 voice, s32 format, s32 pitch,s32 delay, void *snd, s32 size_snd, s32 volume_l, s32 volume_r, ASNDVoiceCallback callback);
279 
282 s32 ASND_SetInfiniteVoice(s32 voice, s32 format, s32 pitch,s32 delay, void *snd, s32 size_snd, s32 volume_l, s32 volume_r);
283 
290 s32 ASND_AddVoice(s32 voice, void *snd, s32 size_snd);
291 
297 s32 ASND_StopVoice(s32 voice);
298 
302 s32 ASND_PauseVoice(s32 voice, s32 pause);
303 
307 s32 ASND_StatusVoice(s32 voice);
308 
314 
319 s32 ASND_ChangePitchVoice(s32 voice, s32 pitch);
320 
327 s32 ASND_ChangeVolumeVoice(s32 voice, s32 volume_l, s32 volume_r);
328 
337 
344 u32 ASND_GetTimerVoice(s32 voice);
345 
352 s32 ASND_TestPointer(s32 voice, void *pointer);
353 
362 
373 
375 
378 #ifdef __cplusplus
379  }
380 #endif
381 
382 #endif
383 
Definition: asndlib.h:119
Definition: asndlib.h:132
u32 ASND_GetTimerVoice(s32 voice)
Returns the voice playback time.
Definition: asndlib.h:137
Definition: asndlib.h:129
int32_t s32
32bit signed integer
Definition: gctypes.h:24
s32 ASND_GetAudioRate()
Returns the current audio rate.
Definition: asndlib.h:141
Definition: asndlib.h:105
Definition: asndlib.h:111
Definition: asndlib.h:113
Definition: asndlib.h:140
Data type definitions.
s32 ASND_StatusVoice(s32 voice)
Returns the status of the selected voice.
s32 ASND_StopVoice(s32 voice)
Stops the selected voice.
Definition: asndlib.h:116
s32 ASND_Is_Paused()
Returns sound paused status.
s32 ASND_GetFirstUnusedVoice()
Returns the first unused voice.
Definition: asndlib.h:128
Definition: asndlib.h:126
GLsizei const GLvoid * pointer
Definition: glext.h:6488
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: asndlib.h:127
s32 ASND_SetVoice(s32 voice, s32 format, s32 pitch, s32 delay, void *snd, s32 size_snd, s32 volume_l, s32 volume_r, ASNDVoiceCallback callback)
Sets a PCM voice to play.
u32 ASND_GetTickCounterVoice(s32 voice)
Returns the voice tick counter.
Definition: asndlib.h:131
Definition: asndlib.h:115
s32 ASND_SetInfiniteVoice(s32 voice, s32 format, s32 pitch, s32 delay, void *snd, s32 size_snd, s32 volume_l, s32 volume_r)
Sets a PCM voice to play infinitely.
void callback(s32 result, dvdcmdblk *block)
Definition: dvd.c:2293
void ASND_Init()
Initializes the ASND lib and fixes the hardware sample rate to 48000.
Definition: asndlib.h:109
Definition: asndlib.h:114
s32 ASND_TestVoiceBufferReady(s32 voice)
Tests to determine if the voice is ready to receive a new buffer sample with ASND_AddVoice().
Definition: asndlib.h:134
void ASND_End()
De-initializes the ASND lib.
s32 ASND_AddVoice(s32 voice, void *snd, s32 size_snd)
Adds a PCM voice to play from the second buffer.
u32 ASND_GetTime()
Returns the global time.
Definition: asndlib.h:125
Definition: asndlib.h:108
s32 ASND_TestPointer(s32 voice, void *pointer)
Tests if pointer is in use by voice as a buffer.
void ASND_SetCallback(void(*callback)())
Sets a global callback for general purposes.
s32 ASND_ChangeVolumeVoice(s32 voice, s32 volume_l, s32 volume_r)
Changes the voice volume in real-time.
Definition: asndlib.h:112
u32 ASND_GetDSP_PercentUse()
Returns the DSP usage.
time_t time(time_t *timer)
s32 ASND_ChangePitchVoice(s32 voice, s32 pitch)
Changes the voice pitch in real-time.
s32 ASND_PauseVoice(s32 voice, s32 pause)
Pauses the selected voice.
void(* ASNDVoiceCallback)(s32 voice)
Callback type for ASND_SetVoice().
Definition: asndlib.h:181
u32 ASND_GetDSP_ProcessTime()
Definition: asndlib.h:104
void ASND_SetTime(u32 time)
Set the global time.
u32 ASND_GetSampleCounter()
Retrieves the global sample counter.
Definition: asndlib.h:110
Definition: asndlib.h:130
Definition: asndlib.h:133
Definition: asndlib.h:138
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:6293
Definition: asndlib.h:120
Definition: asndlib.h:107
int ANote2Freq(int note, int freq_base, int note_base)
Initializes the SND lib and fixes the hardware sample rate.
Definition: asndlib.h:106
Definition: asndlib.h:118
void ASND_Pause(s32 paused)
Used to pause (or unpause) the sound.
Definition: asndlib.h:136
Definition: asndlib.h:117
uint32_t u32
32bit unsigned integer
Definition: gctypes.h:19
Definition: asndlib.h:139
Definition: ibxm.c:36
u32 ASND_GetSamplesPerTick()
Retrieves the samples sent from the IRQ in one tick.
Definition: asndlib.h:135