Subversion Repositories eduke32

Rev

Rev 8387 | Rev 8755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1471 terminx 1
/*
2
 Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
8216 terminx 3
 
1471 terminx 4
 This program is free software; you can redistribute it and/or
5
 modify it under the terms of the GNU General Public License
6
 as published by the Free Software Foundation; either version 2
7
 of the License, or (at your option) any later version.
8216 terminx 8
 
1471 terminx 9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8216 terminx 12
 
1471 terminx 13
 See the GNU General Public License for more details.
8216 terminx 14
 
1471 terminx 15
 You should have received a copy of the GNU General Public License
16
 along with this program; if not, write to the Free Software
8216 terminx 17
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
1471 terminx 19
 */
20
 
21
/**
22
 * Abstraction layer for hiding the various supported sound devices
23
 * behind a common and opaque interface called on by MultiVoc.
24
 */
25
 
26
#include "drivers.h"
27
 
8218 terminx 28
#include "driver_adlib.h"
8752 terminx 29
#include "driver_sf2.h"
8381 terminx 30
#include "_midi.h"
1471 terminx 31
 
8216 terminx 32
#ifdef RENDERTYPESDL
1471 terminx 33
# include "driver_sdl.h"
34
#endif
35
 
8216 terminx 36
#ifdef _WIN32
37
# include "driver_directsound.h"
38
# include "driver_winmm.h"
39
#endif
1471 terminx 40
 
8216 terminx 41
int ASS_PCMSoundDriver  = ASS_AutoDetect;
42
int ASS_MIDISoundDriver = ASS_AutoDetect;
8219 terminx 43
int ASS_EMIDICard = -1;
1471 terminx 44
 
8221 terminx 45
#define UNSUPPORTED_PCM          nullptr,nullptr,nullptr,nullptr,nullptr,nullptr
8381 terminx 46
#define UNSUPPORTED_MIDI         EMIDI_GeneralMIDI,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr
47
#define UNSUPPORTED_COMPLETELY   nullptr,nullptr,UNSUPPORTED_PCM,UNSUPPORTED_MIDI
8216 terminx 48
 
8381 terminx 49
static struct
50
{
51
    const char *DriverName;
52
 
8216 terminx 53
    int  (*GetError)(void);
54
    const char *(*ErrorString)(int);
55
 
56
    int  (*PCM_Init)(int *, int *, void *);
57
    void (*PCM_Shutdown)(void);
58
    int  (*PCM_BeginPlayback)(char *, int, int, void (*)(void));
59
    void (*PCM_StopPlayback)(void);
60
    void (*PCM_Lock)(void);
61
    void (*PCM_Unlock)(void);
62
 
8381 terminx 63
    int  EMIDICardType;
8216 terminx 64
    int  (*MIDI_Init)(midifuncs *);
65
    void (*MIDI_Shutdown)(void);
8381 terminx 66
    int  (*MIDI_StartPlayback)(void);
8216 terminx 67
    void (*MIDI_HaltPlayback)(void);
68
    void (*MIDI_SetTempo)(int tempo, int division);
69
    void (*MIDI_Lock)(void);
70
    void (*MIDI_Unlock)(void);
8381 terminx 71
    void (*MIDI_Service)(void);
1471 terminx 72
} SoundDrivers[ASS_NumSoundCards] = {
8387 terminx 73
 
8216 terminx 74
    // Simple DirectMedia Layer
75
    {
76
        "SDL",
8239 terminx 77
    #ifdef RENDERTYPESDL
8216 terminx 78
        SDLDrv_GetError,
79
        SDLDrv_ErrorString,
80
        SDLDrv_PCM_Init,
81
        SDLDrv_PCM_Shutdown,
82
        SDLDrv_PCM_BeginPlayback,
83
        SDLDrv_PCM_StopPlayback,
84
        SDLDrv_PCM_Lock,
85
        SDLDrv_PCM_Unlock,
86
        UNSUPPORTED_MIDI,
87
    #else
88
        UNSUPPORTED_COMPLETELY
89
    #endif
8239 terminx 90
    },
8219 terminx 91
 
7126 terminx 92
    // Windows DirectSound
5270 terminx 93
    {
8216 terminx 94
        "DirectSound",
8239 terminx 95
    #ifdef RENDERTYPEWIN
8216 terminx 96
        DirectSoundDrv_GetError,
97
        DirectSoundDrv_ErrorString,
98
        DirectSoundDrv_PCM_Init,
99
        DirectSoundDrv_PCM_Shutdown,
100
        DirectSoundDrv_PCM_BeginPlayback,
101
        DirectSoundDrv_PCM_StopPlayback,
102
        DirectSoundDrv_PCM_Lock,
103
        DirectSoundDrv_PCM_Unlock,
104
        UNSUPPORTED_MIDI,
105
    #else
106
        UNSUPPORTED_COMPLETELY
107
    #endif
8239 terminx 108
    },
8216 terminx 109
 
8219 terminx 110
    // OPL3 emulation
111
    {
8381 terminx 112
        "AdLib OPL3 emulation",
8219 terminx 113
        AdLibDrv_GetError,
114
        AdLibDrv_ErrorString,
115
 
116
        UNSUPPORTED_PCM,
117
 
8381 terminx 118
        EMIDI_AdLib,
8219 terminx 119
        AdLibDrv_MIDI_Init,
120
        AdLibDrv_MIDI_Shutdown,
121
        AdLibDrv_MIDI_StartPlayback,
122
        AdLibDrv_MIDI_HaltPlayback,
123
        AdLibDrv_MIDI_SetTempo,
124
        nullptr,
125
        nullptr,
8381 terminx 126
        AdLibDrv_MIDI_Service,
8219 terminx 127
    },
128
 
8216 terminx 129
    // Windows MultiMedia system
5272 terminx 130
    {
8381 terminx 131
        "Windows MME",
8239 terminx 132
    #ifdef _WIN32
8216 terminx 133
        WinMMDrv_GetError,
134
        WinMMDrv_ErrorString,
135
 
136
        UNSUPPORTED_PCM,
137
 
8381 terminx 138
        EMIDI_GeneralMIDI,
8216 terminx 139
        WinMMDrv_MIDI_Init,
140
        WinMMDrv_MIDI_Shutdown,
141
        WinMMDrv_MIDI_StartPlayback,
142
        WinMMDrv_MIDI_HaltPlayback,
143
        WinMMDrv_MIDI_SetTempo,
144
        WinMMDrv_MIDI_Lock,
145
        WinMMDrv_MIDI_Unlock,
8381 terminx 146
        WinMMDrv_MIDI_Service,
8216 terminx 147
    #else
148
        UNSUPPORTED_COMPLETELY
149
    #endif
8239 terminx 150
    },
8752 terminx 151
 
152
    // TinySoundFont
153
    {
154
        "SoundFont2 synthesizer",
155
        SF2_GetError,
156
        SF2_ErrorString,
157
 
158
        UNSUPPORTED_PCM,
159
 
160
        EMIDI_GeneralMIDI,
161
        SF2_MIDI_Init,
162
        SF2_MIDI_Shutdown,
163
        SF2_MIDI_StartPlayback,
164
        SF2_MIDI_HaltPlayback,
165
        SF2_MIDI_SetTempo,
166
        nullptr,
167
        nullptr,
168
        SF2_MIDI_Service,
169
    },
1471 terminx 170
};
171
 
172
 
8216 terminx 173
int SoundDriver_IsPCMSupported(int driver)  { return (SoundDrivers[driver].PCM_Init != 0); }
174
int SoundDriver_IsMIDISupported(int driver) { return (SoundDrivers[driver].MIDI_Init != 0); }
175
const char *SoundDriver_GetName(int driver) { return  SoundDrivers[driver].DriverName; }
176
 
177
int SoundDriver_PCM_GetError(void)
1471 terminx 178
{
8221 terminx 179
    if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver))
8216 terminx 180
        return -1;
8221 terminx 181
 
8216 terminx 182
    return SoundDrivers[ASS_PCMSoundDriver].GetError();
1471 terminx 183
}
184
 
8216 terminx 185
const char * SoundDriver_PCM_ErrorString( int ErrorNumber )
1471 terminx 186
{
8221 terminx 187
    if (ASS_PCMSoundDriver < 0 || ASS_PCMSoundDriver >= ASS_NumSoundCards)
5270 terminx 188
        return "No sound driver selected.";
8221 terminx 189
 
190
    if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver))
5270 terminx 191
        return "Unsupported sound driver selected.";
8221 terminx 192
 
8216 terminx 193
    return SoundDrivers[ASS_PCMSoundDriver].ErrorString(ErrorNumber);
194
}
1471 terminx 195
 
8216 terminx 196
int SoundDriver_MIDI_GetError(void)
197
{
8221 terminx 198
    if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver))
8216 terminx 199
        return -1;
8221 terminx 200
 
8216 terminx 201
    return SoundDrivers[ASS_MIDISoundDriver].GetError();
1471 terminx 202
}
203
 
8216 terminx 204
const char * SoundDriver_MIDI_ErrorString( int ErrorNumber )
1471 terminx 205
{
8221 terminx 206
    if (ASS_MIDISoundDriver < 0 || ASS_MIDISoundDriver >= ASS_NumSoundCards)
8216 terminx 207
        return "No sound driver selected.";
8221 terminx 208
 
209
    if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver))
8216 terminx 210
        return "Unsupported sound driver selected.";
8221 terminx 211
 
8216 terminx 212
    return SoundDrivers[ASS_MIDISoundDriver].ErrorString(ErrorNumber);
1471 terminx 213
}
214
 
8216 terminx 215
int SoundDriver_PCM_Init(int *mixrate, int *numchannels, void *initdata)
216
{
217
    return SoundDrivers[ASS_PCMSoundDriver].PCM_Init(mixrate, numchannels, initdata);
218
}
1471 terminx 219
 
8216 terminx 220
int SoundDriver_PCM_BeginPlayback(char *BufferStart, int BufferSize, int NumDivisions, void (*CallBackFunc)(void))
1471 terminx 221
{
8216 terminx 222
    return SoundDrivers[ASS_PCMSoundDriver].PCM_BeginPlayback(BufferStart, BufferSize, NumDivisions, CallBackFunc);
1471 terminx 223
}
224
 
8216 terminx 225
void SoundDriver_PCM_Shutdown(void)                        { SoundDrivers[ASS_PCMSoundDriver].PCM_Shutdown(); }
226
void SoundDriver_PCM_StopPlayback(void)                    { SoundDrivers[ASS_PCMSoundDriver].PCM_StopPlayback(); }
227
void SoundDriver_PCM_Lock(void)                            { SoundDrivers[ASS_PCMSoundDriver].PCM_Lock(); }
228
void SoundDriver_PCM_Unlock(void)                          { SoundDrivers[ASS_PCMSoundDriver].PCM_Unlock(); }
229
int  SoundDriver_MIDI_Init(midifuncs *funcs)               { return SoundDrivers[ASS_MIDISoundDriver].MIDI_Init(funcs); }
8381 terminx 230
int  SoundDriver_MIDI_StartPlayback(void)                  { return SoundDrivers[ASS_MIDISoundDriver].MIDI_StartPlayback(); }
8216 terminx 231
void SoundDriver_MIDI_Shutdown(void)                       { SoundDrivers[ASS_MIDISoundDriver].MIDI_Shutdown(); }
232
void SoundDriver_MIDI_HaltPlayback(void)                   { SoundDrivers[ASS_MIDISoundDriver].MIDI_HaltPlayback(); }
233
void SoundDriver_MIDI_SetTempo(int tempo, int division)    { SoundDrivers[ASS_MIDISoundDriver].MIDI_SetTempo(tempo, division); }
8219 terminx 234
void SoundDriver_MIDI_Lock(void)                           { if (SoundDrivers[ASS_MIDISoundDriver].MIDI_Lock) SoundDrivers[ASS_MIDISoundDriver].MIDI_Lock(); }
235
void SoundDriver_MIDI_Unlock(void)                         { if (SoundDrivers[ASS_MIDISoundDriver].MIDI_Unlock) SoundDrivers[ASS_MIDISoundDriver].MIDI_Unlock(); }
8381 terminx 236
int  SoundDriver_MIDI_GetCardType(void)                    { return SoundDrivers[ASS_MIDISoundDriver].EMIDICardType; }
5270 terminx 237
 
8216 terminx 238
// vim:ts=4:sw=4:expandtab: