/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_WaveSoundPlayer.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ /** * :include nw/snd/snd_WaveSoundPlayer.h * * @file snd_WaveSoundPlayer.h */ #ifndef NW_SND_WAVE_SOUND_PLAYER_H_ #define NW_SND_WAVE_SOUND_PLAYER_H_ #include #include #include #include // WaveSoundInfo, WaveSoundNoteInfo #include #include namespace nw { namespace snd { //--------------------------------------------------------------------------- //! @brief ウェーブサウンドデータのパラメータセットです。 //! //! この情報は @ref WaveSoundHandle::ReadWaveSoundDataInfo から取得できます。 //! //! @see WaveSoundHandle::ReadWaveSoundDataInfo //! //! @date 2010/03/08 loopStart と loopEnd の型を変更 (unsigned long → u32) //! @date 2010/01/22 初版 //--------------------------------------------------------------------------- struct WaveSoundDataInfo { //--------------------------------------------------------------------------- //! @brief ウェーブサウンドデータがループするなら true、 //! 終端で終了するなら false となります。 //--------------------------------------------------------------------------- bool loopFlag; //--------------------------------------------------------------------------- //! @brief ウェーブサウンドデータのサンプリングレートです。 //--------------------------------------------------------------------------- int sampleRate; //--------------------------------------------------------------------------- //! @brief ウェーブサウンドデータがループする時のループ開始位置を、 //! ウェーブサウンドの先頭からのサンプル数で表します。 //--------------------------------------------------------------------------- u32 loopStart; //--------------------------------------------------------------------------- //! @brief ウェーブサウンドデータがループする時のループ終了位置を、 //! ウェーブサウンドの先頭からのサンプル数で表します。 //! ループしない時は、データの終端をサンプル数で表します。 //! (再生される最後のサンプルの次のサンプルを指します) //--------------------------------------------------------------------------- u32 loopEnd; }; namespace internal { namespace driver { class WaveSoundPlayer : public BasicSoundPlayer, public DisposeCallback, public SoundThread::PlayerCallback { /* ------------------------------------------------------------------------ constant variable ------------------------------------------------------------------------ */ public: static const int PAUSE_RELEASE_VALUE = 127; static const int MUTE_RELEASE_VALUE = 127; static const int DEFAULT_PRIORITY = 64; enum StartOffsetType { START_OFFSET_TYPE_SAMPLE, START_OFFSET_TYPE_MILLISEC }; struct WaveSoundCallbackArg { const void* wsdFile; // メモリ上のウェーブサウンドファイル int wsdIndex; // bcwsd 内での当該 WSD インデックス int noteIndex; // 現状ではつねにゼロ u32 callbackData; // SoundArchivePlayer::PrepareWaveSoundImpl にて fileId が入る // (が、CTR では無視される) const PlayerHeapDataManager* dataMgr; }; class WaveSoundCallback { public: virtual ~WaveSoundCallback() {} virtual bool GetWaveSoundData( WaveSoundInfo* info, WaveSoundNoteInfo* noteInfo, WaveInfo* waveData, const WaveSoundCallbackArg& arg ) const = 0; }; /* ------------------------------------------------------------------------ class member ------------------------------------------------------------------------ */ public: WaveSoundPlayer(); virtual void Initialize(); virtual void Finalize(); bool Prepare( const void* waveSoundBase, int index, StartOffsetType startOffsetType, int startOffset, const WaveSoundCallback* callback, u32 callbackData ); virtual void Start(); virtual void Stop(); virtual void Pause( bool flag ); //------------------------------------------------------------------ // プレイヤーパラメータ void SetPanRange( float panRange ); void SetChannelPriority( int priority ); void SetReleasePriorityFix( bool fix ); float GetPanRange() const { return m_PanRange; } int GetChannelPriority() const { return m_Priority; } // invalidate virtual void InvalidateData( const void* start, const void* end ); // info bool ReadWaveSoundDataInfo( WaveSoundDataInfo* info ) const; s32 GetPlaySamplePosition() const; public: void DebugUpdate() { if ( m_ActiveFlag ) { Update(); } } protected: virtual void OnUpdateFrameSoundThread() { Update(); } virtual void OnShutdownSoundThread() { Stop(); } private: bool m_WavePlayFlag; // チャンネルスタートしたかどうか bool m_ReleasePriorityFixFlag; f32 m_PanRange; u8 m_Priority; const WaveSoundCallback* m_pCallback; u32 m_CallbackData; const void* m_pWaveSoundData; int m_WaveSoundIndex; StartOffsetType m_StartOffsetType; int m_StartOffset; CurveLfoParam m_LfoParam; WaveSoundInfo m_WaveSoundInfo; Channel* m_pChannel; void FinishPlayer(); void Update(); bool IsChannelActive() const { return ( m_pChannel != NULL ) && m_pChannel->IsActive(); } bool StartChannel( const WaveSoundCallback* callback, u32 callbackData ); void CloseChannel(); void UpdateChannel(); const void* GetWaveSoundDataAddress() const { return m_pWaveSoundData; } static void ChannelCallbackFunc( Channel* dropChannel, Channel::ChannelCallbackStatus status, u32 userData ); }; } // namespace nw::snd::internal::driver } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw #endif /* NW_SND_WAVE_SOUND_PLAYER_H_ */