SDL_audio.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef _SDL_audio_h
  2. #define _SDL_audio_h
  3. #include "SDL_stdinc.h"
  4. #include "SDL_error.h"
  5. #include "SDL_endian.h"
  6. #include "SDL_mutex.h"
  7. #include "SDL_thread.h"
  8. #include "SDL_rwops.h"
  9. #include "begin_code.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. typedef Uint16 SDL_AudioFormat;
  14. #define SDL_AUDIO_MASK_BITSIZE (0xFF)
  15. #define SDL_AUDIO_MASK_DATATYPE (1<<8)
  16. #define SDL_AUDIO_MASK_ENDIAN (1<<12)
  17. #define SDL_AUDIO_MASK_SIGNED (1<<15)
  18. #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
  19. #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
  20. #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
  21. #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
  22. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  23. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  24. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  25. #define AUDIO_U8 0x0008
  26. #define AUDIO_S8 0x8008
  27. #define AUDIO_U16LSB 0x0010
  28. #define AUDIO_S16LSB 0x8010
  29. #define AUDIO_U16MSB 0x1010
  30. #define AUDIO_S16MSB 0x9010
  31. #define AUDIO_U16 AUDIO_U16LSB
  32. #define AUDIO_S16 AUDIO_S16LSB
  33. #define AUDIO_S32LSB 0x8020
  34. #define AUDIO_S32MSB 0x9020
  35. #define AUDIO_S32 AUDIO_S32LSB
  36. #define AUDIO_F32LSB 0x8120
  37. #define AUDIO_F32MSB 0x9120
  38. #define AUDIO_F32 AUDIO_F32LSB
  39. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  40. #define AUDIO_U16SYS AUDIO_U16LSB
  41. #define AUDIO_S16SYS AUDIO_S16LSB
  42. #define AUDIO_S32SYS AUDIO_S32LSB
  43. #define AUDIO_F32SYS AUDIO_F32LSB
  44. #else
  45. #define AUDIO_U16SYS AUDIO_U16MSB
  46. #define AUDIO_S16SYS AUDIO_S16MSB
  47. #define AUDIO_S32SYS AUDIO_S32MSB
  48. #define AUDIO_F32SYS AUDIO_F32MSB
  49. #endif
  50. #define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
  51. #define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
  52. #define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
  53. #define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
  54. typedef void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream,
  55. int len);
  56. typedef struct SDL_AudioSpec
  57. {
  58. int freq;
  59. SDL_AudioFormat format;
  60. Uint8 channels;
  61. Uint8 silence;
  62. Uint16 samples;
  63. Uint16 padding;
  64. Uint32 size;
  65. SDL_AudioCallback callback;
  66. void *userdata;
  67. } SDL_AudioSpec;
  68. struct SDL_AudioCVT;
  69. typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
  70. SDL_AudioFormat format);
  71. #ifdef __GNUC__
  72. #define SDL_AUDIOCVT_PACKED __attribute__((packed))
  73. #else
  74. #define SDL_AUDIOCVT_PACKED
  75. #endif
  76. typedef struct SDL_AudioCVT
  77. {
  78. int needed;
  79. SDL_AudioFormat src_format;
  80. SDL_AudioFormat dst_format;
  81. double rate_incr;
  82. Uint8 *buf;
  83. int len;
  84. int len_cvt;
  85. int len_mult;
  86. double len_ratio;
  87. SDL_AudioFilter filters[10];
  88. int filter_index;
  89. } SDL_AUDIOCVT_PACKED SDL_AudioCVT;
  90. typedef int SDLCALL tSDL_GetNumAudioDrivers(void);
  91. typedef const char * SDLCALL tSDL_GetAudioDriver(int index);
  92. typedef int SDLCALL tSDL_AudioInit(const char *driver_name);
  93. typedef void SDLCALL tSDL_AudioQuit(void);
  94. typedef const char * SDLCALL tSDL_GetCurrentAudioDriver(void);
  95. typedef int SDLCALL tSDL_OpenAudio(SDL_AudioSpec * desired,
  96. SDL_AudioSpec * obtained);
  97. typedef Uint32 SDL_AudioDeviceID;
  98. typedef int SDLCALL tSDL_GetNumAudioDevices(int iscapture);
  99. typedef const char * SDLCALL tSDL_GetAudioDeviceName(int index,
  100. int iscapture);
  101. typedef SDL_AudioDeviceID SDLCALL tSDL_OpenAudioDevice(const char
  102. *device,
  103. int iscapture,
  104. const
  105. SDL_AudioSpec *
  106. desired,
  107. SDL_AudioSpec *
  108. obtained,
  109. int
  110. allowed_changes);
  111. typedef enum
  112. {
  113. SDL_AUDIO_STOPPED = 0,
  114. SDL_AUDIO_PLAYING,
  115. SDL_AUDIO_PAUSED
  116. } SDL_AudioStatus;
  117. typedef SDL_AudioStatus SDLCALL tSDL_GetAudioStatus(void);
  118. extern DECLSPEC SDL_AudioStatus SDLCALL
  119. SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
  120. typedef void SDLCALL tSDL_PauseAudio(int pause_on);
  121. typedef void SDLCALL tSDL_PauseAudioDevice(SDL_AudioDeviceID dev,
  122. int pause_on);
  123. typedef SDL_AudioSpec * SDLCALL tSDL_LoadWAV_RW(SDL_RWops * src,
  124. int freesrc,
  125. SDL_AudioSpec * spec,
  126. Uint8 ** audio_buf,
  127. Uint32 * audio_len);
  128. #define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
  129. SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
  130. typedef void SDLCALL tSDL_FreeWAV(Uint8 * audio_buf);
  131. typedef int SDLCALL tSDL_BuildAudioCVT(SDL_AudioCVT * cvt,
  132. SDL_AudioFormat src_format,
  133. Uint8 src_channels,
  134. int src_rate,
  135. SDL_AudioFormat dst_format,
  136. Uint8 dst_channels,
  137. int dst_rate);
  138. typedef int SDLCALL tSDL_ConvertAudio(SDL_AudioCVT * cvt);
  139. #define SDL_MIX_MAXVOLUME 128
  140. typedef void SDLCALL tSDL_MixAudio(Uint8 * dst, const Uint8 * src,
  141. Uint32 len, int volume);
  142. typedef void SDLCALL tSDL_MixAudioFormat(Uint8 * dst,
  143. const Uint8 * src,
  144. SDL_AudioFormat format,
  145. Uint32 len, int volume);
  146. typedef void SDLCALL tSDL_LockAudio(void);
  147. typedef void SDLCALL tSDL_LockAudioDevice(SDL_AudioDeviceID dev);
  148. typedef void SDLCALL tSDL_UnlockAudio(void);
  149. typedef void SDLCALL tSDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
  150. typedef void SDLCALL tSDL_CloseAudio(void);
  151. typedef void SDLCALL tSDL_CloseAudioDevice(SDL_AudioDeviceID dev);
  152. extern tSDL_GetNumAudioDrivers *SDL_GetNumAudioDrivers;
  153. extern tSDL_GetAudioDriver *SDL_GetAudioDriver;
  154. extern tSDL_AudioInit *SDL_AudioInit;
  155. extern tSDL_AudioQuit *SDL_AudioQuit;
  156. extern tSDL_GetCurrentAudioDriver *SDL_GetCurrentAudioDriver;
  157. extern tSDL_OpenAudio *SDL_OpenAudio;
  158. extern tSDL_GetNumAudioDevices *SDL_GetNumAudioDevices;
  159. extern tSDL_GetAudioDeviceName *SDL_GetAudioDeviceName;
  160. extern tSDL_OpenAudioDevice *SDL_OpenAudioDevice;
  161. extern tSDL_GetAudioStatus *SDL_GetAudioStatus;
  162. extern tSDL_PauseAudio *SDL_PauseAudio;
  163. extern tSDL_PauseAudioDevice *SDL_PauseAudioDevice;
  164. extern tSDL_LoadWAV_RW *SDL_LoadWAV_RW;
  165. extern tSDL_FreeWAV *SDL_FreeWAV;
  166. extern tSDL_BuildAudioCVT *SDL_BuildAudioCVT;
  167. extern tSDL_ConvertAudio *SDL_ConvertAudio;
  168. extern tSDL_MixAudio *SDL_MixAudio;
  169. extern tSDL_MixAudioFormat *SDL_MixAudioFormat;
  170. extern tSDL_LockAudio *SDL_LockAudio;
  171. extern tSDL_LockAudioDevice *SDL_LockAudioDevice;
  172. extern tSDL_UnlockAudio *SDL_UnlockAudio;
  173. extern tSDL_UnlockAudioDevice *SDL_UnlockAudioDevice;
  174. extern tSDL_CloseAudio *SDL_CloseAudio;
  175. extern tSDL_CloseAudioDevice *SDL_CloseAudioDevice;
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #include "close_code.h"
  180. #endif