audio_tonegen.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _AUDIO_TONEGEN_H_
  13. #define _AUDIO_TONEGEN_H_
  14. #include "audio_types.h"
  15. OSI_EXTERN_C_BEGIN
  16. /**
  17. * \brief opaque data structure for audio tone generator
  18. */
  19. typedef struct auToneGen auToneGen_t;
  20. /**
  21. * \brief create audio tone generator
  22. *
  23. * The sample format of audio tone generator is \p AUSAMPLE_FORMAT_S16,
  24. * the channel count is 1.
  25. *
  26. * \param sample_rate sample rate of generated samples
  27. * \return
  28. * - audio tone generator instance
  29. * - NULL on fail, no memory or invalid parameter
  30. */
  31. auToneGen_t *auToneGenCreate(unsigned sample_rate);
  32. /**
  33. * \brief delete the audio tone generator instance
  34. *
  35. * \param d audio tone generator instance
  36. */
  37. void auToneGenDelete(auToneGen_t *d);
  38. /**
  39. * \brief start audio tone generator
  40. *
  41. * The format of \p gain is 1.14. That is 0x4000 is for full range
  42. * without attenuation, inrange of [32767, -32768].
  43. *
  44. * Audio tone generator can support one frequency or dual frequencies.
  45. * For single frequency, \p freq2 should be the same with \p freq1.
  46. * Both of \p freq1 and \p frea2 can not be zero, and must be less than
  47. * sample rate.
  48. *
  49. * \p period is the period of tone, in milliseconds, \p silence is the
  50. * period of silence after tone. \p period can not be zero, and
  51. * \p silence can be zero.
  52. *
  53. * When \p period or \p silence is \p OSI_DELAY_MAX, it will never
  54. * finish.
  55. *
  56. * If audio tone generator is already started, this will restart audio
  57. * tone generator.
  58. *
  59. * \param d audio tone generator instance
  60. * \param gain gain of generated samples
  61. * \param freq1 the first frequency
  62. * \param freq2 the second frequency
  63. * \param period tone period in milliseconds
  64. * \param silence silence period in milliseconds
  65. * \return
  66. * - true on success
  67. * - false on fail, invalid parameters
  68. */
  69. bool auToneGenStart(auToneGen_t *d, unsigned gain, unsigned freq1, unsigned freq2,
  70. unsigned period, unsigned silence);
  71. /**
  72. * \brief get audio tone samples
  73. *
  74. * When period (both tone period and silence period) is finished, it
  75. * will set \p frame->flags to \p AUFRAME_FLAG_END, and return true.
  76. *
  77. * This will fill sample into \p frame->data+frame->bytes. The maximum
  78. * byte count to be filled is \p bytes. Caller should avoid memory
  79. * overflow.
  80. *
  81. * On success, \p frame->bytes will be updated and format parameters
  82. * will be filled.
  83. *
  84. * \param d audio tone generator instance
  85. * \param frame audio frame
  86. * \param bytes maximum byte count to be filled
  87. * \return
  88. * - filled byte count
  89. * - -1 on fail, invalid parameter
  90. */
  91. int auToneGenSamples(auToneGen_t *d, auFrame_t *frame, unsigned bytes);
  92. OSI_EXTERN_C_END
  93. #endif