1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - dspcomponents - include - dsp - audio
3   File:     g711.h
4 
5   Copyright 2007-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifndef DSP_AUDIO_G711_H__
18 #define DSP_AUDIO_G711_H__
19 
20 
21 #include <twl/dsp/common/pipe.h>
22 #include <twl/dsp/common/audio.h>
23 
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 
30 /*---------------------------------------------------------------------------*/
31 /* Functions */
32 
33 #ifdef SDK_TWL
34 
35 /*---------------------------------------------------------------------------*
36  * Internal core functions placed on LTDMAIN
37  *---------------------------------------------------------------------------*/
38 
39 void DSPi_OpenStaticComponentG711Core(FSFile *file);
40 BOOL DSPi_LoadG711Core(FSFile *file, int slotB, int slotC);
41 void DSPi_UnloadG711Core(void);
42 void DSPi_EncodeG711Core(void *dst, const void *src, u32 len, DSPAudioCodecMode mode);
43 void DSPi_DecodeG711Core(void *dst, const void *src, u32 len, DSPAudioCodecMode mode);
44 BOOL DSPi_TryWaitForG711Core(void);
45 void DSPi_WaitForG711Core(void);
46 
47 /*---------------------------------------------------------------------------*
48   Name:         DSP_OpenStaticComponentG711
49 
50   Description:  Opens the memory file for a G.711 component.
51                 Although you will no longer have to make file system preparations in advance, this will be linked as static memory and thus increase the program size.
52 
53 
54   Arguments:    file: The FSFile structure to open the memory file.
55 
56   Returns:      None.
57  *---------------------------------------------------------------------------*/
DSP_OpenStaticComponentG711(FSFile * file)58 SDK_INLINE void DSP_OpenStaticComponentG711(FSFile *file)
59 {
60     if (OS_IsRunOnTwl())
61     {
62         DSPi_OpenStaticComponentG711Core(file);
63     }
64 }
65 
66 /*---------------------------------------------------------------------------*
67   Name:         DSP_LoadG711
68 
69   Description:  Loads a component that supports the G.711 encoding method into the DSP.
70 
71   Arguments:    file: G.711 component file.
72                 slotB: WRAM-B that was allowed to be used for code memory.
73                 slotC: WRAM-C that was allowed to be used for data memory.
74 
75   Returns:      TRUE if the G.711 component is loaded properly in the DSP.
76  *---------------------------------------------------------------------------*/
DSP_LoadG711(FSFile * file,int slotB,int slotC)77 SDK_INLINE BOOL DSP_LoadG711(FSFile *file, int slotB, int slotC)
78 {
79     if (OS_IsRunOnTwl())
80     {
81         return DSPi_LoadG711Core(file, slotB, slotC);
82     }
83     return FALSE;
84 }
85 
86 /*---------------------------------------------------------------------------*
87   Name:         DSP_UnloadG711
88 
89   Description:  Unloads a component that supports the G.711 encoding method from the DSP.
90 
91   Arguments:    None.
92 
93   Returns:      None.
94  *---------------------------------------------------------------------------*/
DSP_UnloadG711(void)95 SDK_INLINE void DSP_UnloadG711(void)
96 {
97     if (OS_IsRunOnTwl())
98     {
99         DSPi_UnloadG711Core();
100     }
101 }
102 
103 /*---------------------------------------------------------------------------*
104   Name:         DSP_EncodeG711
105 
106   Description:  G.711 encoding.
107 
108   Arguments:    dst: Destination buffer for data conversion. (8-bit A-law/u-law)
109                 src: Buffer with the data to convert. (16-bit PCM)
110                 len: Number of samples to convert.
111                 mode: Codec type.
112 
113   Returns:      None.
114  *---------------------------------------------------------------------------*/
DSP_EncodeG711(void * dst,const void * src,u32 len,DSPAudioCodecMode mode)115 SDK_INLINE void DSP_EncodeG711(void *dst, const void *src, u32 len, DSPAudioCodecMode mode)
116 {
117     if (OS_IsRunOnTwl())
118     {
119         DSPi_EncodeG711Core(dst, src, len, mode);
120     }
121 }
122 
123 /*---------------------------------------------------------------------------*
124   Name:         DSP_DecodeG711
125 
126   Description:  G.711 decoding.
127 
128   Arguments:    dst: Destination buffer for data conversion. (16-bit PCM)
129                 src: Buffer with the data to convert. (8-bit A-law/u-law)
130                 len: Number of samples to convert.
131                 mode: Codec type.
132 
133   Returns:      None.
134  *---------------------------------------------------------------------------*/
DSP_DecodeG711(void * dst,const void * src,u32 len,DSPAudioCodecMode mode)135 SDK_INLINE void DSP_DecodeG711(void *dst, const void *src, u32 len, DSPAudioCodecMode mode)
136 {
137     if (OS_IsRunOnTwl())
138     {
139         DSPi_DecodeG711Core(dst, src, len, mode);
140     }
141 }
142 
143 /*---------------------------------------------------------------------------*
144   Name:         DSP_TryWaitForG711
145 
146   Description:  Determines whether the last issued command has completed.
147 
148   Arguments:    None.
149 
150   Returns:      TRUE if the last issued command has completed.
151  *---------------------------------------------------------------------------*/
DSP_TryWaitForG711(void)152 SDK_INLINE BOOL DSP_TryWaitForG711(void)
153 {
154     if (OS_IsRunOnTwl())
155     {
156         return DSPi_TryWaitForG711Core();
157     }
158     return FALSE;
159 }
160 
161 /*---------------------------------------------------------------------------*
162   Name:         DSP_WaitForG711
163 
164   Description:  Waits for the last issued command to complete.
165 
166   Arguments:    None.
167 
168   Returns:      None.
169  *---------------------------------------------------------------------------*/
DSP_WaitForG711(void)170 SDK_INLINE void DSP_WaitForG711(void)
171 {
172     if (OS_IsRunOnTwl())
173     {
174         DSPi_WaitForG711Core();
175     }
176 }
177 
178 #else
179 
180 void DSP_EncodeG711(void *dst, const void *src, u32 len, DSPAudioCodecMode mode);
181 void DSP_DecodeG711(void *dst, const void *src, u32 len, DSPAudioCodecMode mode);
182 
183 #endif // SDK_TWL
184 
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 
191 #endif // DSP_AUDIO_G711_H__
192