src/audio/SDL_sysaudio.h
author Ryan C. Gordon
Fri, 22 Jul 2011 00:09:58 -0700
changeset 5578 44463666df04
parent 5535 96594ac5fd1a
child 5589 469524dec694
permissions -rw-r--r--
Don't use a bitfield for this.

It pads out to an int anyhow, but causes code bloat as the compiler tries to
mask and shift for that specific bit.
     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     /* Some flags to push duplicate code into the core and reduce #ifdefs. */
    49     int ProvidesOwnCallbackThread:1;
    50     int SkipMixerLock:1;
    51     int HasCaptureSupport:1;
    52     int OnlyHasDefaultOutputDevice:1;
    53     int OnlyHasDefaultInputDevice:1;
    54 } SDL_AudioDriverImpl;
    55 
    56 
    57 typedef struct SDL_AudioDriver
    58 {
    59     /* * * */
    60     /* The name of this audio driver */
    61     const char *name;
    62 
    63     /* * * */
    64     /* The description of this audio driver */
    65     const char *desc;
    66 
    67     SDL_AudioDriverImpl impl;
    68 } SDL_AudioDriver;
    69 
    70 
    71 /* Streamer */
    72 typedef struct
    73 {
    74     Uint8 *buffer;
    75     int max_len;                /* the maximum length in bytes */
    76     int read_pos, write_pos;    /* the position of the write and read heads in bytes */
    77 } SDL_AudioStreamer;
    78 
    79 
    80 /* Define the SDL audio driver structure */
    81 struct SDL_AudioDevice
    82 {
    83     /* * * */
    84     /* Data common to all devices */
    85 
    86     /* The current audio specification (shared with audio thread) */
    87     SDL_AudioSpec spec;
    88 
    89     /* An audio conversion block for audio format emulation */
    90     SDL_AudioCVT convert;
    91 
    92     /* The streamer, if sample rate conversion necessitates it */
    93     int use_streamer;
    94     SDL_AudioStreamer streamer;
    95 
    96     /* Current state flags */
    97     int iscapture;
    98     int enabled;
    99     int paused;
   100     int opened;
   101 
   102     /* Fake audio buffer for when the audio hardware is busy */
   103     Uint8 *fake_stream;
   104 
   105     /* A semaphore for locking the mixing buffers */
   106     SDL_mutex *mixer_lock;
   107 
   108     /* A thread to feed the audio device */
   109     SDL_Thread *thread;
   110     SDL_threadID threadid;
   111 
   112     /* * * */
   113     /* Data private to this driver */
   114     struct SDL_PrivateAudioData *hidden;
   115 };
   116 #undef _THIS
   117 
   118 typedef struct AudioBootStrap
   119 {
   120     const char *name;
   121     const char *desc;
   122     int (*init) (SDL_AudioDriverImpl * impl);
   123     int demand_only;  /* 1==request explicitly, or it won't be available. */
   124 } AudioBootStrap;
   125 
   126 #endif /* _SDL_sysaudio_h */
   127 
   128 /* vi: set ts=4 sw=4 expandtab: */