1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     snd_Voice.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  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   $Rev: 38510 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_SND_VOICE_H_
17 #define NN_SND_VOICE_H_
18 
19 #include <nn/os.h>
20 #include <nn/Result.h>
21 
22 #include <nn/snd/CTR/Common/snd_Types.h>
23 
24 #ifdef __cplusplus
25 
26 /* Please see man pages for details
27 
28 */
29 
30 namespace nn  { namespace snd { namespace CTR {
31 
32 /* Please see man pages for details
33 
34 
35 
36 */
37 typedef void (*VoiceDropCallbackFunc)(class Voice *, uptr userArg);
38 
39 class VoiceImpl;
40 class VoiceManager;
41 
42 /* Please see man pages for details
43 
44  */
45 class Voice
46 {
47     friend class VoiceManager;
48 
49 public:
50 
51     /* Please see man pages for details
52 
53      */
54     enum State
55     {
56         STATE_PLAY,  //
57         STATE_STOP,  //
58         STATE_PAUSE  //
59     };
60 
61 private:
62     const s32                           m_Id;                  // Voice number (for management)
63 
64     util::SizedEnum1<State>             m_State;               // Status
65     util::SizedEnum1<InterpolationType> m_InterpolationType;   // Interpolation method
66     NN_PADDING1;
67 
68     util::SizedEnum1<FilterType>        m_FilterType;          // Filter type
69     MonoFilterCoefficients              m_MonoFilterCoeffs;    // Monopole filter coefficient
70     BiquadFilterCoefficients            m_BiquadFilterCoeffs;  // Bipolar filter coefficient
71     NN_PADDING2;
72 
73     s32                                 m_SampleRate;          // Sampling frequency
74     f32                                 m_Pitch;               // Pitch (ratio for SampleRate)
75 
76     s32                                 m_Priority;            // Priority
77     Voice *                             m_PriorVoice;          // Pointer to the Voice with high priority
78     Voice *                             m_InferiorVoice;       // Pointer to the Voice with low priority
79 
80     VoiceDropCallbackFunc               m_Callback;            // Callback function called when Voice is deallocated by the system
81     uptr                                m_UserArg;             // User argument when calling the above callback
82 
83     MixParam                            m_MixParam;            // Gain for each channel
84     f32                                 m_Volume;              // Volume
85 
86     VoiceImpl*                          m_pImpl;
87 
88     void Initialize();
89     void UpdateStatus(const void* pVars);
90     void UpdateWaveBufferList();
GetId()91     s32 GetId() const { return m_Id; }
GetImpl()92     VoiceImpl* GetImpl() const { return m_pImpl; }
93 
94     /* Please see man pages for details
95 
96 
97 
98 
99      */
100     explicit Voice(s32 id);
101 
102     /* Please see man pages for details
103 
104      */
105     ~Voice();
106 
107 public:
108     /* Please see man pages for details
109 
110 
111      */
112     /* Please see man pages for details
113 
114 
115      */
116     void AppendWaveBuffer(WaveBuffer* pBuffer);
117 
118     /* Please see man pages for details
119 
120 
121      */
122     void DeleteWaveBuffer(WaveBuffer* pBuffer);
123 
124     /* Please see man pages for details
125 
126 
127      */
128     void UpdateWaveBuffer(WaveBuffer* pBuffer);
129 
130     /*
131 
132 */
133 
134     /* Please see man pages for details
135 
136 
137      */
138     /* Please see man pages for details
139 
140 
141      */
142     void SetChannelCount(s32 channelCount);
143 
144     /* Please see man pages for details
145 
146 
147      */
148     void SetSampleFormat(SampleFormat format);
149 
150     /* Please see man pages for details
151 
152 
153      */
154     void SetFrontBypassFlag(bool flag);
155 
156     /* Please see man pages for details
157 
158 
159      */
160     void SetStartFrameFadeInFlag(bool flag);
161 
162     /* Please see man pages for details
163 
164 
165      */
166     void SetSampleRate(s32 sampleRate);
167 
168     /* Please see man pages for details
169 
170 
171      */
172     void SetPitch(f32 pitch);
173 
174     /* Please see man pages for details
175 
176 
177      */
178     void SetAdpcmParam(const AdpcmParam& param);
179 
180     /* Please see man pages for details
181 
182 
183      */
184     void SetPriority(s32 priority);
185 
186     /* Please see man pages for details
187 
188 
189      */
190     void SetState(State state);
191 
192     /* Please see man pages for details
193 
194 
195      */
196     void SetMixParam(const MixParam& mixParam);
197 
198     /* Please see man pages for details
199 
200 
201      */
202     void SetVolume(f32 volume);
203 
204     /* Please see man pages for details
205 
206 
207      */
208     void SetInterpolationType(InterpolationType type);
209 
210     /* Please see man pages for details
211 
212 
213      */
214     void SetFilterType(FilterType type);
215 
216     /* Please see man pages for details
217 
218 
219      */
220     void EnableMonoFilter(bool enable);
221 
222     /* Please see man pages for details
223 
224 
225      */
226     void SetMonoFilterCoefficients(const MonoFilterCoefficients* pCoeff) NN_ATTRIBUTE_DEPRECATED;
227 
228     /* Please see man pages for details
229 
230 
231      */
232     void SetMonoFilterCoefficients(const MonoFilterCoefficients& coeff);
233 
234     /* Please see man pages for details
235 
236 
237      */
238     void SetMonoFilterCoefficients(u16 cutoff);
239 
240     /* Please see man pages for details
241 
242 
243      */
244     void EnableBiquadFilter(bool enable);
245 
246     /* Please see man pages for details
247 
248 
249      */
250     void SetBiquadFilterCoefficients(const BiquadFilterCoefficients* pCoeff) NN_ATTRIBUTE_DEPRECATED;
251 
252     /* Please see man pages for details
253 
254 
255      */
256     void SetBiquadFilterCoefficients(const BiquadFilterCoefficients& coeff);
257     /*
258 
259 */
260 
261     /* Please see man pages for details
262 
263 
264      */
265     /* Please see man pages for details
266 
267 
268      */
GetPitch()269     inline f32 GetPitch() const { return m_Pitch; }
270 
271     /* Please see man pages for details
272 
273 
274      */
GetPriority()275     inline s32 GetPriority() const { return m_Priority; }
276 
277     /* Please see man pages for details
278 
279 
280      */
GetState()281     inline Voice::State GetState() const { return m_State; }
282 
283     /* Please see man pages for details
284 
285 
286      */
GetMixParam()287     inline const MixParam& GetMixParam() const { return m_MixParam; }
288 
289     /* Please see man pages for details
290 
291 
292      */
GetVolume()293     inline f32 GetVolume() const { return m_Volume; }
294 
295     /* Please see man pages for details
296 
297 
298      */
GetInterpolationType()299     inline InterpolationType GetInterpolationType() const { return m_InterpolationType; }
300 
301     /* Please see man pages for details
302 
303 
304      */
GetFilterType()305     inline FilterType GetFilterType() const { return m_FilterType; }
306 
307     /* Please see man pages for details
308 
309 
310      */
311     void GetMonoFilterCoefficients(MonoFilterCoefficients* pCoeff) NN_ATTRIBUTE_DEPRECATED;
312 
313     /* Please see man pages for details
314 
315 
316      */
317     void GetMonoFilterCoefficients(MonoFilterCoefficients& coeff);
318 
319     /* Please see man pages for details
320 
321 
322      */
323     void GetBiquadFilterCoefficients(BiquadFilterCoefficients* pCoeff) NN_ATTRIBUTE_DEPRECATED;
324 
325     /* Please see man pages for details
326 
327 
328      */
329     void GetBiquadFilterCoefficients(BiquadFilterCoefficients& coeff);
330     /*
331 
332 */
333 
334     /* Please see man pages for details
335 
336 
337      */
338     /* Please see man pages for details
339 
340 
341      */
342     s32 GetPlayPosition() const;
343 
344     /* Please see man pages for details
345 
346 
347      */
348     bool IsPlaying() const;
349     /*
350 
351 */
352 
353     /* Please see man pages for details
354 
355 
356      */
357     /* Please see man pages for details
358 
359 
360 
361 
362 
363 
364      */
365     bool SetupBcwav(uptr addrBcwav, WaveBuffer* pWaveBuffer0, WaveBuffer* pWaveBuffer1, Bcwav::ChannelIndex channelIndex = Bcwav::CHANNEL_INDEX_L);
366     /*
367 
368 */
369 
370 private:
371     void SetChannelCountCommand(s32 channelCount);
372     void SetSampleFormatCommand(SampleFormat format);
373     void SetFrontBypassFlagCommand(bool flag);
374     void SetStartFrameFadeInFlagCommand(bool flag);
375     void SetSampleRateCommand(s32 sampleRate);
376     void SetPitchCommand(f32 pitch);
377     void SetInterpolationTypeCommand(InterpolationType type);
378     void SetFilterTypeCommand(FilterType type);
379     void EnableMonoFilterCommand(bool enable);
380     void SetMonoFilterCoefficientsCommand(const MonoFilterCoefficients& coeff);
381     void SetMonoFilterCoefficientsCommand(u16 cutoff);
382     void EnableBiquadFilterCommand(bool enable);
383     void SetBiquadFilterCoefficientsCommand(const BiquadFilterCoefficients& coeff);
384     void SetAdpcmParamCommand(const AdpcmParam& param);
385     void SetStateCommand(State state);
386     void SetMixParamCommand(const MixParam& mixParam);
387     void SetVolumeCommand(f32 volume);
388     bool SetupBcwavCommand(uptr addrBcwav, WaveBuffer* pWaveBuffer0, WaveBuffer* pWaveBuffer1, Bcwav::ChannelIndex channelIndex);
389 }; // class Voice
390 
391 /* Please see man pages for details
392 
393 
394  */
395 /* Please see man pages for details
396 
397 
398 
399 
400 
401  */
402 Voice* AllocVoice(s32 priority, VoiceDropCallbackFunc callback, uptr userArg);
403 
404 /* Please see man pages for details
405 
406 
407  */
408 void FreeVoice(Voice* pVoice);
409 /*
410 
411 */
412 
413 }}} // namespace nn::snd::CTR
414 
415 #endif // __cplusplus
416 
417 #endif //NN_SND_VOICE_H_
418