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