src/audio/SDL_sysaudio.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 02 Feb 2014 00:53:27 -0800
changeset 8149 681eb46b8ac4
parent 8093 b43765095a6f
child 9012 aa058c87737b
permissions -rw-r--r--
Fixed bug 2374 - Update copyright for 2014...

Is it that time already??
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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_internal.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 /* Used by audio targets during DetectDevices() */
    34 typedef void (*SDL_AddAudioDevice)(const char *name);
    35 
    36 typedef struct SDL_AudioDriverImpl
    37 {
    38     void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn);
    39     int (*OpenDevice) (_THIS, const char *devname, int iscapture);
    40     void (*ThreadInit) (_THIS); /* Called by audio thread at start */
    41     void (*WaitDevice) (_THIS);
    42     void (*PlayDevice) (_THIS);
    43     Uint8 *(*GetDeviceBuf) (_THIS);
    44     void (*WaitDone) (_THIS);
    45     void (*CloseDevice) (_THIS);
    46     void (*LockDevice) (_THIS);
    47     void (*UnlockDevice) (_THIS);
    48     void (*Deinitialize) (void);
    49 
    50     /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
    51 
    52     /* Some flags to push duplicate code into the core and reduce #ifdefs. */
    53     int ProvidesOwnCallbackThread;
    54     int SkipMixerLock;  /* !!! FIXME: do we need this anymore? */
    55     int HasCaptureSupport;
    56     int OnlyHasDefaultOutputDevice;
    57     int OnlyHasDefaultInputDevice;
    58 } SDL_AudioDriverImpl;
    59 
    60 
    61 typedef struct SDL_AudioDriver
    62 {
    63     /* * * */
    64     /* The name of this audio driver */
    65     const char *name;
    66 
    67     /* * * */
    68     /* The description of this audio driver */
    69     const char *desc;
    70 
    71     SDL_AudioDriverImpl impl;
    72 
    73     char **outputDevices;
    74     int outputDeviceCount;
    75 
    76     char **inputDevices;
    77     int inputDeviceCount;
    78 } SDL_AudioDriver;
    79 
    80 
    81 /* Streamer */
    82 typedef struct
    83 {
    84     Uint8 *buffer;
    85     int max_len;                /* the maximum length in bytes */
    86     int read_pos, write_pos;    /* the position of the write and read heads in bytes */
    87 } SDL_AudioStreamer;
    88 
    89 
    90 /* Define the SDL audio driver structure */
    91 struct SDL_AudioDevice
    92 {
    93     /* * * */
    94     /* Data common to all devices */
    95 
    96     /* The current audio specification (shared with audio thread) */
    97     SDL_AudioSpec spec;
    98 
    99     /* An audio conversion block for audio format emulation */
   100     SDL_AudioCVT convert;
   101 
   102     /* The streamer, if sample rate conversion necessitates it */
   103     int use_streamer;
   104     SDL_AudioStreamer streamer;
   105 
   106     /* Current state flags */
   107     int iscapture;
   108     int enabled;
   109     int paused;
   110     int opened;
   111 
   112     /* Fake audio buffer for when the audio hardware is busy */
   113     Uint8 *fake_stream;
   114 
   115     /* A semaphore for locking the mixing buffers */
   116     SDL_mutex *mixer_lock;
   117 
   118     /* A thread to feed the audio device */
   119     SDL_Thread *thread;
   120     SDL_threadID threadid;
   121 
   122     /* * * */
   123     /* Data private to this driver */
   124     struct SDL_PrivateAudioData *hidden;
   125 };
   126 #undef _THIS
   127 
   128 typedef struct AudioBootStrap
   129 {
   130     const char *name;
   131     const char *desc;
   132     int (*init) (SDL_AudioDriverImpl * impl);
   133     int demand_only;  /* 1==request explicitly, or it won't be available. */
   134 } AudioBootStrap;
   135 
   136 #endif /* _SDL_sysaudio_h */
   137 
   138 /* vi: set ts=4 sw=4 expandtab: */