Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 44100 * 20.4 = 899640
- size_t SoundEffect::GetSampleDurationMS() const
- {
- if ( !pImpl->mWaveFormat || !pImpl->mWaveFormat->nSamplesPerSec )
- return 0;
- uint64_t samples = GetSampleDuration();
- return static_cast<size_t>( ( samples * 1000 ) / pImpl->mWaveFormat->nSamplesPerSec );
- }
- size_t SoundEffect::GetSampleDuration() const
- {
- if ( !pImpl->mWaveFormat || !pImpl->mWaveFormat->nChannels )
- return 0;
- switch( GetFormatTag( pImpl->mWaveFormat ) )
- {
- case WAVE_FORMAT_ADPCM:
- {
- auto adpcmFmt = reinterpret_cast<const ADPCMWAVEFORMAT*>( pImpl->mWaveFormat );
- uint64_t duration = uint64_t( pImpl->mAudioBytes / adpcmFmt->wfx.nBlockAlign ) * adpcmFmt->wSamplesPerBlock;
- int partial = pImpl->mAudioBytes % adpcmFmt->wfx.nBlockAlign;
- if ( partial )
- {
- if ( partial >= ( 7 * adpcmFmt->wfx.nChannels ) )
- duration += ( partial * 2 / adpcmFmt->wfx.nChannels - 12 );
- }
- return static_cast<size_t>( duration );
- }
- #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
- case WAVE_FORMAT_WMAUDIO2:
- case WAVE_FORMAT_WMAUDIO3:
- if ( pImpl->mSeekTable && pImpl->mSeekCount > 0 )
- {
- return pImpl->mSeekTable[ pImpl->mSeekCount - 1 ] / uint32_t( 2 * pImpl->mWaveFormat->nChannels );
- }
- break;
- #endif
- #if defined(_XBOX_ONE) && defined(_TITLE)
- case WAVE_FORMAT_XMA2:
- return reinterpret_cast<const XMA2WAVEFORMATEX*>( pImpl->mWaveFormat )->SamplesEncoded;
- #endif
- default:
- if ( pImpl->mWaveFormat->wBitsPerSample > 0 )
- {
- return static_cast<size_t>( ( uint64_t( pImpl->mAudioBytes ) * 8 )
- / uint64_t( pImpl->mWaveFormat->wBitsPerSample * pImpl->mWaveFormat->nChannels ) );
- }
- }
- return 0;
- }
- inline uint32_t GetFormatTag( const WAVEFORMATEX* wfx )
- {
- if ( wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE )
- {
- if ( wfx->cbSize < ( sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) ) )
- return 0;
- static const GUID s_wfexBase = {0x00000000, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
- auto wfex = reinterpret_cast<const WAVEFORMATEXTENSIBLE*>( wfx );
- if ( memcmp( reinterpret_cast<const BYTE*>(&wfex->SubFormat) + sizeof(DWORD),
- reinterpret_cast<const BYTE*>(&s_wfexBase) + sizeof(DWORD), sizeof(GUID) - sizeof(DWORD) ) != 0 )
- {
- return 0;
- }
- return wfex->SubFormat.Data1;
- }
- else
- {
- return wfx->wFormatTag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement