A concrete implementation of Audio as a 'pipe'. More...
#include <audio.hpp>
Public Member Functions | |
PipeAudio (std::unique_ptr< AudioSource > src, std::unique_ptr< AudioSink > sink) | |
Constructs a PipeAudio from a source and a sink. More... | |
Audio::State | Update () override |
Performs an update cycle on this Audio. More... | |
const std::string & | File () const override |
This Audio's current file. More... | |
void | SetPlaying (bool playing) override |
Sets whether this Audio should be playing or not. More... | |
Audio::State | CurrentState () const override |
The state of this Audio. More... | |
void | SetPosition (std::uint64_t position) override |
Attempts to seek to the given position. More... | |
std::uint64_t | Position () const override |
This Audio's current position. More... | |
Public Member Functions inherited from Audio | |
virtual | ~Audio ()=default |
Virtual, empty destructor for Audio. | |
Private Member Functions | |
void | ClearFrame () |
Clears the current frame and its iterator. | |
bool | DecodeIfFrameEmpty () |
Decodes a new frame, if the current frame is empty. More... | |
bool | FrameFinished () const |
Returns whether the current frame has been finished. More... | |
void | TransferFrame () |
Transfers as much of the current frame as possible to the sink. | |
Private Attributes | |
std::unique_ptr< AudioSource > | src |
The source of audio data. | |
std::unique_ptr< AudioSink > | sink |
The sink to which audio data is sent. | |
AudioSource::DecodeVector | frame |
The current decoded frame. | |
AudioSource::DecodeVector::iterator | frame_iterator |
The current position in the current decoded frame. | |
Additional Inherited Members | |
Public Types inherited from Audio | |
enum | State : uint8_t { State::NONE, State::STOPPED, State::PLAYING, State::AT_END } |
Enumeration of possible states for this Audio. More... | |
A concrete implementation of Audio as a 'pipe'.
PipeAudio is comprised of a 'source', which decodes frames from a file, and a 'sink', which plays out the decoded frames. Updating consists of shifting frames from the source to the sink.
PipeAudio::PipeAudio | ( | std::unique_ptr< AudioSource > | src, |
std::unique_ptr< AudioSink > | sink | ||
) |
Constructs a PipeAudio from a source and a sink.
src | The source of decoded audio frames. |
sink | The target of decoded audio frames. |
Definition at line 62 of file audio.cpp.
References ClearFrame().
|
overridevirtual |
|
private |
Decodes a new frame, if the current frame is empty.
Definition at line 153 of file audio.cpp.
References AudioSource::END_OF_FILE, frame, frame_iterator, FrameFinished(), and src.
Referenced by Update().
|
overridevirtual |
|
private |
Returns whether the current frame has been finished.
If this is true, then either the frame is empty, or all of the samples in the frame have been fed to the ringbuffer.
Definition at line 172 of file audio.cpp.
References frame, and frame_iterator.
Referenced by DecodeIfFrameEmpty(), TransferFrame(), and Update().
|
overridevirtual |
This Audio's current position.
As this may be executing whilst the playing callback is running, do not expect it to be highly accurate.
NoAudioError | if the current state is NONE. |
Implements Audio.
Definition at line 90 of file audio.cpp.
|
overridevirtual |
Sets whether this Audio should be playing or not.
playing | True for playing; false for stopped. |
NoAudioError | if the current state is NONE. |
Implements Audio.
Definition at line 74 of file audio.cpp.
References sink.
|
overridevirtual |
Attempts to seek to the given position.
position | The position to seek to, in microseconds. |
NoAudioError | if the current state is NONE. |
Implements Audio.
Definition at line 98 of file audio.cpp.
References ClearFrame(), sink, and src.
|
overridevirtual |
Performs an update cycle on this Audio.
Depending on the Audio implementation, this may do actions such as performing a decoding round, checking for end-of-file, transferring frames, and so on.
Implements Audio.
Definition at line 118 of file audio.cpp.
References DecodeIfFrameEmpty(), FrameFinished(), sink, src, and TransferFrame().