/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_HardwareChannel.cpp 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 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include #include #include NW_SND_ADAPTIVE_SOURCE( HardwareChannel ) namespace nw { namespace snd { namespace internal { namespace driver { /* ======================================================================== static function ======================================================================== */ void HardwareChannel::CalcOffsetDspAdpcmParam( u16* outPredScale, u16* outYn1, u16* outYn2, u32 offset, const void* dataAddr, const DspAdpcmParam& adpcmParam ) { DspAdpcmParameterBlock adpcm; std::memcpy( adpcm.a, adpcmParam.coef, sizeof(u16)*16 ); adpcm.gain = 0; // adpcmParam.gain; adpcm.predScale = adpcmParam.predScale; adpcm.yn1 = adpcmParam.yn1; adpcm.yn2 = adpcmParam.yn2; DspAddress currentPos = GetDspAddressBySample( dataAddr, 0, SAMPLE_FORMAT_DSP_ADPCM ); DspAddress endPos = GetDspAddressBySample( dataAddr, offset, SAMPLE_FORMAT_DSP_ADPCM ); while ( currentPos < endPos ) { // 8バイトごとのpred scaleを読み取る if ( ! (currentPos & 0xf) ) { u8 byte = *reinterpret_cast( OS_PhysicalToCached( currentPos >> 1 ) ); adpcm.predScale = (u16)byte; currentPos += 2; } u8 byte = *reinterpret_cast( OS_PhysicalToCached( currentPos >> 1 ) ); u8 nibble; if ( currentPos & 0x1 ) { nibble = static_cast( byte & 0xf ); } else { nibble = static_cast( byte >> 4 ); } #ifdef NW_PLATFORM_CTRWIN AX_DecodeDspAdpcm( &adpcm, nibble ); #else nn::dspsnd::CTR::Dspsnd::DecodeAdpcmNibble( reinterpret_cast(&adpcm), nibble ); #endif currentPos++; } *outPredScale = adpcm.predScale; *outYn1 = adpcm.yn1; *outYn2 = adpcm.yn2; } /* ======================================================================== member function ======================================================================== */ HardwareChannel::HardwareChannel() : m_pWaveData( NULL ), m_IsReserveForFree( false ), m_Callback( NULL ), m_pCallbackData( NULL ) { Initialize(); } HardwareChannel::~HardwareChannel() { } void HardwareChannel::ClearParamBlock() { m_pVpb = NULL; m_SyncFlag = 0; } void HardwareChannel::Initialize( const void* waveAddr, SampleFormat format, int sampleRate ) { m_pWaveData = waveAddr; m_Format = format; m_SampleRate = sampleRate; OnInitialize(); } void HardwareChannel::SetLoopStart( const void* baseAddress, u32 samples ) { if ( ! IsAvailable() ) return; DspAddress dspAddress = GetDspAddressBySample( baseAddress, samples, m_Format ); SetVoiceLoopAddr( dspAddress ); } void HardwareChannel::SetLoopEnd( const void* baseAddress, u32 samples ) { if ( ! IsAvailable() ) return; DspAddress dspAddress = GetDspAddressBySample( baseAddress, samples-1, m_Format ); SetVoiceEndAddr( dspAddress ); } bool HardwareChannel::IsDataAddressCovered( const void* begin, const void* end ) const { if ( ! IsAvailable() ) { return false; } if ( m_pWaveData == NULL ) { return false; } if ( begin <= m_pWaveData && m_pWaveData <= end ) { return true; } else { return false; } } void HardwareChannel::SetLpf( u16 /*freq*/ ) {} // TODO: void HardwareChannel::SetBiquad( u8 /*filterType*/, f32 /*value*/ ) {} // TODO: void HardwareChannel::SetPriority( u32 /*priority*/ ) {} // TODO: void HardwareChannel::ChannelCallback( void* callbackData ) { ParameterBlock* dropVpb = reinterpret_cast( callbackData ); HardwareChannel* pChannel = reinterpret_cast( dropVpb->userContext ); NW_NULL_ASSERT( pChannel ); pChannel->ClearParamBlock(); // 解放処理に時間がかかるので、割り込み禁止期間が延びないように // 後で処理を行うようにする。 HardwareChannelManager::GetInstance().ReserveForFreeHardwareChannel( pChannel ); } } // namespace nw::snd::internal::driver } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw