iaudiomgrinterface.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef _WIN32
  3. #ifdef LIBAUDIOMGR_EXPORTS
  4. #define LIBAUDIOMGR_API __declspec(dllexport)
  5. #else
  6. #define LIBAUDIOMGR_API __declspec(dllimport)
  7. #endif
  8. # elif ( defined(__GNUC__) && __GNUC__ >= 4 )
  9. #define LIBAUDIOMGR_API __attribute__((visibility("default")))
  10. #else // RVC_OS_WIN
  11. #define LIBAUDIOMGR_API
  12. #endif // RVC_OS_WIN
  13. #include <stddef.h>
  14. #include <stdarg.h>
  15. #ifndef MAX_PATH
  16. #define MAX_PATH 260
  17. #endif
  18. typedef struct audiocap_param_s
  19. {
  20. /** callbacks */
  21. int ideviceid;
  22. int isamprate;
  23. int ichannels;
  24. int isampleformat;
  25. double flatency;
  26. /* called from inner thread, should not block, can be null */
  27. void (*on_audio_callback)(const void* input, unsigned long audiolen,void* userdata);
  28. void* user_data;
  29. }audiocap_param_t;
  30. #pragma pack(1)
  31. typedef struct rvc_audio_device_s
  32. {
  33. int id; /*audo device id*/
  34. int channels; /*max channels*/
  35. int samprate; /*default samplerate*/
  36. double low_latency; /*default low latency*/
  37. double high_latency; /*default high latency*/
  38. char name[MAX_PATH]; /*device name*/
  39. char description[MAX_PATH]; /*device description*/
  40. } rvc_audio_device_t;
  41. #pragma pack()
  42. enum audiomgr_loglevel {
  43. AUDIOMGR_LOG_DEBUG,
  44. AUDIOMGR_LOG_INFO,
  45. AUDIOMGR_LOG_WARN,
  46. AUDIOMGR_LOG_ERROR,
  47. AUDIOMGR_LOG_FATAL
  48. };
  49. typedef struct audiomgr_callback_s{
  50. void (*debug)(void* user_data, audiomgr_loglevel elevel, const char* fmt, va_list arg);
  51. void (*on_audio_mgr_failed)();
  52. void (*on_audio_mgr_excption)();
  53. void* user_data;
  54. }audiomgr_callback_t;
  55. class IAudioMgr
  56. {
  57. public:
  58. virtual int audio_mgr_initialize() = 0;
  59. virtual int audio_mgr_terminate() = 0;
  60. /**/
  61. virtual int audio_get_device_count(bool binput) = 0;
  62. #ifdef _WIN32
  63. virtual int audio_get_device_name(char* pstrbuf, size_t ulen, bool binput, unsigned int uindex) = 0;
  64. #else
  65. virtual int audio_get_device_name(char* pstrbuf, size_t ulen, bool binput, int index) = 0;
  66. #endif
  67. virtual int audio_get_device_id(const char* pstrname, bool binput) = 0;
  68. virtual rvc_audio_device_t* audio_get_device_infos(bool binput, int index) = 0;
  69. virtual int audio_get_device_volume(int* ivolume, const char* pstrname, bool binput) = 0;
  70. virtual int audio_set_device_volume(int ivolume, const char* pstrname, bool binput) = 0;
  71. virtual int set_audio_capture_params(audiocap_param_t* param) = 0;
  72. virtual int start_audio_capture() = 0;
  73. virtual int stop_audio_capture() = 0;
  74. virtual int audio_mgr_destroy() = 0;
  75. };
  76. extern "C" LIBAUDIOMGR_API IAudioMgr* CreateAudioMgrObj(audiomgr_callback_t* pCallback);
  77. extern "C" LIBAUDIOMGR_API void DestroyIAudioMgrObj(IAudioMgr* pIAudioMgr);