Advertisement
Kitomas

kit_w32_audio.h (scrapped)

Jul 14th, 2023
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.44 KB | Source Code | 0 0
  1. //compile with kernel32, and ole32
  2. /**
  3.  * \file kit_w32_audio.h
  4.  * \brief Header file for KIT Win32's audio module
  5.  */
  6. #ifndef _KIT_W32_AUDIO_H
  7. #define _KIT_W32_AUDIO_H
  8. #  ifndef _KIT_AUDIO
  9. #  define _KIT_AUDIO
  10.  
  11.  
  12.  
  13. #include <wchar.h> //might be redundant, but this for sure includes wchar_t
  14. #include <stdint.h>
  15. #include <string.h> //used for memcpy
  16.  
  17. #include <synchapi.h> //used for CRITICAL_SECTION
  18. #include <processthreadsapi.h> //used to create and manage threads
  19. #include <combaseapi.h>
  20. #  define _kit_audioMalloc(_type,_len) CoTaskMemAlloc(sizeof(_type)*(_len))
  21. #  define _kit_audioFree(_ptr) CoTaskMemFree(_ptr)
  22. #  define _kit_audioRealloc(_ptr,_type,_len) CoTaskMemRealloc(_ptr,sizeof(_type)*(_len))
  23. #ifndef COM_NO_WINDOWS_H
  24. # define COM_NO_WINDOWS_H
  25. #  include <windef.h> //includes winnt.h
  26. #  include <initguid.h>
  27. #  include <audioclient.h>
  28. #  include <mmdeviceapi.h>
  29. # undef COM_NO_WINDOWS_H
  30. #else
  31. #  include <windef.h>
  32. #  include <initguid.h>
  33. #  include <audioclient.h>
  34. #  include <mmdeviceapi.h>
  35. #endif
  36. #include <dsound.h>
  37.  
  38.  
  39.  
  40. /* GENERAL */
  41.  
  42. /**
  43.  * \name Audio Format Constants
  44.  */
  45. /** @{ */
  46. #define KIT_AUDIO_FMT_I8  (0x8007) ///< \brief   signed  8-bit samples
  47. #define KIT_AUDIO_FMT_U8  (0x0007) ///< \brief unsigned  8-bit samples
  48.  
  49. #define KIT_AUDIO_FMT_I16LSB (0x800F) ///< \brief   signed 16-bit samples (little endian)
  50. #define KIT_AUDIO_FMT_U16LSB (0x000F) ///< \brief unsigned 16-bit samples (little endian)
  51. #define KIT_AUDIO_FMT_I24LSB (0x8017) ///< \brief   signed 24-bit samples (little endian)
  52. #define KIT_AUDIO_FMT_U24LSB (0x0017) ///< \brief unsigned 24-bit samples (little endian)
  53. #define KIT_AUDIO_FMT_I32LSB (0x801F) ///< \brief   signed 32-bit samples (little endian)
  54. #define KIT_AUDIO_FMT_U32LSB (0x001F) ///< \brief unsigned 32-bit samples (little endian)
  55. #define KIT_AUDIO_FMT_F32LSB (0x811F) ///< \brief 32-bit float samples (little endian)
  56. #define KIT_AUDIO_FMT_F64LSB (0x813F) ///< \brief 64-bit float samples (little endian)
  57. //x86 is little endian
  58. //#define KIT_AUDIO_FMT_I16MSB (0x900F) ///< \brief   signed 16-bit samples (big endian)
  59. //#define KIT_AUDIO_FMT_U16MSB (0x100F) ///< \brief unsigned 16-bit samples (big endian)
  60. //#define KIT_AUDIO_FMT_I24MSB (0x9017) ///< \brief   signed 24-bit samples (big endian)
  61. //#define KIT_AUDIO_FMT_U24MSB (0x1017) ///< \brief unsigned 24-bit samples (big endian)
  62. //#define KIT_AUDIO_FMT_I32MSB (0x901F) ///< \brief   signed 32-bit samples (big endian)
  63. //#define KIT_AUDIO_FMT_U32MSB (0x101F) ///< \brief unsigned 32-bit samples (big endian)
  64. //#define KIT_AUDIO_FMT_F32MSB (0x911F) ///< \brief 32-bit float samples (big endian)
  65. //#define KIT_AUDIO_FMT_F64MSB (0x913F) ///< \brief 64-bit float samples (big endian)
  66.  
  67. #define KIT_AUDIO_FMT_I16 KIT_AUDIO_FMT_I16LSB
  68. #define KIT_AUDIO_FMT_U16 KIT_AUDIO_FMT_U16LSB
  69. #define KIT_AUDIO_FMT_I24 KIT_AUDIO_FMT_I24LSB
  70. #define KIT_AUDIO_FMT_U24 KIT_AUDIO_FMT_U24LSB
  71. #define KIT_AUDIO_FMT_I32 KIT_AUDIO_FMT_I32LSB
  72. #define KIT_AUDIO_FMT_U32 KIT_AUDIO_FMT_U32LSB
  73. #define KIT_AUDIO_FMT_F32 KIT_AUDIO_FMT_F32LSB
  74. #define KIT_AUDIO_FMT_F64 KIT_AUDIO_FMT_F64LSB
  75. #define KIT_AUDIO_FMT_INVALID (0x7FFF)
  76. /** @} */
  77.  
  78.  
  79. /**
  80.  * \name Audio Format Bitmasks & Macros
  81.  */
  82. /** @{ */ /* (the "M" in FMT_M means (bit)mask) */
  83. #define KIT_AUDIO_FMT_MBITSIZE (0x00FF) ///< \brief format bitsize mask
  84. #define KIT_AUDIO_FMT_MFLOAT   (0x0100) ///< \brief format float mask
  85. #define KIT_AUDIO_FMT_MENDIAN  (0X1000) ///< \brief format endianness mask
  86. #define KIT_AUDIO_FMT_MSIGNED  (0x8000) ///< \brief format signedness mask
  87. #define KIT_AUDIO_FMT_BITSIZE(x)        ((x) & KIT_AUDIO_FMT_MBITSIZE)
  88. #define KIT_AUDIO_FMT_ISFLOAT(x)        ((x) & KIT_AUDIO_FMT_MFLOAT)
  89. #define KIT_AUDIO_FMT_ISBIGENDIAN(x)    ((x) & KIT_AUDIO_FMT_MENDIAN)
  90. #define KIT_AUDIO_FMT_ISSIGNED(x)       ((x) & KIT_AUDIO_FMT_MSIGNED)
  91. #define KIT_AUDIO_FMT_ISINT(x)          (!KIT_AUDIO_FMT_ISFLOAT(x))
  92. #define KIT_AUDIO_FMT_ISLITTLEENDIAN(x) (!KIT_AUDIO_FMT_ISBIGENDIAN(x))
  93. #define KIT_AUDIO_FMT_ISUNSIGNED(x)     (!KIT_AUDIO_FMT_ISSIGNED(x))
  94. /** @} */
  95.  
  96.  
  97. /**
  98.  * \name Audio Device Type Constants
  99.  */
  100. /** @{ */
  101. #define _KIT_AUDIO_DEVTYPE_BASE                               0
  102. #define  KIT_AUDIO_DEVTYPE_WASAPIIN  (_KIT_AUDIO_DEVTYPE_BASE+1)
  103. #define  KIT_AUDIO_DEVTYPE_WASAPIOUT (_KIT_AUDIO_DEVTYPE_BASE+2)
  104. /** @} */
  105.  
  106.  
  107. /**
  108.  * \name Audio Device Type Macros
  109.  */
  110. /** @{ */
  111. #define KIT_AUDIO_IFNOTDEVICE(_device)\
  112.   if(_device               == NULL                  || \
  113.      _device->_magic.num   != 0x007665446F69647561     \
  114.   )
  115. #define KIT_AUDIO_IFDEVICEINVALID(_device,_type)\
  116.   if(_device               == NULL                  || \
  117.      _device->_magic.num   != 0x007665446F69647561  || \
  118.      _device->_device_type != _type                    \
  119.   )
  120. #define KIT_AUDIO_AUDITANDLOCK(_device,_type,_errorvalue)\
  121.   if(!kit_audioLockDevice(_device)  || \
  122.      _device->device_type != _type    \
  123.   ) return _errorvalue;
  124. #define KIT_AUDIO_LOCK(_device) \
  125.   EnterCriticalSection(&_device->_mutex);
  126. //assumes audit already happened
  127. #define KIT_AUDIO_UNLOCK(_device) \
  128.   LeaveCriticalSection(&_device->_mutex);
  129. /** @} */
  130.  
  131.  
  132. /**
  133.  * Audio Format (FMT)
  134.  * \verbatim
  135.    Bit Layout is as follows:
  136.  
  137.    +----------------------sample is signed if set
  138.    |
  139.    |        +----------sample is bigendian if set
  140.    |        |
  141.    |        |           +--sample is float if set
  142.    |        |           |
  143.    |        |           |  +-sample bit size (-1)+
  144.    |        |           |  |                     |
  145.    15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
  146.    \endverbatim
  147.  */
  148. typedef uint16_t kit_audioFormat;
  149.  
  150.  
  151. /**
  152.  * PCM Audio Callback
  153.  * This type of function is called when an opened (and unpaused)
  154.  * audio device's audio buffer needs more PCM data.
  155.  * The given audio buffer must be completely filled before returning
  156.  * \param userdata A user-defined pointer passed to the callback, which
  157.  *                 is stored in the same kit_audioSpec as the callback itself
  158.  * \param stream   A pointer to the audio data buffer
  159.  * \param len      The length of that buffer in samples (number of sample frames is len/<# of channels>)
  160.  */
  161. typedef void (*kit_audioCallback) (void* userdata,  void* stream, unsigned int len);
  162.  
  163.  
  164. /**
  165.  * \brief This enum is used to indicate the play status of an audio device
  166.  */
  167. typedef enum {
  168.   ADPStateInvalid = 0,
  169.   ADPStateStopped = 1,
  170.   ADPStatePlaying = 2,
  171.   ADPStatePaused  = 3
  172. } kit_audioDevicePState;
  173.  
  174.  
  175. /**
  176.  * \brief This enum is used to indicate an audio device's state
  177.  */
  178. typedef enum { //there might be a better way to name these...
  179.   ADStatusInvalid    = (0),
  180.   ADStatusActive     = (DEVICE_STATE_ACTIVE),
  181.   ADStatusDisabled   = (DEVICE_STATE_DISABLED),
  182.   ADStatusNotPresent = (DEVICE_STATE_NOTPRESENT),
  183.   ADStatusUnplugged  = (DEVICE_STATE_UNPLUGGED),
  184.   ADStatusAll        = (DEVICE_STATE_ACTIVE|DEVICE_STATE_DISABLED|DEVICE_STATE_NOTPRESENT|DEVICE_STATE_UNPLUGGED)
  185. } kit_audioDeviceStatus;
  186.  
  187.  
  188. /* *
  189.  * \brief This struct contains info about audio format conversion
  190.  * /
  191. typedef struct {
  192. } kit_audioCVT; */
  193.  
  194.  
  195. /**
  196.  * \brief This is the struct for an audio specification (something like a config but for a kit_audioDevice)
  197.  * \verbatim
  198.    For multi-channel audio, the current channel mapping is:
  199.    2:  FL  FR                          (stereo)
  200.    3:  FL  FR LFE                      (2.1 surround)
  201.    4:  FL  FR  BL  BR                  (quad)
  202.    5:  FL  FR LFE  BL  BR              (4.1 surround)
  203.    6:  FL  FR  FC LFE  BL  BR          (5.1 surround)
  204.    7:  FL  FR  FC LFE  BC  SL  SR      (6.1 surround)
  205.    8:  FL  FR  FC LFE  BL  BR  SL  SR  (7.1 surround)
  206.    \endverbatim
  207.  */
  208. typedef struct {
  209.   kit_audioCallback    callback; ///< \brief Called when the audio buffer needs to be refilled
  210.   void*                userdata; ///< \brief User-defined pointer passed to callback
  211.   uint32_t            frequency; ///< \brief Sample rate of audio in Hz
  212.   uint32_t          buffer_size; ///< \brief Audio buffer length in bytes (automatically calculated)
  213.   uint32_t           buffer_len; ///< \brief Audio buffer length in samples (must a be power of 2)
  214.   uint16_t             channels; ///< \brief Number of audio channels (1=mono, 2=stereo, etc.)
  215.   kit_audioFormat        format; ///< \brief Audio data format information
  216. } kit_audioSpec;
  217.  
  218.  
  219. /**
  220.  * \brief This is the struct used for both WASAPI in/out devices. \n
  221.  * Something of note is that most members of this struct have the "_" prefix,
  222.  * which states that they are private and most likely should not be interacted
  223.  * with or modified unless through kit_audio's interface.
  224.  *
  225.  * (While this struct uses an ID in the form of _magic, this type of ID
  226.  * is not present in every kind of 'kit_moduleName' struct.)
  227.  */
  228. typedef struct {
  229.   union {
  230.     char                str[8]; ///< \brief String portion of ID ("audioDev\x00")
  231.     uint64_t               num; ///< \brief Number portion of ID (0x007665446F69647561)
  232.   } /* --------------- */ _magic; ///< \brief Struct ID number; union of uint64_t and char[8]
  233.   CRITICAL_SECTION        _mutex; ///< \brief Used to stop callback from triggering if kit_audioLockDevice is called
  234.   //CRITICAL_SECTION _callback_mutex; ///< \brief Used to lock access to _callback_thread specifically
  235.   kit_audioSpec              src; ///< \brief Audio format of input stream buffer
  236.   //kit_audioCVT               cvt; ///< \brief Contains format conversion info
  237.   kit_audioSpec              cvt; ///< \brief Audio format of ConVerTed (output) stream
  238.   HANDLE                  _event; ///< \brief Event handle used in callback handling
  239.   union {
  240.     HANDLE             _handle; ///< \brief Pointer handle of the device
  241.     IAudioClient*      _client;
  242.   };
  243.   //HANDLE        _callback_thread; ///< \brief System callback thread, which kit_audioDeviceReset locks until completion for
  244.   void*                  _stream; ///< \brief Points to the input stream data that is passed to _src.callback
  245.   void*               _buffer[2]; ///< \brief Output streams (while 0 is playing, 1 is being filled, and vice versa)
  246.   float*                  volume; ///< \brief Volume multiplier for each audio channel (0.0 -> 1.0)
  247.   kit_audioDevicePState _playing; ///< \brief play state of device (stopped, playing, paused)
  248.   kit_audioDeviceStatus  _status; ///< \brief current device status (active, disabled, etc.)
  249.   uint32_t      callback_timeout; ///< \brief Timeout for callback thread, in milliseconds (default of 10000)
  250.   uint8_t            _cvt_needed; ///< \brief A boolean of 'is format conversion needed?'
  251.   uint8_t            device_type; ///< \brief 1, 2  =  WASAPI capture, WASAPI render
  252.   uint8_t                 _which; ///< \brief Which output stream to fill with more audio data
  253.   uint8_t          _apply_volume; ///< \brief A boolean of whether to apply volume settings
  254. } kit_audioDevice;
  255.  
  256.  
  257.  
  258. /* INLINES */
  259.  
  260. /**
  261.  * \brief Lock the audio callback of a given device from being called
  262.  *        (useful for manipulating the device struct)
  263.  *
  264.  * \param device A pointer to the device
  265.  * \return A boolean of if the given pointer is an actual audio device
  266.  *
  267.  * \remark This activates a CRITICAL_SECTION mutex, so unlock as soon as possible
  268.  */
  269. static inline int kit_audioLockDevice(kit_audioDevice* device){
  270.   KIT_AUDIO_IFNOTDEVICE(device) return 0;
  271.   else { EnterCriticalSection(&device->_mutex); return 1; }
  272. }
  273.  
  274.  
  275. /**
  276.  * \brief Unlock the audio callback of a given device
  277.  *
  278.  * \param device A pointer to the device
  279.  * \return A boolean of if the given pointer is an actual audio device
  280.  */
  281. static inline int kit_audioUnlockDevice(kit_audioDevice* device){
  282.   KIT_AUDIO_IFNOTDEVICE(device) return 0;
  283.   else { LeaveCriticalSection(&device->_mutex); return 1; }
  284. }
  285.  
  286.  
  287. /* *
  288.  * \brief Get the current playing state of a given device
  289.  *
  290.  * \param device A pointer to the device
  291.  * \return A boolean value of whether the device is currently unpaused or not
  292.  * /
  293. static inline int kit_audioIsPlaying(kit_audioDevice* device){
  294.   if(!kit_audioLockDevice(device)) return 0;
  295.   int isPlaying=device->_playing;
  296.   KIT_AUDIO_UNLOCK(device);
  297.   return isPlaying;
  298. }*/
  299.  
  300.  
  301. /**
  302.  * \brief Set a device channel's volume multiplier (values should be 0.0 -> 1.0)
  303.  *
  304.  * \param device A pointer to the device
  305.  * \param volume New volume multiplier for selected channel
  306.  * \param channel Channel to assign new multiplier to
  307.  */
  308. static inline void kit_audioSetVolume(kit_audioDevice* device, float volume,uint32_t channel){
  309.   if(!kit_audioLockDevice(device)) return;
  310.   if(channel>=device->cvt.channels) return;
  311.   device->volume[channel]=volume;
  312.   KIT_AUDIO_UNLOCK(device);
  313. }
  314.  
  315.  
  316. /**
  317.  * \brief Set Stereo volume multiplier for device (values should be 0.0 -> 1.0)
  318.  *
  319.  * \param device A pointer to the device
  320.  * \param volL New volume multiplier for left channel (or just channel 0 if channels is equal to 1)
  321.  * \param volR New volume multiplier for right channel (ignored if channels is <2)
  322.  */
  323. static inline void kit_audioSetVolumeLR(kit_audioDevice* device, float volL,float volR){
  324.   if(!kit_audioLockDevice(device)) return;
  325.   device->volume[0]=volL;
  326.   if(device->cvt.channels>1) device->volume[1]=volR;
  327.   KIT_AUDIO_UNLOCK(device);
  328. }
  329.  
  330.  
  331.  
  332. /* COM-RELATED FUNCTIONS */
  333.  
  334. //extern kit_audioSpec _kit_audioWaveFormatToSpec(void* format);
  335.  
  336.  
  337. //extern WAVEFORMATEXTENSIBLE _kit_audioSpecToWaveFormat(kit_audioSpec* spec, int* returnStatus_p);
  338.  
  339.  
  340. //extern int _kit_audioQueryDevice(unsigned int index, int isCapture); //assumes globals are already locked
  341.  
  342.  
  343. //extern int _kit_audioQueryDeviceProps(unsigned int index, int isCapture); //assumes globals are already locked
  344.  
  345.  
  346. /**
  347.  * \brief Query and update render/capture audio device list, given a device status
  348.  *
  349.  * \param isCapture A boolean of whether to update the render or capture device list
  350.  * \param status A kit_audioDeviceStatus enum value used to filter
  351.  *        which devices are included in the new list
  352.  * \return A return status code
  353.  * \verbatim Possible return status codes:
  354.  
  355.    \endverbatim
  356.  */
  357. extern int kit_audioQueryDevices(int isCapture, kit_audioDeviceStatus status);
  358.  
  359.  
  360. /**
  361.  * \brief Get number of devices in current device list
  362.  *
  363.  * \param isCapture A boolean of whether to reference the render or capture device list
  364.  * \return The current number of audio endpoint devices
  365.  *
  366.  * \remark This device list can be updated with a call to kit_audioQueryDevices
  367.  * \sa kit_audioQueryDevices
  368.  */
  369. extern unsigned int kit_audioGetNumDevices(int isCapture);
  370.  
  371.  
  372. /**
  373.  * \brief Get the 'friendly name' of a given audio device
  374.  *
  375.  * \param index The index of an audio device in the current device list
  376.  * \param isCapture A boolean of whether to reference the render or capture audio device list
  377.  * \param mode Which name property to pull from; 0 -> 2
  378.  *        (PKEY_Device_FriendlyName, PKEY_Device_DeviceDesc, PKEY_DeviceInterface_FriendlyName)
  379.  * \param returnStatus_p A pointer to an int to be filled with the return status code (can be NULL)
  380.  * \verbatim Possible return status codes:
  381.  
  382.    \endverbatim
  383.  * \return A wide string pointer to the device name, or NULL on error
  384.  *
  385.  * \remark Do not attempt to free the returned pointer yourself. This string is managed internally
  386.  */
  387. extern wchar_t* kit_audioGetDeviceName(unsigned int index, int isCapture,
  388.                                        int mode, int* returnStatus_p);
  389.  
  390.  
  391. /**
  392.  * \brief Get the device ID of a given device, as a wide string
  393.  *
  394.  * \param index The index of an audio device in the current device list
  395.  * \param isCapture A boolean of whether to reference the render or capture audio device list
  396.  * \param returnStatus_p A pointer to an int to be filled with the return status code (can be NULL)
  397.  * \verbatim Possible return status codes
  398.  
  399.    \endverbatim
  400.  * \return A wide string pointer to the device ID, or NULL on error
  401.  *
  402.  * \remark Do not attempt to free the returned pointer yourself. This string is managed internally
  403.  */
  404. extern wchar_t* kit_audioGetDeviceID(unsigned int index, int isCapture, int* returnStatus_p);
  405.  
  406.  
  407. /**
  408.  * \brief Get current connection status of an audio device
  409.  *
  410.  * \param index The index of an audio device in the current device list
  411.  * \param isCapture A boolean of whether to reference the render or capture audio device list
  412.  * \return A kit_audioDeviceStatus enum value (ADStateInvalid if index is out of range)
  413.  */
  414. extern kit_audioDeviceStatus kit_audioGetDeviceStatus(unsigned int index, int isCapture, int* returnStatus_p);
  415.  
  416.  
  417. /**
  418.  * \brief Get the audio format specification of a given audio device
  419.  *
  420.  * \param index The index of an audio device in the current device list
  421.  * \param isCapture A boolean of whether to reference the render or capture audio device list
  422.  * \param spec A pointer to a kit_audioSpec struct to be filled in with the device's specification
  423.  * \return A return status code
  424.  * \verbatim Possible return status codes:
  425.  
  426.    \endverbatim
  427.  */
  428. extern int kit_audioGetDeviceSpec(unsigned int index, int isCapture, kit_audioSpec* spec);
  429.  
  430.  
  431. extern int kit_audioIsSpecSupported(unsigned int index, int isCapture,
  432.                                     kit_audioSpec* spec, kit_audioSpec* closestMatch);
  433.  
  434.  
  435. extern unsigned int kit_audioGetDeviceIndexFromID(wchar_t* deviceID, int isCapture, int* returnStatus_p);
  436.  
  437.  
  438.  
  439. /* kit_audioDevice-RELATED FUNCTIONS */
  440.  
  441. //TBD
  442. extern int kit_audioDevicePlay(kit_audioDevice* device, kit_audioDevicePState playState);
  443.  
  444.  
  445. /**
  446.  * \brief Get the current play state of a given device
  447.  *
  448.  * \param device A pointer to the device
  449.  * \return A kit_audioDevicePState enum value of the device's play state
  450.  */
  451. extern kit_audioDevicePState kit_audioGetDevicePlayState(kit_audioDevice* device);
  452.  
  453.  
  454.  
  455. /* (UN)INIT FUNCTIONS */
  456.  
  457. /**
  458.  * \brief Initialize kit_w32_audio, while optionally initializing COM, too. \n
  459.  * This function should ideally be called only once, and in the process's main thread. \n
  460.  * (Bad things will happen if kit_audio functions are called before initializing.)
  461.  *
  462.  * \param initCOM A boolean of whether to initialize COM within the function
  463.  * \return A return status code
  464.  * \verbatim Possible return status codes:
  465.    0: Success; no error
  466.    1: Init has already been called (this check is prone to race conditions, and is therefore unreliable)
  467.    2: Failed to create device enumerator object
  468.    3: Failed to enumerate input (capture) audio endpoints
  469.    4: Failed to enumerate output (render) audio endpoints
  470.    \endverbatim
  471.  *
  472.  * \remark If initCOM=0, "CoInitialize(NULL,COINIT_MULTITHREADED)"
  473.  *         must be called prior to calling kit_audioInit.
  474.  * \sa kit_audioQuit
  475.  */
  476. extern int kit_audioInit(int initCOM);
  477.  
  478.  
  479. /**
  480.  * \brief Uninitialize kit_w32_audio, freeing and releasing remaining interfaces in the process. \n
  481.  * It is recommended to call kit_audioQuit only once, and in the same thread as the prior call to kit_audioInit.
  482.  *
  483.  * \param uninitCOM A boolean of whether to uninitialize COM after freeing/releasing everything
  484.  * \return 0 on success, and 1 if kit_w32_audio is already uninitialized
  485.  *
  486.  * \remark Due to chronic and unexplainable problems with CoUninitialize, setting uninitCOM to 0 is recommended
  487.  * \sa kit_audioInit
  488.  */
  489. extern int kit_audioQuit(int uninitCOM);
  490.  
  491.  
  492. //TBD
  493. extern kit_audioDevice* kit_audioDeviceOpen(kit_audioSpec* spec, unsigned int index,
  494.                                             int isCapture, int* returnStatus_p);
  495.  
  496.  
  497. //TBD
  498. extern int kit_audioDeviceClose(kit_audioDevice** device_p);
  499.  
  500.  
  501.  
  502. #  endif //_KIT_AUDIO
  503. #endif //_KIT_W32_AUDIO_H
  504.  
  505. //move this back to kit_w32_audio.c once i'm done testing with it
  506. typedef struct {
  507.   union {
  508.     WAVEFORMATEX         device_format;
  509.     WAVEFORMATEXTENSIBLE device_format_ext;
  510.   };
  511.   IMMDeviceCollection* devices;
  512.   IMMDevice*            device;
  513.   IPropertyStore*        props;
  514.   IAudioClient*         client;
  515.   LPWSTR             device_id; //aka wide char* (wchar_t*)!
  516.   LPWSTR          device_iname;
  517.   LPWSTR           device_name;
  518.   LPWSTR           device_desc;
  519.   size_t      device_iname_len;
  520.   size_t       device_name_len;
  521.   size_t       device_desc_len;
  522.   UINT            device_index;
  523.   EDataFlow          data_flow; //read-only; set by init
  524.   int                data_type; //1,2,3 = pcm&format, float&format_ext, pcm&format_ext
  525.   int     event_driven_support; //might not be used
  526. } _kit_audioGlobalsDevInfo;
  527. struct _kit_audioGlobals_s {
  528.   CRITICAL_SECTION           lock;
  529.   IMMDeviceEnumerator* enumerator;
  530.   kit_audioDevice**   kit_devices;
  531.   UINT            kit_devices_len;
  532.   _kit_audioGlobalsDevInfo      i;
  533.   _kit_audioGlobalsDevInfo      o;
  534.   int                        init;
  535. };
  536.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement