2
0

AACDecoder.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "AACDecoder.h"
  2. #include <stdlib.h> // for free, malloc
  3. #include "CodecType.h" // for bell
  4. namespace bell {
  5. class AudioContainer;
  6. } // namespace bell
  7. using namespace bell;
  8. AACDecoder::AACDecoder() {
  9. aac = AACInitDecoder();
  10. pcmData = (int16_t*)malloc(AAC_MAX_NSAMPS * AAC_MAX_NCHANS * sizeof(int16_t));
  11. }
  12. AACDecoder::~AACDecoder() {
  13. AACFreeDecoder(aac);
  14. free(pcmData);
  15. }
  16. bool AACDecoder::setup(uint32_t sampleRate, uint8_t channelCount,
  17. uint8_t bitDepth) {
  18. return true;
  19. }
  20. bool AACDecoder::setup(AudioContainer* container) {
  21. return true;
  22. }
  23. uint8_t* AACDecoder::decode(uint8_t* inData, uint32_t& inLen,
  24. uint32_t& outLen) {
  25. if (!inData)
  26. return nullptr;
  27. int status = AACDecode(aac, static_cast<unsigned char**>(&inData),
  28. reinterpret_cast<int*>(&inLen),
  29. static_cast<short*>(this->pcmData));
  30. AACGetLastFrameInfo(aac, &frame);
  31. if (status != ERR_AAC_NONE) {
  32. lastErrno = status;
  33. return nullptr;
  34. }
  35. if (sampleRate != frame.sampRateOut) {
  36. this->sampleRate = frame.sampRateOut;
  37. }
  38. if (channelCount != frame.nChans) {
  39. this->channelCount = frame.nChans;
  40. }
  41. outLen = frame.outputSamps * sizeof(int16_t);
  42. return (uint8_t*)pcmData;
  43. }