TDME2  1.9.200
VorbisDecoder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vorbis/vorbisfile.h>
4 
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
9 #include <tdme/tdme.h>
16 
17 using std::string;
18 using std::vector;
19 using std::unique_ptr;
20 
25 
26 /**
27  * OGG/Vorbis audio decoder
28  * @author Andreas Drewke
29  */
31 {
32 private:
33  struct OGGFileData {
34  vector<uint8_t> data;
35  size_t position { 0 };
36  };
37 
38 public:
39  /**
40  * Constructor
41  */
42  inline VorbisDecoder() {}
43 
44  /**
45  * Destructor
46  */
47  inline virtual ~VorbisDecoder() {
48  close();
49  }
50 
51  // overridden methods
52  void openFile(const string& pathName, const string& fileName) override;
53  void reset() override;
54  int64_t readFromStream(ByteBuffer* data) override;
55  void close() override;
56 
57 private:
58  /**
59  * Read from OGG file data
60  * @param buffer buffer to read into
61  * @param size chunk bytes to read
62  * @param count chunk count to read
63  * @param oggFileData pointer to OGG file data
64  */
65  static size_t oggfiledata_read(void* buffer, size_t size, size_t count, VorbisDecoder::OGGFileData* oggFileData);
66 
67  /**
68  * Seek in OGG file data
69  * @param oggFileData OGG file data pointer
70  * @param offset offset (can be relative to position)
71  * @param whence whence see (SEEK_*)
72  */
73  static int oggfiledata_seek(VorbisDecoder::OGGFileData* oggFileData, ogg_int64_t offset, int whence);
74 
75  /**
76  * Close OGG file data
77  * @param oggFileData pointer to OGG file data
78  */
80 
81  /**
82  * Tell position of OGG file data
83  * @param oggFileData pointer to OGG file data
84  * @return current read position
85  */
87 
88  //
89  unique_ptr<OGGFileData> oggFileData;
90  string pathName;
91  string fileName;
92  OggVorbis_File vf;
93  int section { 0 };
94 };
Audio decoder base class.
Definition: AudioDecoder.h:23
OGG/Vorbis audio decoder.
Definition: VorbisDecoder.h:31
static int oggfiledata_close(VorbisDecoder::OGGFileData *oggFileData)
Close OGG file data.
virtual ~VorbisDecoder()
Destructor.
Definition: VorbisDecoder.h:47
static int oggfiledata_seek(VorbisDecoder::OGGFileData *oggFileData, ogg_int64_t offset, int whence)
Seek in OGG file data.
unique_ptr< OGGFileData > oggFileData
Definition: VorbisDecoder.h:89
void close() override
Closes the audio file.
int64_t readFromStream(ByteBuffer *data) override
Read raw PCM data from stream.
static size_t oggfiledata_read(void *buffer, size_t size, size_t count, VorbisDecoder::OGGFileData *oggFileData)
Read from OGG file data.
void reset() override
Resets this audio decoder, if a stream was open it will be rewinded.
void openFile(const string &pathName, const string &fileName) override
Open a local file.
static long oggfiledata_tell(VorbisDecoder::OGGFileData *oggFileData)
Tell position of OGG file data.
Byte buffer class.
Definition: ByteBuffer.h:27