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