mp3_decode_port.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "luat_base.h"
  2. #include "luat_mem.h"
  3. #include "luat_multimedia.h"
  4. #include "luat_mem.h"
  5. #ifdef LUAT_BSP_NOT_SUPPORT_FLOAT
  6. #else
  7. #include "mp3_decode/minimp3.h"
  8. LUAT_WEAK void *mp3_decoder_create(void)
  9. {
  10. return luat_heap_malloc(sizeof(mp3dec_t));
  11. }
  12. LUAT_WEAK void mp3_decoder_init(void *decoder)
  13. {
  14. memset(decoder, 0, sizeof(mp3dec_t));
  15. mp3dec_init(decoder);
  16. }
  17. LUAT_WEAK void mp3_decoder_set_debug(void *decoder, uint8_t onoff)
  18. {
  19. (void)decoder;
  20. (void)onoff;
  21. }
  22. LUAT_WEAK int mp3_decoder_get_info(void *decoder, const uint8_t *input, uint32_t len, uint32_t *hz, uint8_t *channel)
  23. {
  24. mp3dec_frame_info_t info;
  25. if (mp3dec_decode_frame(decoder, input, len, NULL, &info) > 0)
  26. {
  27. *hz = info.hz;
  28. *channel = info.channels;
  29. return 1;
  30. }
  31. else
  32. {
  33. return 0;
  34. }
  35. }
  36. LUAT_WEAK int mp3_decoder_get_data(void *decoder, const uint8_t *input, uint32_t len, int16_t *pcm, uint32_t *out_len, uint32_t *hz, uint32_t *used)
  37. {
  38. mp3dec_frame_info_t info;
  39. int result = mp3dec_decode_frame(decoder, input, len, pcm, &info);
  40. if (result >= 0) {
  41. *hz = info.hz;
  42. *out_len = (result * info.channels * 2);
  43. *used = info.frame_bytes;
  44. }
  45. else {
  46. *out_len = 0;
  47. }
  48. return result;
  49. }
  50. #endif