SDL_sysaudio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../SDL_internal.h"
  19. #ifndef _SDL_sysaudio_h
  20. #define _SDL_sysaudio_h
  21. #include "SDL_mutex.h"
  22. #include "SDL_thread.h"
  23. /* The SDL audio driver */
  24. typedef struct SDL_AudioDevice SDL_AudioDevice;
  25. #define _THIS SDL_AudioDevice *_this
  26. /* Used by audio targets during DetectDevices() */
  27. typedef void (*SDL_AddAudioDevice)(const char *name);
  28. typedef struct SDL_AudioDriverImpl
  29. {
  30. void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn);
  31. int (*OpenDevice) (_THIS, const char *devname, int iscapture);
  32. void (*ThreadInit) (_THIS); /* Called by audio thread at start */
  33. void (*WaitDevice) (_THIS);
  34. void (*PlayDevice) (_THIS);
  35. Uint8 *(*GetDeviceBuf) (_THIS);
  36. void (*WaitDone) (_THIS);
  37. void (*CloseDevice) (_THIS);
  38. void (*LockDevice) (_THIS);
  39. void (*UnlockDevice) (_THIS);
  40. void (*Deinitialize) (void);
  41. /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
  42. /* Some flags to push duplicate code into the core and reduce #ifdefs. */
  43. int ProvidesOwnCallbackThread;
  44. int SkipMixerLock; /* !!! FIXME: do we need this anymore? */
  45. int HasCaptureSupport;
  46. int OnlyHasDefaultOutputDevice;
  47. int OnlyHasDefaultInputDevice;
  48. } SDL_AudioDriverImpl;
  49. typedef struct SDL_AudioDriver
  50. {
  51. /* * * */
  52. /* The name of this audio driver */
  53. const char *name;
  54. /* * * */
  55. /* The description of this audio driver */
  56. const char *desc;
  57. SDL_AudioDriverImpl impl;
  58. char **outputDevices;
  59. int outputDeviceCount;
  60. char **inputDevices;
  61. int inputDeviceCount;
  62. } SDL_AudioDriver;
  63. /* Streamer */
  64. typedef struct
  65. {
  66. Uint8 *buffer;
  67. int max_len; /* the maximum length in bytes */
  68. int read_pos, write_pos; /* the position of the write and read heads in bytes */
  69. } SDL_AudioStreamer;
  70. /* Define the SDL audio driver structure */
  71. struct SDL_AudioDevice
  72. {
  73. /* * * */
  74. /* Data common to all devices */
  75. /* The current audio specification (shared with audio thread) */
  76. SDL_AudioSpec spec;
  77. /* An audio conversion block for audio format emulation */
  78. SDL_AudioCVT convert;
  79. /* The streamer, if sample rate conversion necessitates it */
  80. int use_streamer;
  81. SDL_AudioStreamer streamer;
  82. /* Current state flags */
  83. int iscapture;
  84. int enabled;
  85. int paused;
  86. int opened;
  87. /* Fake audio buffer for when the audio hardware is busy */
  88. Uint8 *fake_stream;
  89. /* A semaphore for locking the mixing buffers */
  90. SDL_mutex *mixer_lock;
  91. /* A thread to feed the audio device */
  92. SDL_Thread *thread;
  93. SDL_threadID threadid;
  94. /* * * */
  95. /* Data private to this driver */
  96. struct SDL_PrivateAudioData *hidden;
  97. };
  98. #undef _THIS
  99. typedef struct AudioBootStrap
  100. {
  101. const char *name;
  102. const char *desc;
  103. int (*init) (SDL_AudioDriverImpl * impl);
  104. int demand_only; /* 1==request explicitly, or it won't be available. */
  105. } AudioBootStrap;
  106. #endif /* _SDL_sysaudio_h */
  107. /* vi: set ts=4 sw=4 expandtab: */