Skylicht Engine
Loading...
Searching...
No Matches
IWavSubDecoder.h
1#ifndef _SKYLICHTAUDIO_WAVESUBDECODER_
2#define _SKYLICHTAUDIO_WAVESUBDECODER_
3
4#include "WavHeader.h"
5#include "Stream/IStream.h"
6#include "Driver/ISoundSource.h"
7#include "AudioDebugLog.h"
8
9namespace Skylicht
10{
11 namespace Audio
12 {
13 class IWavSubDecoder
14 {
15 public:
16 IWavSubDecoder(IStreamCursor* streamCursor, SWaveChunk* waveChunks)
17 :m_streamCursor(streamCursor),
18 m_waveChunks(waveChunks),
19 m_currentDataNode(0),
20 m_currentChunkPosition(0),
21 m_decodedSamples(0),
22 m_loop(false),
23 m_isDecoderInError(false)
24 {
25 }
26
27 virtual ~IWavSubDecoder()
28 {
29 }
30
31 const STrackParams& getTrackParams()
32 {
33 return m_trackParams;
34 }
35
36 virtual int decode(void* buffer, int size) = 0;
37
38 virtual int seek(int size) = 0;
39
40 inline void setLoop(bool b)
41 {
42 m_loop = b;
43 }
44
45 protected:
46 IStreamCursor* m_streamCursor;
47
48 SWaveChunk* m_waveChunks;
49 SDataNode* m_currentDataNode;
50 STrackParams m_trackParams;
51
52 int m_currentChunkPosition;
53 int m_decodedSamples;
54 bool m_loop;
55 bool m_isDecoderInError;
56
57 void goToNextDataChunk(void)
58 {
59 if (!(m_waveChunks && m_streamCursor))
60 return;
61
62 if (!m_currentDataNode)
63 {
64 m_currentDataNode = m_waveChunks->DataNodes;
65 }
66 else
67 {
68 if (m_currentDataNode->Next)
69 {
70 m_currentDataNode = m_currentDataNode->Next;
71 }
72 else
73 {
74 m_currentDataNode = NULL;
75 m_waveChunks->DataHeader.ChunkSize = 0;
76 return;
77 }
78 }
79
80 m_streamCursor->seek(m_currentDataNode->FileOffset + ChunkHeaderSize, IStreamCursor::OriginStart);
81 m_waveChunks->DataHeader.ChunkSize = m_currentDataNode->ByteSize;
82 m_currentChunkPosition = 0;
83 }
84 };
85 }
86}
87
88#endif
Interface for a stream cursor, providing seek and read operations on an audio stream.
Definition IStream.h:39
@ OriginStart
Seek from the beginning of the stream.
Definition IStream.h:46
Handles all core audio functionality.
Definition AudioDebugLog.h:31
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition WavHeader.h:69
Definition ISoundSource.h:43
Definition WavHeader.h:109