MusicBCSTM.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef FREESHOP_MUISCBCSTM_HPP
  2. #define FREESHOP_MUISCBCSTM_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. #ifdef _3DS
  12. #include <3ds.h>
  13. #endif
  14. namespace FreeShop {
  15. class MusicBCSTM {
  16. public:
  17. MusicBCSTM();
  18. ~MusicBCSTM();
  19. bool openFromFile(const std::string &filename);
  20. void play();
  21. void pause();
  22. void stop();
  23. protected:
  24. void streamData();
  25. uint8_t read8();
  26. uint16_t read16();
  27. uint32_t read32();
  28. bool fileAdvance(uint64_t byteSize);
  29. void fillBuffers();
  30. private:
  31. enum RefType: uint16_t {
  32. ByteTable = 0x0100,
  33. ReferenceTable = 0x0101,
  34. SampleData = 0x1F00,
  35. DSPADPCMInfo = 0x0300,
  36. InfoBlock = 0x4000,
  37. SeekBlock = 0x4001,
  38. DataBlock = 0x4002,
  39. StreamInfo = 0x4100,
  40. TrackInfo = 0x4101,
  41. ChannelInfo = 0x4102,
  42. };
  43. enum {
  44. BufferCount = 20,
  45. };
  46. bool m_isLittleEndian;
  47. bool m_isStreaming;
  48. bool m_isPaused;
  49. cpp3ds::Thread m_thread;
  50. cpp3ds::Mutex m_mutex;
  51. cpp3ds::FileInputStream m_file;
  52. bool m_looping;
  53. uint32_t m_channelCount;
  54. uint32_t m_sampleRate;
  55. uint32_t m_blockLoopStart;
  56. uint32_t m_blockLoopEnd;
  57. uint32_t m_blockCount;
  58. uint32_t m_blockSize;
  59. uint32_t m_blockSampleCount;
  60. uint32_t m_lastBlockSize;
  61. uint32_t m_lastBlockSampleCount;
  62. uint16_t m_adpcmCoefs[2][16];
  63. uint32_t m_currentBlock;
  64. uint32_t m_infoOffset;
  65. uint32_t m_dataOffset;
  66. #ifdef _3DS
  67. u16 m_channel[2];
  68. ndspWaveBuf m_waveBuf[2][BufferCount];
  69. ndspAdpcmData m_adpcmData[2][2];
  70. std::vector<u8, cpp3ds::LinearAllocator<u8>> m_bufferData[2][BufferCount];
  71. #endif
  72. };
  73. } // namespace FreeShop
  74. #endif // FREESHOP_MUISCBCSTM_HPP