MusicMP3.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef FREESHOP_MUSICMP3_HPP
  2. #define FREESHOP_MUSICMP3_HPP
  3. #include <string>
  4. #include <vector>
  5. #include <cpp3ds/Config.hpp>
  6. #include <cpp3ds/Audio/AlResource.hpp>
  7. #include <cpp3ds/System/Lock.hpp>
  8. #include <cpp3ds/System/Mutex.hpp>
  9. #include <cpp3ds/System/Thread.hpp>
  10. #include <cpp3ds/System/FileInputStream.hpp>
  11. #include <mpg123.h>
  12. #ifdef _3DS
  13. #include <3ds.h>
  14. #endif
  15. namespace FreeShop {
  16. class MusicMP3 {
  17. public:
  18. MusicMP3();
  19. ~MusicMP3();
  20. bool openFromFile(const std::string &filename);
  21. void play(bool launchThread = true);
  22. void pause();
  23. void stop();
  24. bool getSongFinished();
  25. protected:
  26. void streamData();
  27. void fillBuffers();
  28. private:
  29. bool m_isLittleEndian;
  30. bool m_isStreaming;
  31. bool m_isPaused;
  32. bool m_isStopped;
  33. bool m_isSongFinished;
  34. cpp3ds::Thread m_thread;
  35. cpp3ds::Mutex m_mutex;
  36. cpp3ds::FileInputStream m_file;
  37. std::string m_fileName;
  38. bool m_looping;
  39. uint32_t m_channelCount;
  40. uint32_t m_sampleRate;
  41. #ifdef _3DS
  42. u16 m_channel[2];
  43. ndspWaveBuf m_waveBuf[2];
  44. ndspAdpcmData m_adpcmData[2][2];
  45. std::vector<u8> m_bufferData[2];
  46. uint64_t decodeMP3(void* buffer);
  47. #endif
  48. };
  49. } // namespace FreeShop
  50. #endif // FREESHOP_MUSICMP3_HPP