Advertisement
Kitomas

the async part of kit_kmixer.h as of 2023-10-27

Oct 27th, 2023
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.06 KB | None | 0 0
  1. /**
  2.  * Add an asynchronous mixer voice (useful for playing sound effects)
  3.  * \param[in] device The device to add the voice to
  4.  * \param[in] linearInterpolation Whether to use linear interpolation or nearest-neighbor when resampling
  5.  * \param[in] stereo Whether to use stereo or mono for each track
  6.  * \param[in] outputVoiceID The voice to output to (0 for the device itself)
  7.  * \param[in] numTracks The maximum number of tracks that can play at once
  8.  * \return The index of the newly-created voice, or 0 on error (call SDL_GetError() for more info)
  9.  *
  10.  * \remark There is no AsyncRemove function. Instead, use VoiceRemove on the returned voice ID! \n
  11.  * \remark Also, the resulting VoiceSpec is that of the device, EXCEPT for stereo (and format, which will always be AUDIO_F32).
  12.  */
  13. extern Uint32 kit_kmixerAsyncAdd(kit_kmixerDevice* device,
  14.                                  SDL_bool linearInterpolation, SDL_bool stereo,
  15.                                  Uint32 outputVoiceID, Uint32 numTracks);
  16.  
  17.  
  18. /**
  19.  * Play a kit_acodecPCM audio clip asynchronously, with a custom pan, volume, and speed
  20.  * \param[in] device The device that contains the async voice
  21.  * \param[in] voiceID The async voice to query
  22.  * \param[in] pcm The audio clip to queue
  23.  * \param[in] pan The pan setting of the clip (-1.0f -> 1.0f)
  24.  * \param[in] volumeL The left channel's volume, or total volume if mono (>=0.0f)
  25.  * \param[in] volumeR The right channel's volume (>=0.0f; ignored if mono)
  26.  * \param[in] speedMultiplier The speed the clip should play at; 1 for 1x, 1.5 for 1.5x, etc.
  27.  * \return The track that clip was queued, -2 if no free track was found, or -1 on error (call SDL_GetError() for more info)
  28.  *
  29.  * \remark To check for a valid async voice, the first 4 bytes of *userdata are compared to 0x54414455 ("UDAT"). \n
  30.  *         This means that even if the voice is invalid, no error will occur if the check is true (so don't do that)!
  31.  * \sa kit_kmixerAsyncPlay
  32.  * \sa kit_kmixerAsyncPlayP
  33.  * \sa kit_kmixerAsyncPlayV
  34.  * \sa kit_kmixerAsyncPlayS
  35.  * \sa kit_kmixerAsyncStopTrack
  36.  * \sa kit_kmixerAsyncStopAllTracks
  37.  */
  38. extern Uint32 kit_kmixerAsyncPlayPVS(kit_kmixerDevice* device, Uint32 voiceID, kit_acodecPCM* pcm,
  39.                                      float pan, float volumeL, float volumeR, double speedMultiplier);
  40.  
  41. /**
  42.  * Play a kit_acodecPCM audio clip asynchronously
  43.  * \param[in] device The device that contains the async voice
  44.  * \param[in] voiceID The async voice to query
  45.  * \param[in] pcm The audio clip to queue
  46.  * \return The track that clip was queued, -2 if no free track was found, or -1 on error (call SDL_GetError() for more info)
  47.  *
  48.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  49.  * \sa kit_kmixerAsyncPlayPVS
  50.  * \sa kit_kmixerAsyncPlayP
  51.  * \sa kit_kmixerAsyncPlayV
  52.  * \sa kit_kmixerAsyncPlayS
  53.  * \sa kit_kmixerAsyncStopTrack
  54.  * \sa kit_kmixerAsyncStopAllTracks
  55.  */
  56. static inline Uint32 kit_kmixerAsyncPlay(kit_kmixerDevice* device, Uint32 voiceID, kit_acodecPCM* pcm){
  57.   return kit_kmixerAsyncPlayPVS(device, voiceID, pcm, 0.0f, 1.0f,1.0f, 1.0);
  58. }
  59.  
  60. /**
  61.  * Play a kit_acodecPCM audio clip asynchronously, with a custom pan
  62.  * \param[in] device The device that contains the async voice
  63.  * \param[in] voiceID The async voice to query
  64.  * \param[in] pcm The audio clip to queue
  65.  * \param[in] pan The pan setting of the clip (-1.0f -> 1.0f)
  66.  * \return The track that clip was queued, -2 if no free track was found, or -1 on error (call SDL_GetError() for more info)
  67.  *
  68.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  69.  * \sa kit_kmixerAsyncPlayPVS
  70.  * \sa kit_kmixerAsyncPlay
  71.  * \sa kit_kmixerAsyncPlayV
  72.  * \sa kit_kmixerAsyncPlayS
  73.  * \sa kit_kmixerAsyncStopTrack
  74.  * \sa kit_kmixerAsyncStopAllTracks
  75.  */
  76. static inline Uint32 kit_kmixerAsyncPlayP(kit_kmixerDevice* device, Uint32 voiceID, kit_acodecPCM* pcm,
  77.                                           float pan)
  78. {
  79.   return kit_kmixerAsyncPlayPVS(device, voiceID, pcm, pan, 1.0f,1.0f, 1.0);
  80. }
  81.  
  82. /**
  83.  * Play a kit_acodecPCM audio clip asynchronously, with a custom volume
  84.  * \param[in] device The device that contains the async voice
  85.  * \param[in] voiceID The async voice to query
  86.  * \param[in] pcm The audio clip to queue
  87.  * \param[in] volumeL The left channel's volume, or total volume if mono (>=0.0f)
  88.  * \param[in] volumeR The right channel's volume (>=0.0f; ignored if mono)
  89.  * \return The track that clip was queued, -2 if no free track was found, or -1 on error (call SDL_GetError() for more info)
  90.  *
  91.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  92.  * \sa kit_kmixerAsyncPlayPVS
  93.  * \sa kit_kmixerAsyncPlay
  94.  * \sa kit_kmixerAsyncPlayP
  95.  * \sa kit_kmixerAsyncPlayS
  96.  * \sa kit_kmixerAsyncStopTrack
  97.  * \sa kit_kmixerAsyncStopAllTracks
  98.  */
  99. static inline Uint32 kit_kmixerAsyncPlayV(kit_kmixerDevice* device, Uint32 voiceID, kit_acodecPCM* pcm,
  100.                                           float volumeL, float volumeR)
  101. {
  102.   return kit_kmixerAsyncPlayPVS(device, voiceID, pcm, 0.0f, volumeL,volumeR, 1.0);
  103. }
  104.  
  105. /**
  106.  * Play a kit_acodecPCM audio clip asynchronously, with a custom speed
  107.  * \param[in] device The device that contains the async voice
  108.  * \param[in] voiceID The async voice to query
  109.  * \param[in] pcm The audio clip to queue
  110.  * \param[in] speedMultiplier The speed the clip should play at; 1 for 1x, 1.5 for 1.5x, etc.
  111.  * \return The track that clip was queued, -2 if no free track was found, or -1 on error (call SDL_GetError() for more info)
  112.  *
  113.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  114.  * \sa kit_kmixerAsyncPlayPVS
  115.  * \sa kit_kmixerAsyncPlay
  116.  * \sa kit_kmixerAsyncPlayP
  117.  * \sa kit_kmixerAsyncPlayV
  118.  * \sa kit_kmixerAsyncStopTrack
  119.  * \sa kit_kmixerAsyncStopAllTracks
  120.  */
  121. static inline Uint32 kit_kmixerAsyncPlayS(kit_kmixerDevice* device, Uint32 voiceID, kit_acodecPCM* pcm,
  122.                                           double speedMultiplier)
  123. {
  124.   return kit_kmixerAsyncPlayPVS(device, voiceID, pcm, 0.0f, 1.0f,1.0f, speedMultiplier);
  125. }
  126.  
  127. /**
  128.  * Force an async track to stop playing
  129.  * \param[in] device The device that contains the async voice
  130.  * \param[in] voiceID The async voice to query
  131.  * \param[in] trackNum The track to stop
  132.  * \return 0 on success, 1 if track isn't playing anything, or <0 on error (call SDL_GetError() for more info)
  133.  *
  134.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  135.  * \sa kit_kmixerAsyncPlayPVS
  136.  * \sa kit_kmixerAsyncPlay
  137.  * \sa kit_kmixerAsyncPlayP
  138.  * \sa kit_kmixerAsyncPlayV
  139.  * \sa kit_kmixerAsyncPlayS
  140.  * \sa kit_kmixerAsyncStopAllTracks
  141.  */
  142. extern int kit_kmixerAsyncStopTrack(kit_kmixerDevice* device, Uint32 voiceID,
  143.                                     Uint32 trackNum);
  144.  
  145. /**
  146.  * Force all async tracks to stop playing
  147.  * \param[in] device The device that contains the async voice
  148.  * \param[in] voiceID The async voice to query
  149.  * \return 0 on success, or <0 on error (call SDL_GetError() for more info)
  150.  *
  151.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  152.  * \sa kit_kmixerAsyncPlayPVS
  153.  * \sa kit_kmixerAsyncPlay
  154.  * \sa kit_kmixerAsyncPlayP
  155.  * \sa kit_kmixerAsyncPlayV
  156.  * \sa kit_kmixerAsyncPlayS
  157.  * \sa kit_kmixerAsyncStopTrack
  158.  */
  159. extern int kit_kmixerAsyncStopAllTracks(kit_kmixerDevice* device, Uint32 voiceID);
  160.  
  161.  
  162. /**
  163.  * Get the number of tracks actively playing audio clips
  164.  * \param[in] device The device that contains the async voice
  165.  * \param[in] voiceID The async voice to query
  166.  * \return The number of active tracks, or -1 on error (call SDL_GetError() for more info)
  167.  *
  168.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  169.  * \sa kit_kmixerAsyncPlayPVS
  170.  * \sa kit_kmixerAsyncGetNumTracks
  171.  * \sa kit_kmixerAsyncGetTrackPlayState
  172.  * \sa kit_kmixerAsyncGetTrackPosition
  173.  */
  174. extern Uint32 kit_kmixerAsyncGetActiveTracks(kit_kmixerDevice* device, Uint32 voiceID);
  175.  
  176. /**
  177.  * Get the total number of tracks of an async voice
  178.  * \param[in] device The device that contains the async voice
  179.  * \param[in] voiceID The async voice to query
  180.  * \return The number of tracks, or -1 on error (call SDL_GetError() for more info)
  181.  *
  182.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  183.  * \sa kit_kmixerAsyncPlayPVS
  184.  * \sa kit_kmixerAsyncGetActiveTracks
  185.  * \sa kit_kmixerAsyncGetTrackPlayState
  186.  * \sa kit_kmixerAsyncGetTrackPosition
  187.  */
  188. extern Uint32 kit_kmixerAsyncGetNumTracks(kit_kmixerDevice* device, Uint32 voiceID);
  189.  
  190. /**
  191.  * Get a boolean of whether a given async track is playing or not
  192.  * \param[in] device The device that contains the async voice
  193.  * \param[in] voiceID The async voice to query
  194.  * \param[in] trackNum The track to query
  195.  * \return The aforementioned boolean, or -1 on error (call SDL_GetError() for more info)
  196.  *
  197.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  198.  * \sa kit_kmixerAsyncPlayPVS
  199.  * \sa kit_kmixerAsyncGetActiveTracks
  200.  * \sa kit_kmixerAsyncGetNumTracks
  201.  * \sa kit_kmixerAsyncGetTrackPosition
  202.  */
  203. extern int kit_kmixerAsyncGetTrackPlayState(kit_kmixerDevice* device, Uint32 voiceID,
  204.                                             Uint32 trackNum);
  205.  
  206. /**
  207.  * Get current position of a track's clip, in seconds
  208.  * \param[in] device The device that contains the async voice
  209.  * \param[in] voiceID The async voice to query
  210.  * \param[in] trackNum The track to query
  211.  * \return The current position, or NAN on error (call SDL_GetError() for more info)
  212.  *
  213.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  214.  * \sa kit_kmixerAsyncPlayPVS
  215.  * \sa kit_kmixerAsyncGetActiveTracks
  216.  * \sa kit_kmixerAsyncGetNumTracks
  217.  * \sa kit_kmixerAsyncGetTrackPlayState
  218.  */
  219. extern double kit_kmixerAsyncGetTrackPosition(kit_kmixerDevice* device, Uint32 voiceID,
  220.                                               Uint32 trackNum);
  221.  
  222.  
  223. /**
  224.  * Set an async track's deltaS value, in units per sample (to be applied to current speed every sample)
  225.  * \param[in] device The device that contains the async voice
  226.  * \param[in] voiceID The async voice to query
  227.  * \param[in] trackNum The track to query
  228.  * \param[in] deltaS The new deltaS value to set the track to
  229.  * \return 0 on success, or -1 on error (call SDL_GetError() for more info)
  230.  *
  231.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  232.  * \sa kit_kmixerAsyncPlayPVS
  233.  */
  234. extern int kit_kmixerAsyncSetTrackDeltaS(kit_kmixerDevice* device, Uint32 voiceID,
  235.                                          Uint32 trackNum, double deltaS);
  236.  
  237. /**
  238.  * Set an async track's deltaS value, in seconds to speed = 0->1  or 1->0 (to be applied to current speed every sample)
  239.  * \param[in] device The device that contains the async voice
  240.  * \param[in] voiceID The async voice to query
  241.  * \param[in] trackNum The track to query
  242.  * \param[in] deltaS_seconds The new deltaS value to set the track to
  243.  * \return 0 on success, or -1 on error (call SDL_GetError() for more info)
  244.  *
  245.  * \remark (refer to to kit_kmixerAsyncPlayPVS 's remark)
  246.  * \sa kit_kmixerAsyncPlayPVS
  247.  */
  248. static inline int kit_kmixerAsyncSetTrackDeltaS2(kit_kmixerDevice* device, Uint32 voiceID,
  249.                                                  Uint32 trackNum, double deltaS_seconds)
  250. {
  251.   int freq = device->_spec.freq;
  252.   return kit_kmixerAsyncSetTrackDeltaS(device, voiceID, trackNum, (1.0/deltaS_seconds)/freq);
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement