AudioDecoder.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /****************************************************************************
  2. Copyright (c) 2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #pragma once
  22. #include "audio/android/OpenSLHelper.h"
  23. #include "audio/android/PcmData.h"
  24. #include "base/CCData.h"
  25. namespace cocos2d { namespace experimental {
  26. class AudioDecoder
  27. {
  28. public:
  29. AudioDecoder();
  30. virtual ~AudioDecoder();
  31. virtual bool init(const std::string &url, int sampleRate);
  32. bool start();
  33. inline PcmData getResult()
  34. { return _result; };
  35. protected:
  36. virtual bool decodeToPcm() = 0;
  37. bool resample();
  38. bool interleave();
  39. static size_t fileRead(void* ptr, size_t size, size_t nmemb, void* datasource);
  40. static int fileSeek(void* datasource, int64_t offset, int whence);
  41. static int fileClose(void* datasource);
  42. static long fileTell(void* datasource);
  43. std::string _url;
  44. PcmData _result;
  45. int _sampleRate;
  46. Data _fileData;
  47. size_t _fileCurrPos;
  48. };
  49. }} // namespace cocos2d { namespace experimental {