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