TDME2  1.9.200
AudioDecoder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
11 
12 using std::string;
13 
17 
18 /**
19  * Audio decoder base class
20  * @author Andreas Drewke
21  */
23 {
24 public:
25  static constexpr uint8_t CHANNELS_NONE { 0 };
26  static constexpr uint32_t SAMPLERATE_NONE { 0 };
27  static constexpr uint8_t BITSPERSAMPLES_NONE { 0 };
28  static constexpr uint64_t SAMPLES_NONE { 0 };
29 
30 protected:
31  uint8_t channels { CHANNELS_NONE };
34  uint64_t samples { SAMPLES_NONE };
35 
36  /**
37  * Constructor
38  */
39  inline AudioDecoder() {}
40 
41  /**
42  * Destructor
43  */
44  inline virtual ~AudioDecoder() {}
45 
46 public:
47  /**
48  * Open a local file
49  * @param pathName path name
50  * @param fileName file name
51  * @throws tdme::os::filesystem::FileSystemException
52  * @throws tdme::audio::decoder::AudioDecoderException
53  */
54  virtual void openFile(const string& pathName, const string& fileName) = 0;
55 
56  /**
57  * Resets this audio decoder, if a stream was open it will be rewinded
58  * @throws tdme::os::filesystem::FileSystemException
59  * @throws tdme::audio::decoder::AudioDecoderException
60  */
61  virtual void reset() = 0;
62 
63  /**
64  * @return number of channels or CHANNELS_NONE
65  */
66  inline uint8_t getChannels() const {
67  return channels;
68  }
69 
70  /**
71  * @return sample rate in hz or SAMPLERATE_NONE
72  */
73  inline uint32_t getSampleRate() const {
74  return sampleRate;
75  }
76 
77  /**
78  * @return bits per sample or BITSPERSAMPLES_NONE
79  */
80  inline uint8_t getBitsPerSample() const {
81  return bitsPerSample;
82  }
83 
84  /**
85  * @return samples or SAMPLES_NONE
86  */
87  inline uint64_t getSamples() const {
88  return samples;
89  }
90 
91  /**
92  * Read raw PCM data from stream
93  * @param data byte buffer
94  * @throws tdme::os::filesystem::FileSystemException
95  * @throws tdme::audio::decoder::AudioDecoderException
96  * @return number of bytes read
97  */
98  virtual int64_t readFromStream(ByteBuffer* data) = 0;
99 
100  /**
101  * Closes the audio file
102  * @throws tdme::os::filesystem::FileSystemException
103  * @throws tdme::audio::decoder::AudioDecoderException
104  */
105  virtual void close() = 0;
106 
107 };
Audio decoder base class.
Definition: AudioDecoder.h:23
virtual void openFile(const string &pathName, const string &fileName)=0
Open a local file.
static constexpr uint8_t CHANNELS_NONE
Definition: AudioDecoder.h:25
virtual void reset()=0
Resets this audio decoder, if a stream was open it will be rewinded.
virtual ~AudioDecoder()
Destructor.
Definition: AudioDecoder.h:44
static constexpr uint32_t SAMPLERATE_NONE
Definition: AudioDecoder.h:26
virtual int64_t readFromStream(ByteBuffer *data)=0
Read raw PCM data from stream.
static constexpr uint8_t BITSPERSAMPLES_NONE
Definition: AudioDecoder.h:27
static constexpr uint64_t SAMPLES_NONE
Definition: AudioDecoder.h:28
virtual void close()=0
Closes the audio file.
Byte buffer class.
Definition: ByteBuffer.h:27