2
0

AACDecoder.cpp 1.1 KB

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