URY playd
C++ minimalist audio player
mp3.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_MP3_HPP
11 #define PLAYD_AUDIO_SOURCE_MP3_HPP
12 #ifdef WITH_MP3
13 
14 #include <cstdint>
15 #include <string>
16 #include <vector>
17 
18 extern "C" {
19 #include <mpg123.h>
20 }
21 
22 #include "../audio_source.hpp"
23 #include "../sample_formats.hpp"
24 
26 class Mp3AudioSource : public AudioSource
27 {
28 public:
34  Mp3AudioSource(const std::string &path);
35 
37  ~Mp3AudioSource();
38 
39  DecodeResult Decode() override;
40  std::uint64_t Seek(std::uint64_t position) override;
41 
42  std::uint8_t ChannelCount() const override;
43  std::uint32_t SampleRate() const override;
44  SampleFormat OutputSampleFormat() const override;
45 
46 private:
48  static const size_t BUFFER_SIZE;
49 
50  std::vector<std::uint8_t> buffer;
51 
53  mpg123_handle *context;
54 
59  void AddFormat(long rate);
60 };
61 
62 #endif // WITH_MP3
63 #endif // PLAYD_AUDIO_SOURCE_MP3_HPP
virtual DecodeResult Decode()=0
Performs a round of decoding.
An object responsible for decoding an audio file.
virtual std::uint8_t ChannelCount() const =0
Returns the channel count.
virtual SampleFormat OutputSampleFormat() const =0
Returns the output sample format.
virtual std::uint64_t Seek(std::uint64_t position)=0
Seeks to the given position, in samples.
virtual std::uint32_t SampleRate() const =0
Returns the sample rate.
SampleFormat
Sample formats available in playd.