An object responsible for decoding an audio file. More...
#include <audio_source.hpp>
Collaboration diagram for AudioSource:Public Types | |
| enum | DecodeState : std::uint8_t { DecodeState::WAITING_FOR_FRAME, DecodeState::DECODING, DecodeState::END_OF_FILE } |
| An enumeration of possible states the decoder can be in. More... | |
| using | DecodeVector = std::vector< std::uint8_t > |
| Type of decoded sample vectors. | |
| using | DecodeResult = std::pair< DecodeState, DecodeVector > |
| Type of the result of Decode(). | |
Public Member Functions | |
| AudioSource (const std::string &path) | |
| Constructs an AudioSource. More... | |
| virtual | ~AudioSource ()=default |
| Virtual, empty destructor for AudioSource. | |
| virtual DecodeResult | Decode ()=0 |
| Performs a round of decoding. More... | |
| virtual std::uint8_t | ChannelCount () const =0 |
| Returns the channel count. More... | |
| virtual std::uint32_t | SampleRate () const =0 |
| Returns the sample rate. More... | |
| virtual SampleFormat | OutputSampleFormat () const =0 |
| Returns the output sample format. More... | |
| virtual std::uint64_t | Seek (std::uint64_t position)=0 |
| Seeks to the given position, in samples. More... | |
| virtual size_t | BytesPerSample () const |
| Returns the number of bytes for each sample this decoder outputs. More... | |
| virtual const std::string & | Path () const |
| Gets the file-path of this audio source's audio file. More... | |
| virtual std::uint64_t | SamplesFromMicros (std::uint64_t micros) const |
| Converts a position in microseconds to an elapsed sample count. More... | |
| std::uint64_t | MicrosFromSamples (std::uint64_t samples) const |
| Converts an elapsed sample count to a position in microseconds. More... | |
Protected Attributes | |
| std::string | path |
| The file-path of this AudioSource's audio file. | |
An object responsible for decoding an audio file.
AudioSource is an abstract base class, implemented separately for each supported audio file format.
Definition at line 35 of file audio_source.hpp.
|
strong |
An enumeration of possible states the decoder can be in.
| Enumerator | |
|---|---|
| WAITING_FOR_FRAME | The decoder is currently trying to acquire a frame. |
| DECODING | The decoder is currently decoding a frame. |
| END_OF_FILE | The decoder has run out of things to decode. |
Definition at line 39 of file audio_source.hpp.
| AudioSource::AudioSource | ( | const std::string & | path | ) |
Constructs an AudioSource.
| path | The path to the file from which this AudioSource is decoding. |
Definition at line 16 of file audio_source.cpp.
|
virtual |
Returns the number of bytes for each sample this decoder outputs.
As the decoder returns packed samples, this includes the channel count as a factor.
Definition at line 20 of file audio_source.cpp.
References ChannelCount(), OutputSampleFormat(), and SAMPLE_FORMAT_BPS.
|
pure virtual |
Returns the channel count.
Referenced by BytesPerSample(), and SdlAudioSink::SdlAudioSink().
|
pure virtual |
Performs a round of decoding.
| std::uint64_t AudioSource::MicrosFromSamples | ( | std::uint64_t | samples | ) | const |
Converts an elapsed sample count to a position in microseconds.
| samples | The number of elapsed samples. |
Definition at line 40 of file audio_source.cpp.
References SampleRate().
|
pure virtual |
Returns the output sample format.
Referenced by BytesPerSample(), and SdlAudioSink::SdlAudioSink().
|
virtual |
Gets the file-path of this audio source's audio file.
Definition at line 26 of file audio_source.cpp.
References path.
|
pure virtual |
Returns the sample rate.
Should fail if, for some peculiar reason, the sample rate is above ((2^31) - 1)Hz; this probably implies something is wrong anyway.
Referenced by MicrosFromSamples(), SamplesFromMicros(), and SdlAudioSink::SdlAudioSink().
|
virtual |
Converts a position in microseconds to an elapsed sample count.
| micros | The song position, in microseconds. |
Definition at line 31 of file audio_source.cpp.
References SampleRate().
|
pure virtual |
Seeks to the given position, in samples.
For convenience, the new position (in terms of samples) is returned.
| position | The requested new position in the file, in samples. |