3 #include <cpp3ds/Audio/SoundFileReader.hpp>
13 class SoundFileReaderMp3 :
public SoundFileReader
18 ~SoundFileReaderMp3();
23 static bool check(InputStream& stream);
29 bool open(InputStream& stream, SoundFileReader::Info& info)
override;
35 void seek(Uint64 sampleOffset)
override;
41 Uint64
read(Int16* samples, Uint64 maxCount)
override;
53 bool update (mpg123_handle* handle ){
54 return mpg123_getformat(handle, &m_rate, &m_channels, &m_encoding) == MPG123_OK;
56 std::string toString()
const {
68 mpg123_frameinfo m_info;
69 const std::size_t m_headerSize = 4;
71 bool update (mpg123_handle* handle ){
72 return mpg123_info(handle, &m_info) == MPG123_OK;
74 std::size_t getFrameSizeInBytesIncludingHeader()
const {
75 return m_info.framesize;
77 std::size_t getFrameSizeInBytesNoHeader()
const {
78 return m_info.framesize - m_headerSize;
80 std::size_t getExpectedNumberOfSamples()
const {
81 return getFrameSizeInBytesNoHeader() /
sizeof(short);
83 std::uint32_t getSamplingRateInHz()
const {
86 std::uint32_t getNumberOfChannels()
const {
89 case mpg123_mode::MPG123_M_MONO:
91 case mpg123_mode::MPG123_M_STEREO:
92 case mpg123_mode::MPG123_M_JOINT:
93 case mpg123_mode::MPG123_M_DUAL:
100 std::string toString()
const {
167 mpg123_handle* m_handle;
168 InputStream* m_stream;
169 FrameInfo m_frameInfo;
170 OutputFormat m_outputFormat;
173 std::size_t m_streambufferSize;
174 unsigned char* m_streambuffer;
177 bool initializeLibrary();
180 bool probeFirstFrame(InputStream& stream);
181 void fillSfmlInfo(SoundFileReader::Info& info)
const;
virtual Uint64 read(Int16 *samples, Uint64 maxCount)=0
Read audio samples from the open file.
virtual bool open(InputStream &stream, Info &info)=0
Open a sound file for reading.
virtual void seek(Uint64 sampleOffset)=0
Change the current read position to the given sample offset.