1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_WaveSoundPlayer.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 /** 19 * :include nw/snd/snd_WaveSoundPlayer.h 20 * 21 * @file snd_WaveSoundPlayer.h 22 */ 23 24 #ifndef NW_SND_WAVE_SOUND_PLAYER_H_ 25 #define NW_SND_WAVE_SOUND_PLAYER_H_ 26 27 #include <nw/snd/snd_BasicSoundPlayer.h> 28 #include <nw/snd/snd_DisposeCallback.h> 29 #include <nw/snd/snd_CurveLfo.h> 30 #include <nw/snd/snd_WaveSoundFileReader.h> // WaveSoundInfo, WaveSoundNoteInfo 31 #include <nw/snd/snd_Channel.h> 32 #include <nw/snd/snd_SoundThread.h> 33 34 namespace nw { 35 namespace snd { 36 37 //--------------------------------------------------------------------------- 38 //! @brief ウェーブサウンドデータのパラメータセットです。 39 //! 40 //! この情報は @ref WaveSoundHandle::ReadWaveSoundDataInfo から取得できます。 41 //! 42 //! @see WaveSoundHandle::ReadWaveSoundDataInfo 43 //! 44 //! @date 2010/03/08 loopStart と loopEnd の型を変更 (unsigned long → u32) 45 //! @date 2010/01/22 初版 46 //--------------------------------------------------------------------------- 47 struct WaveSoundDataInfo 48 { 49 //--------------------------------------------------------------------------- 50 //! @brief ウェーブサウンドデータがループするなら true、 51 //! 終端で終了するなら false となります。 52 //--------------------------------------------------------------------------- 53 bool loopFlag; 54 55 //--------------------------------------------------------------------------- 56 //! @brief ウェーブサウンドデータのサンプリングレートです。 57 //--------------------------------------------------------------------------- 58 int sampleRate; 59 60 //--------------------------------------------------------------------------- 61 //! @brief ウェーブサウンドデータがループする時のループ開始位置を、 62 //! ウェーブサウンドの先頭からのサンプル数で表します。 63 //--------------------------------------------------------------------------- 64 u32 loopStart; 65 66 //--------------------------------------------------------------------------- 67 //! @brief ウェーブサウンドデータがループする時のループ終了位置を、 68 //! ウェーブサウンドの先頭からのサンプル数で表します。 69 //! ループしない時は、データの終端をサンプル数で表します。 70 //! (再生される最後のサンプルの次のサンプルを指します) 71 //--------------------------------------------------------------------------- 72 u32 loopEnd; 73 }; 74 75 namespace internal { 76 namespace driver { 77 78 class WaveSoundPlayer : public BasicSoundPlayer, public DisposeCallback, public SoundThread::PlayerCallback 79 { 80 /* ------------------------------------------------------------------------ 81 constant variable 82 ------------------------------------------------------------------------ */ 83 public: 84 static const int PAUSE_RELEASE_VALUE = 127; 85 static const int MUTE_RELEASE_VALUE = 127; 86 static const int DEFAULT_PRIORITY = 64; 87 88 enum StartOffsetType 89 { 90 START_OFFSET_TYPE_SAMPLE, 91 START_OFFSET_TYPE_MILLISEC 92 }; 93 94 95 struct WaveSoundCallbackArg 96 { 97 const void* wsdFile; // メモリ上のウェーブサウンドファイル 98 int wsdIndex; // bcwsd 内での当該 WSD インデックス 99 int noteIndex; // 現状ではつねにゼロ 100 u32 callbackData; // SoundArchivePlayer::PrepareWaveSoundImpl にて fileId が入る 101 // (が、CTR では無視される) 102 const PlayerHeapDataManager* dataMgr; 103 }; 104 105 class WaveSoundCallback 106 { 107 public: ~WaveSoundCallback()108 virtual ~WaveSoundCallback() {} 109 110 virtual bool GetWaveSoundData( 111 WaveSoundInfo* info, 112 WaveSoundNoteInfo* noteInfo, 113 WaveInfo* waveData, 114 const WaveSoundCallbackArg& arg 115 ) const = 0; 116 }; 117 118 /* ------------------------------------------------------------------------ 119 class member 120 ------------------------------------------------------------------------ */ 121 public: 122 WaveSoundPlayer(); 123 124 virtual void Initialize(); 125 virtual void Finalize(); 126 127 bool Prepare( 128 const void* waveSoundBase, 129 int index, 130 StartOffsetType startOffsetType, 131 int startOffset, 132 const WaveSoundCallback* callback, 133 u32 callbackData 134 ); 135 virtual void Start(); 136 virtual void Stop(); 137 virtual void Pause( bool flag ); 138 139 //------------------------------------------------------------------ 140 // プレイヤーパラメータ 141 142 void SetPanRange( float panRange ); 143 void SetChannelPriority( int priority ); 144 void SetReleasePriorityFix( bool fix ); 145 GetPanRange()146 float GetPanRange() const { return m_PanRange; } GetChannelPriority()147 int GetChannelPriority() const { return m_Priority; } 148 149 // invalidate 150 151 virtual void InvalidateData( const void* start, const void* end ); 152 153 // info 154 155 bool ReadWaveSoundDataInfo( WaveSoundDataInfo* info ) const; 156 s32 GetPlaySamplePosition() const; 157 158 public: DebugUpdate()159 void DebugUpdate() { if ( m_ActiveFlag ) { Update(); } } 160 161 protected: OnUpdateFrameSoundThread()162 virtual void OnUpdateFrameSoundThread() { Update(); } OnShutdownSoundThread()163 virtual void OnShutdownSoundThread() { Stop(); } 164 165 private: 166 bool m_WavePlayFlag; // チャンネルスタートしたかどうか 167 bool m_ReleasePriorityFixFlag; 168 169 f32 m_PanRange; 170 u8 m_Priority; 171 172 const WaveSoundCallback* m_pCallback; 173 u32 m_CallbackData; 174 175 const void* m_pWaveSoundData; 176 int m_WaveSoundIndex; 177 StartOffsetType m_StartOffsetType; 178 int m_StartOffset; 179 180 CurveLfoParam m_LfoParam; 181 182 WaveSoundInfo m_WaveSoundInfo; 183 184 Channel* m_pChannel; 185 186 void FinishPlayer(); 187 void Update(); IsChannelActive()188 bool IsChannelActive() const { return ( m_pChannel != NULL ) && m_pChannel->IsActive(); } 189 bool StartChannel( const WaveSoundCallback* callback, u32 callbackData ); 190 void CloseChannel(); 191 void UpdateChannel(); GetWaveSoundDataAddress()192 const void* GetWaveSoundDataAddress() const { return m_pWaveSoundData; } 193 static void ChannelCallbackFunc( 194 Channel* dropChannel, 195 Channel::ChannelCallbackStatus status, 196 u32 userData 197 ); 198 }; 199 200 } // namespace nw::snd::internal::driver 201 } // namespace nw::snd::internal 202 } // namespace nw::snd 203 } // namespace nw 204 205 206 #endif /* NW_SND_WAVE_SOUND_PLAYER_H_ */ 207 208