audio_test.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-1-16 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include <rtconfig.h>
  13. #if defined(PKG_USING_WAVPLAYER)
  14. #include "wavrecorder.h"
  15. #include "wavplayer.h"
  16. #include "dfs_posix.h"
  17. /*
  18. The routine just for test automatically.
  19. - For record function: Run it w/o parameter.
  20. - For replay function: Run it with parameter.
  21. */
  22. static int audio_test(int argc, char **argv)
  23. {
  24. #define DEF_MAX_ARGV_NUM 8
  25. int smplrate[] = {8000, 16000, 44100, 48000};
  26. int smplbit[] = {16};
  27. int chnum[] = {1, 2};
  28. struct wavrecord_info info;
  29. char strbuf[128];
  30. int i, j, k;
  31. int bDoRecording = 1;
  32. struct stat stat_buf;
  33. if (argc > 1)
  34. bDoRecording = 0;
  35. for (i = 0; i < sizeof(smplrate) / sizeof(int); i++)
  36. {
  37. for (j = 0; j < sizeof(smplbit) / sizeof(int); j++)
  38. {
  39. for (k = 0; k < sizeof(chnum) / sizeof(int); k++)
  40. {
  41. snprintf(strbuf, sizeof(strbuf), "/mnt/sd0/%d_%d_%d.wav", smplrate[i], smplbit[j], chnum[k]);
  42. if (bDoRecording)
  43. {
  44. rt_kprintf("Recording file at %s\n", strbuf);
  45. info.uri = strbuf;
  46. info.samplerate = smplrate[i];
  47. info.samplebits = smplbit[j];
  48. info.channels = chnum[k];
  49. wavrecorder_start(&info);
  50. rt_thread_mdelay(10000);
  51. wavrecorder_stop();
  52. rt_thread_mdelay(1000);
  53. }
  54. else
  55. {
  56. if (stat((const char *)strbuf, &stat_buf) < 0)
  57. {
  58. rt_kprintf("%s non-exist.\n", strbuf);
  59. continue;
  60. }
  61. rt_kprintf("Replay file at %s\n", strbuf);
  62. wavplayer_play(strbuf);
  63. rt_thread_mdelay(10000);
  64. wavplayer_stop();
  65. }
  66. } // k
  67. } // j
  68. } // i
  69. return 0;
  70. }
  71. #ifdef FINSH_USING_MSH
  72. MSH_CMD_EXPORT(audio_test, Audio record / replay);
  73. #endif
  74. #endif /* PKG_USING_WAVPLAYER */