2017-03-02 00:40:55 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AudioHardwareSA.h"
|
|
|
|
|
2017-10-20 00:58:06 +02:00
|
|
|
class CAEWaveDecoder final : public CAEStreamingDecoder
|
2017-03-02 00:40:55 +01:00
|
|
|
{
|
|
|
|
private:
|
2017-03-03 21:20:30 +01:00
|
|
|
uint32_t m_dataSize;
|
|
|
|
uint32_t m_offsetToData;
|
2017-05-14 00:29:45 +02:00
|
|
|
size_t m_maxBlockSize = 0;
|
2018-02-11 14:11:00 +01:00
|
|
|
uint8_t* m_buffer = nullptr;
|
2017-03-02 00:40:55 +01:00
|
|
|
|
|
|
|
struct FormatChunk
|
|
|
|
{
|
2017-03-03 21:20:30 +01:00
|
|
|
uint16_t audioFormat;
|
|
|
|
uint16_t numChannels;
|
|
|
|
uint32_t sampleRate;
|
|
|
|
uint32_t byteRate;
|
|
|
|
uint16_t blockAlign;
|
|
|
|
uint16_t bitsPerSample;
|
|
|
|
} m_formatChunk;
|
2017-03-02 00:40:55 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CAEWaveDecoder(CAEDataStream* stream)
|
2017-05-14 00:29:45 +02:00
|
|
|
: CAEStreamingDecoder(stream)
|
2017-03-02 00:40:55 +01:00
|
|
|
{}
|
|
|
|
|
2017-03-03 21:20:30 +01:00
|
|
|
virtual ~CAEWaveDecoder() override
|
|
|
|
{
|
|
|
|
delete[] m_buffer;
|
|
|
|
}
|
|
|
|
|
2017-03-02 00:40:55 +01:00
|
|
|
virtual bool Initialise() override;
|
2017-03-02 01:35:13 +01:00
|
|
|
virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override;
|
2017-03-02 00:40:55 +01:00
|
|
|
|
2017-10-20 00:58:06 +02:00
|
|
|
virtual uint32_t GetStreamLengthMs() const override
|
2017-03-03 21:20:30 +01:00
|
|
|
{ return (static_cast<uint64_t>(m_dataSize) * 1000) / m_formatChunk.blockAlign; }
|
2017-10-20 00:58:06 +02:00
|
|
|
virtual uint32_t GetStreamPlayTimeMs() const override
|
2017-03-03 21:20:30 +01:00
|
|
|
{ return (static_cast<uint64_t>(GetStream()->GetCurrentPosition() - m_offsetToData) * 1000) / m_formatChunk.blockAlign; }
|
2017-03-02 00:40:55 +01:00
|
|
|
|
2017-03-02 01:35:13 +01:00
|
|
|
virtual void SetCursor(uint32_t nTime) override
|
2017-03-03 21:20:30 +01: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 );
|
|
|
|
}
|
2017-03-02 00:40:55 +01:00
|
|
|
|
2017-10-20 00:58:06 +02:00
|
|
|
virtual uint32_t GetSampleRate() const override
|
2017-03-03 21:20:30 +01:00
|
|
|
{ return m_formatChunk.sampleRate; }
|
2017-03-02 00:40:55 +01:00
|
|
|
|
2017-10-20 00:58:06 +02:00
|
|
|
virtual uint32_t GetStreamID() const override
|
2017-03-02 00:40:55 +01:00
|
|
|
{ return GetStream()->GetID(); }
|
2017-03-03 21:20:30 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
size_t CalcBufferSize( uint32_t outputBuf );
|
2017-03-02 00:40:55 +01:00
|
|
|
};
|