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