2017-03-02 04:40:55 +05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AudioHardwareSA.h"
|
|
|
|
|
|
|
|
class CAEWaveDecoder : public CAEStreamingDecoder
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
unsigned int nDataSize;
|
|
|
|
unsigned int nOffsetToData;
|
|
|
|
//bool bInitialised;
|
|
|
|
|
|
|
|
struct FormatChunk
|
|
|
|
{
|
|
|
|
unsigned short audioFormat;
|
|
|
|
unsigned short numChannels;
|
|
|
|
unsigned int sampleRate;
|
|
|
|
unsigned int byteRate;
|
|
|
|
unsigned short blockAlign;
|
|
|
|
unsigned short bitsPerSample;
|
|
|
|
} formatChunk;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CAEWaveDecoder(CAEDataStream* stream)
|
|
|
|
: CAEStreamingDecoder(stream)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual bool Initialise() override;
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override;
|
2017-03-02 04:40:55 +05:00
|
|
|
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual uint32_t GetStreamLengthMs() override
|
2017-03-02 04:40:55 +05:00
|
|
|
{ return static_cast<unsigned long long>(nDataSize) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); }
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual uint32_t GetStreamPlayTimeMs() override
|
2017-03-02 04:40:55 +05:00
|
|
|
{ return static_cast<unsigned long long>(GetStream()->GetCurrentPosition() - nOffsetToData) * 8000 / (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels); }
|
|
|
|
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual void SetCursor(uint32_t nTime) override
|
2017-03-02 04:40:55 +05:00
|
|
|
{ auto nPos = static_cast<unsigned long long>(nTime) * (formatChunk.sampleRate*formatChunk.bitsPerSample*formatChunk.numChannels) / 8000;
|
|
|
|
auto nModulo = (formatChunk.numChannels*formatChunk.bitsPerSample/8);
|
|
|
|
auto nExtra = nPos % nModulo ? nModulo - (nPos % nModulo) : 0;
|
|
|
|
GetStream()->Seek(nOffsetToData + nPos + nExtra, FILE_BEGIN); }
|
|
|
|
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual uint32_t GetSampleRate() override
|
2017-03-02 04:40:55 +05:00
|
|
|
{ return formatChunk.sampleRate; }
|
|
|
|
|
2017-03-02 05:35:13 +05:00
|
|
|
virtual uint32_t GetStreamID() override
|
2017-03-02 04:40:55 +05:00
|
|
|
{ return GetStream()->GetID(); }
|
|
|
|
};
|