audio_resample_demo.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. *****************************************************************
  3. *
  4. * Audio 变采样使用demo
  5. *
  6. *****************************************************************
  7. */
  8. #include "asm/includes.h"
  9. #include "media/includes.h"
  10. #include "system/includes.h"
  11. #include "app_config.h"
  12. #include "audio_config.h"
  13. #include "audio_decode.h"
  14. #include "app_main.h"
  15. #include "Resample_api.h"
  16. /* #include "audio_dec.h" */
  17. /* #include "clock_cfg.h" */
  18. static RS_PARA_STRUCT rs_para_obj;
  19. static RS_STUCT_API *test_rs_api;
  20. static s16 sin_48k[48] = {
  21. 0, 2139, 4240, 6270, 8192, 9974, 11585, 12998,
  22. 14189, 15137, 15826, 16244, 16384, 16244, 15826, 15137,
  23. 14189, 12998, 11585, 9974, 8192, 6270, 4240, 2139,
  24. 0, -2139, -4240, -6270, -8192, -9974, -11585, -12998,
  25. -14189, -15137, -15826, -16244, -16384, -16244, -15826, -15137,
  26. -14189, -12998, -11585, -9974, -8192, -6270, -4240, -2139
  27. };
  28. static s16 output_buf[96] = {0};
  29. void audio_resample_demo(void)
  30. {
  31. rs_para_obj.nch = 2; //双声道
  32. rs_para_obj.new_insample = 48000; //输入采样率
  33. rs_para_obj.new_outsample = 32000;//输出采样率
  34. test_rs_api = get_rsfast_context();
  35. s32 rs_bufsize = test_rs_api->need_buf();
  36. s16 *rs_buf = malloc(rs_bufsize);
  37. test_rs_api->open(rs_buf, &rs_para_obj);
  38. s16 *inbuf = sin_48k; //输入数据的buffer
  39. s16 *obuf = output_buf; //输出数据的buffer
  40. u32 len = sizeof(sin_48k) / 2; //输入数据的长度
  41. u32 rdlen = test_rs_api->run(rs_buf, inbuf, len, obuf); //len是n个s16,数据在 inbuf,返回rdlen个s16 是输出数据的长度,输出数据在obuf
  42. put_buf(obuf, rdlen); //把输出数据打印出来
  43. }