1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_WaveSound.cpp
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  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   $Revision: 20021 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "precompiled.h"
17 
18 #include <nw/snd/snd_WaveSound.h>
19 
20 #include <nn/os.h>
21 #include <nw/snd/snd_SoundInstanceManager.h>
22 #include <nw/snd/snd_DriverCommandManager.h>
23 
24 namespace nw {
25 namespace snd {
26 namespace internal {
27 
28 NW_UT_RUNTIME_TYPEINFO_DEFINITION(WaveSound,BasicSound);
29 
30 /* ========================================================================
31         member function
32    ======================================================================== */
33 
34 /*---------------------------------------------------------------------------*
35   Name:         WaveSound
36 
37   Description:  コンストラクタ
38 
39   Arguments:    None.
40 
41   Returns:      None.
42  *---------------------------------------------------------------------------*/
WaveSound(WaveSoundInstanceManager & manager)43 WaveSound::WaveSound(
44     WaveSoundInstanceManager& manager
45 )
46 : m_pManager( manager ),
47   m_InitializeFlag(false)
48 {
49 }
50 
Initialize()51 void WaveSound::Initialize()
52 {
53     BasicSound::Initialize();
54 
55     m_pTempSpecialHandle = NULL;
56     m_PreparedFlag = false;
57 
58     m_InitializeFlag = true;
59 }
60 
61 /*---------------------------------------------------------------------------*
62   Name:         Shutdown
63 
64   Description:  サウンドの終了
65 
66   Arguments:    None.
67 
68   Returns:      None.
69  *---------------------------------------------------------------------------*/
Finalize()70 void WaveSound::Finalize()
71 {
72     if ( ! m_InitializeFlag ) return;
73     m_InitializeFlag = false;
74 
75     BasicSound::Finalize();
76 
77     m_pManager.Free( this );
78 }
79 
80 /*---------------------------------------------------------------------------*
81   Name:         Prepare
82 
83   Description:  サウンド開始
84 
85   Arguments:    seqDataBase   - シーケンスデータベースアドレス
86                 seqDataOffset - シーケンスデータのオフセット
87                 bank          - バンクデータ
88 
89   Returns:      None.
90  *---------------------------------------------------------------------------*/
Prepare(const void * waveSoundBase,s32 waveSoundOffset,driver::WaveSoundPlayer::StartOffsetType startOffsetType,s32 offset,const driver::WaveSoundPlayer::WaveSoundCallback * callback,u32 callbackData)91 void WaveSound::Prepare(
92     const void* waveSoundBase,
93     s32 waveSoundOffset,
94     driver::WaveSoundPlayer::StartOffsetType startOffsetType,
95     s32 offset,
96     const driver::WaveSoundPlayer::WaveSoundCallback* callback,
97     u32 callbackData
98 )
99 {
100     NW_NULL_ASSERT( waveSoundBase );
101     NW_NULL_ASSERT( callback );
102 
103     DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
104     DriverCommandWaveSoundSetup* command =
105         cmdmgr.AllocCommand<DriverCommandWaveSoundSetup>();
106     command->id = DRIVER_COMMAND_WAVESND_SETUP;
107     command->player = &m_WaveSoundPlayerInstance;
108     command->waveSoundBase = waveSoundBase;
109     command->waveSoundOffset = waveSoundOffset;
110     command->startOffsetType = startOffsetType;
111     command->offset = offset;
112     command->callback = callback;
113     command->callbackData = callbackData;
114     cmdmgr.PushCommand(command);
115 
116 
117     m_PreparedFlag = true;
118 }
119 
120 /*---------------------------------------------------------------------------*
121   Name:         SetChannelPriority
122 
123   Description:  発音プライオリティを変更
124 
125   Arguments:    priority - 発音プライオリティ
126 
127   Returns:      None.
128  *---------------------------------------------------------------------------*/
SetChannelPriority(int priority)129 void WaveSound::SetChannelPriority( int priority )
130 {
131     NW_MINMAX_ASSERT( priority, 0, 127 );
132 
133     DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
134     DriverCommandWaveSoundChannelPrio* command =
135         cmdmgr.AllocCommand<DriverCommandWaveSoundChannelPrio>();
136     command->id = DRIVER_COMMAND_WAVESND_CHANNELPRIO;
137     command->player = &m_WaveSoundPlayerInstance;
138     command->priority = priority;
139     cmdmgr.PushCommand(command);
140 }
141 
142 /*---------------------------------------------------------------------------*
143   Name:         SetReleasePriorityFix
144 
145   Description:  リリース時のプライオリティを変化しないようにする
146 
147   Arguments:    fix -
148 
149   Returns:      なし
150  *---------------------------------------------------------------------------*/
SetReleasePriorityFix(bool fix)151 void WaveSound::SetReleasePriorityFix( bool fix )
152 {
153     DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
154     DriverCommandWaveSoundPrioFix* command =
155         cmdmgr.AllocCommand<DriverCommandWaveSoundPrioFix>();
156     command->id = DRIVER_COMMAND_WAVESND_PRIOFIX;
157     command->player = &m_WaveSoundPlayerInstance;
158     command->priorityFix = fix;
159     cmdmgr.PushCommand(command);
160 }
161 
162 /*---------------------------------------------------------------------------*
163   Name:         OnUpdatePlayerPriority
164 
165   Description:  プレイヤープライオリティを変更
166 
167   Arguments:
168 
169   Returns:      None.
170  *---------------------------------------------------------------------------*/
OnUpdatePlayerPriority()171 void WaveSound::OnUpdatePlayerPriority()
172 {
173     int priority = CalcCurrentPlayerPriority();
174     m_pManager.UpdatePriority( this, priority );
175 }
176 
IsAttachedTempSpecialHandle()177 bool WaveSound::IsAttachedTempSpecialHandle()
178 {
179     return m_pTempSpecialHandle != NULL;
180 }
181 
DetachTempSpecialHandle()182 void WaveSound::DetachTempSpecialHandle()
183 {
184     // TODO: m_pTempSpecialHandle->DetachSound();
185 }
186 
ReadWaveSoundDataInfo(WaveSoundDataInfo * info) const187 bool WaveSound::ReadWaveSoundDataInfo( WaveSoundDataInfo* info ) const
188 {
189     if ( ! IsPlayerAvailable() ) return false;
190     return m_WaveSoundPlayerInstance.ReadWaveSoundDataInfo( info );
191 }
192 
GetPlaySamplePosition() const193 long WaveSound::GetPlaySamplePosition() const
194 {
195     if ( ! IsPlayerAvailable() ) return 0;
196     return m_WaveSoundPlayerInstance.GetPlaySamplePosition();
197 }
198 
199 } // namespace nw::snd::internal
200 } // namespace nw::snd
201 } // namespace nw
202 
203