/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_HardwareChannel.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 22284 $ *---------------------------------------------------------------------------*/ #ifndef NW_SND_HARDWARE_CHANNEL_ #define NW_SND_HARDWARE_CHANNEL_ #include #include #include namespace nw { namespace snd { namespace internal { namespace driver { class HardwareChannel { friend class HardwareChannelManager; #ifdef NW_PLATFORM_CTRWIN public: typedef AXVPB ParameterBlock; typedef AXPBMIX MixParameterBlock; typedef AXPBADPCM DspAdpcmParameterBlock; typedef AXPBADPCMLOOP DspAdpcmLoopParameterBlock; #endif public: // ------------------------------------------------------------------------ // コールバック関数 enum HardwareChannelCallbackStatus { CALLBACK_STATUS_CANCEL, CALLBACK_STATUS_DROP_DSP }; typedef void (*HardwareChannelCallback)( HardwareChannel* hardwareChannel, HardwareChannelCallbackStatus status, void* callbackData ); public: typedef u32 DspAddress; static u32 GetSampleByDspAddress( const void* baseAddress, DspAddress addr, SampleFormat format ); static void CalcOffsetDspAdpcmParam( u16* outPredScale, u16* outYn1, u16* outYn2, u32 offset, const void* dataAddr, const DspAdpcmParam& adpcmParam ); private: static DspAddress GetDspAddressBySample( const void* baseAddress, u32 samples, SampleFormat format ); public: HardwareChannel(); ~HardwareChannel(); void SetParamBlock( ParameterBlock* vpb ); void ClearParamBlock(); void Initialize( const void* waveAddr, SampleFormat format, int sampleRate ); bool IsPlaying() const; bool IsPlayFinished() const; SampleFormat GetFormat() const { return m_Format; } void Run(); void Stop(); void Sync(); // アドレス関連関数 void StopAtPoint( const void* baseAddress, u32 samples ); void SetLoopStart( const void* baseAddress, u32 samples = 0 ); void SetLoopEnd( const void* baseAddress, u32 samples ); void SetBaseAddress( const void* baseAddress ) { m_pWaveData = baseAddress; } void SetLoopFlag( bool loopFlag ); u32 GetPlayPosition() const; bool IsCurrentAddressCovered( const void* begin, const void* end ) const; bool IsDataAddressCovered( const void* begin, const void* end ) const; // パラメータ設定関数 void SetAddr( bool loopFlag, const void* waveAddr, u32 startOffset, u32 loopStart, u32 loopEnd ); void SetDspAdpcm( const DspAdpcmParam* param ); void SetDspAdpcmLoop( const DspAdpcmLoopParam* param ); void SetSrcType( SrcType type, f32 pitch ); void SetMixParam( const MixParam& param ); void SetSrc( f32 ratio, bool initialUpdate ); void SetVolume( f32 volume ); void SetLpf( u16 freq ); void SetBiquad( u8 filterType, f32 value ); void SetPriority( u32 priority ); void SetVoiceMix( const MixParameterBlock& mix, bool immediatelySync = false ); bool IsAvailable() const { return m_pVpb != NULL; } private: void Initialize(); void OnInitialize(); DspAddress GetLoopStartDspAddress() const; DspAddress GetLoopEndDspAddress() const; static void ChannelCallback( void *callbackData ); void SetVoiceLoopAddr( u32 addr ); void SetVoiceEndAddr( u32 addr ); void SetVoiceLoop( u32 loop ); static const u16 VOICE_GAIN_MAX = 0x7fff; static const u16 VOLUME_DEFAULT = 0x8000; const void* m_pWaveData; SampleFormat m_Format; int m_SampleRate; bool m_IsReserveForFree; HardwareChannelCallback m_Callback; void* m_pCallbackData; // AxVoiceParamBlock が持っていた値 ParameterBlock* m_pVpb; u32 m_SyncFlag; bool m_IsFirstVeUpdate; public: ut::LinkListNode m_LinkNode; #ifdef NW_PLATFORM_CTRWIN private: DspAddress GetCurrentPlayingDspAddress() const; float GetDspRatio( f32 ratio ) const; #endif }; } // namespace nw::snd::internal::driver } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw #endif /* NW_SND_HARDWARE_CHANNEL_ */