URY playd
C++ minimalist audio player
audio_source.hpp
Go to the documentation of this file.
1 // This file is part of playd.
2 // playd is licensed under the MIT licence: see LICENSE.txt.
3 
10 #ifndef PLAYD_AUDIO_SOURCE_HPP
11 #define PLAYD_AUDIO_SOURCE_HPP
12 
13 #include <cstdint>
14 #include <string>
15 #include <vector>
16 
17 #include "../errors.hpp"
18 #include "sample_formats.hpp"
19 
36 {
37 public:
39  enum class DecodeState : std::uint8_t {
43  DECODING,
46  };
47 
49  using DecodeVector = std::vector<std::uint8_t>;
50 
52  using DecodeResult = std::pair<DecodeState, DecodeVector>;
53 
59  AudioSource(const std::string &path);
60 
62  virtual ~AudioSource() = default;
63 
64  //
65  // Methods that must be overridden
66  //
67 
74  virtual DecodeResult Decode() = 0;
75 
80  virtual std::uint8_t ChannelCount() const = 0;
81 
88  virtual std::uint32_t SampleRate() const = 0;
89 
94  virtual SampleFormat OutputSampleFormat() const = 0;
95 
102  virtual std::uint64_t Seek(std::uint64_t position) = 0;
103 
104  //
105  // Methods provided 'for free'
106  //
107 
114  virtual size_t BytesPerSample() const;
115 
120  virtual const std::string &Path() const;
121 
127  virtual std::uint64_t SamplesFromMicros(std::uint64_t micros) const;
128 
134  std::uint64_t MicrosFromSamples(std::uint64_t samples) const;
135 
136 protected:
138  std::string path;
139 };
140 
141 #endif // PLAYD_AUDIO_SOURCE_HPP
virtual DecodeResult Decode()=0
Performs a round of decoding.
std::string path
The file-path of this AudioSource&#39;s audio file.
An object responsible for decoding an audio file.
virtual const std::string & Path() const
Gets the file-path of this audio source&#39;s audio file.
virtual std::uint8_t ChannelCount() const =0
Returns the channel count.
virtual ~AudioSource()=default
Virtual, empty destructor for AudioSource.
virtual std::uint64_t SamplesFromMicros(std::uint64_t micros) const
Converts a position in microseconds to an elapsed sample count.
virtual SampleFormat OutputSampleFormat() const =0
Returns the output sample format.
std::uint64_t MicrosFromSamples(std::uint64_t samples) const
Converts an elapsed sample count to a position in microseconds.
AudioSource(const std::string &path)
Constructs an AudioSource.
The decoder is currently trying to acquire a frame.
virtual std::uint64_t Seek(std::uint64_t position)=0
Seeks to the given position, in samples.
The decoder is currently decoding a frame.
The decoder has run out of things to decode.
DecodeState
An enumeration of possible states the decoder can be in.
virtual size_t BytesPerSample() const
Returns the number of bytes for each sample this decoder outputs.
virtual std::uint32_t SampleRate() const =0
Returns the sample rate.
SampleFormat
Sample formats available in playd.
std::vector< std::uint8_t > DecodeVector
Type of decoded sample vectors.
std::pair< DecodeState, DecodeVector > DecodeResult
Type of the result of Decode().
The SampleFormat enumeration and related declarations.