src/audio/SDL_sysaudio.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5262 b530ef003506
child 5578 44463666df04
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
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@2049
    48
    /* Some flags to push duplicate code into the core and reduce #ifdefs. */
icculus@2049
    49
    int ProvidesOwnCallbackThread:1;
icculus@2049
    50
    int SkipMixerLock:1;
icculus@2049
    51
    int HasCaptureSupport:1;
icculus@2049
    52
    int OnlyHasDefaultOutputDevice:1;
icculus@2049
    53
    int OnlyHasDefaultInputDevice:1;
icculus@2049
    54
} SDL_AudioDriverImpl;
icculus@2049
    55
icculus@2049
    56
icculus@2049
    57
typedef struct SDL_AudioDriver
slouken@1895
    58
{
slouken@1895
    59
    /* * * */
slouken@1895
    60
    /* The name of this audio driver */
slouken@1895
    61
    const char *name;
slouken@0
    62
slouken@1895
    63
    /* * * */
slouken@1895
    64
    /* The description of this audio driver */
slouken@1895
    65
    const char *desc;
slouken@0
    66
icculus@2049
    67
    SDL_AudioDriverImpl impl;
icculus@2049
    68
} SDL_AudioDriver;
slouken@0
    69
slouken@322
    70
slouken@2716
    71
/* Streamer */
slouken@2716
    72
typedef struct
slouken@2716
    73
{
slouken@2716
    74
    Uint8 *buffer;
slouken@2716
    75
    int max_len;                /* the maximum length in bytes */
slouken@2716
    76
    int read_pos, write_pos;    /* the position of the write and read heads in bytes */
slouken@2716
    77
} SDL_AudioStreamer;
slouken@2716
    78
slouken@2716
    79
icculus@2049
    80
/* Define the SDL audio driver structure */
icculus@2049
    81
struct SDL_AudioDevice
icculus@2049
    82
{
slouken@1895
    83
    /* * * */
slouken@1895
    84
    /* Data common to all devices */
slouken@0
    85
slouken@1895
    86
    /* The current audio specification (shared with audio thread) */
slouken@1895
    87
    SDL_AudioSpec spec;
slouken@0
    88
slouken@1895
    89
    /* An audio conversion block for audio format emulation */
slouken@1895
    90
    SDL_AudioCVT convert;
slouken@0
    91
slouken@2716
    92
    /* The streamer, if sample rate conversion necessitates it */
slouken@2716
    93
    int use_streamer;
slouken@2716
    94
    SDL_AudioStreamer streamer;
slouken@2716
    95
slouken@1895
    96
    /* Current state flags */
icculus@2049
    97
    int iscapture;
slouken@1895
    98
    int enabled;
slouken@1895
    99
    int paused;
slouken@1895
   100
    int opened;
slouken@0
   101
slouken@1895
   102
    /* Fake audio buffer for when the audio hardware is busy */
slouken@1895
   103
    Uint8 *fake_stream;
slouken@0
   104
slouken@1895
   105
    /* A semaphore for locking the mixing buffers */
slouken@1895
   106
    SDL_mutex *mixer_lock;
slouken@0
   107
slouken@1895
   108
    /* A thread to feed the audio device */
slouken@1895
   109
    SDL_Thread *thread;
slouken@3578
   110
    SDL_threadID threadid;
slouken@0
   111
slouken@1895
   112
    /* * * */
slouken@1895
   113
    /* Data private to this driver */
slouken@1895
   114
    struct SDL_PrivateAudioData *hidden;
slouken@0
   115
};
slouken@0
   116
#undef _THIS
slouken@0
   117
slouken@1895
   118
typedef struct AudioBootStrap
slouken@1895
   119
{
slouken@1895
   120
    const char *name;
slouken@1895
   121
    const char *desc;
slouken@2060
   122
    int (*init) (SDL_AudioDriverImpl * impl);
slouken@2060
   123
    int demand_only:1;          /* 1==request explicitly, or it won't be available. */
slouken@0
   124
} AudioBootStrap;
slouken@0
   125
icculus@2049
   126
#endif /* _SDL_sysaudio_h */
slouken@0
   127
slouken@1895
   128
/* vi: set ts=4 sw=4 expandtab: */