MP3Decoder.cpp 851 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) Kuba Szczodrzyński 2022-1-14.
  2. #include "MP3Decoder.h"
  3. MP3Decoder::MP3Decoder() {
  4. mp3 = MP3InitDecoder();
  5. pcmData = (int16_t *)malloc(MAX_NSAMP * MAX_NGRAN * MAX_NCHAN * sizeof(int16_t));
  6. }
  7. MP3Decoder::~MP3Decoder() {
  8. MP3FreeDecoder(mp3);
  9. free(pcmData);
  10. }
  11. bool MP3Decoder::setup(uint32_t sampleRate, uint8_t channelCount, uint8_t bitDepth) {
  12. return true;
  13. }
  14. uint8_t *MP3Decoder::decode(uint8_t *inData, uint32_t inLen, uint32_t &outLen) {
  15. if (!inData)
  16. return nullptr;
  17. int status = MP3Decode(
  18. mp3,
  19. static_cast<unsigned char **>(&inData),
  20. reinterpret_cast<int *>(&inLen),
  21. static_cast<short *>(this->pcmData),
  22. /* useSize */ 0);
  23. MP3GetLastFrameInfo(mp3, &frame);
  24. if (status != ERR_MP3_NONE) {
  25. lastErrno = status;
  26. return nullptr;
  27. }
  28. outLen = frame.outputSamps * sizeof(int16_t);
  29. return (uint8_t *)pcmData;
  30. }