SilentPatch/SilentPatchSA/WaveDecoderSA.h

55 lines
1.4 KiB
C
Raw Permalink Normal View History

#pragma once
#include "AudioHardwareSA.h"
class CAEWaveDecoder : public CAEStreamingDecoder
{
private:
2017-03-04 01:20:30 +05:00
uint32_t m_dataSize;
uint32_t m_offsetToData;
2017-05-14 03:29:45 +05:00
size_t m_maxBlockSize = 0;
void* m_buffer = nullptr;
struct FormatChunk
{
2017-03-04 01:20:30 +05:00
uint16_t audioFormat;
uint16_t numChannels;
uint32_t sampleRate;
uint32_t byteRate;
uint16_t blockAlign;
uint16_t bitsPerSample;
} m_formatChunk;
public:
CAEWaveDecoder(CAEDataStream* stream)
2017-05-14 03:29:45 +05:00
: CAEStreamingDecoder(stream)
{}
2017-03-04 01:20:30 +05:00
virtual ~CAEWaveDecoder() override
{
delete[] m_buffer;
}
virtual bool Initialise() override;
virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override;
virtual uint32_t GetStreamLengthMs() override
2017-03-04 01:20:30 +05:00
{ return (static_cast<uint64_t>(m_dataSize) * 1000) / m_formatChunk.blockAlign; }
virtual uint32_t GetStreamPlayTimeMs() override
2017-03-04 01:20:30 +05:00
{ return (static_cast<uint64_t>(GetStream()->GetCurrentPosition() - m_offsetToData) * 1000) / m_formatChunk.blockAlign; }
virtual void SetCursor(uint32_t nTime) override
2017-03-04 01:20:30 +05:00
{
uint64_t sampleNum = (static_cast<uint64_t>(nTime) * m_formatChunk.sampleRate) / 1000;
GetStream()->Seek( m_offsetToData + (static_cast<uint32_t>(sampleNum) * m_formatChunk.blockAlign), FILE_BEGIN );
}
virtual uint32_t GetSampleRate() override
2017-03-04 01:20:30 +05:00
{ return m_formatChunk.sampleRate; }
virtual uint32_t GetStreamID() override
{ return GetStream()->GetID(); }
2017-03-04 01:20:30 +05:00
private:
size_t CalcBufferSize( uint32_t outputBuf );
};