1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //
21 // unix_snd_main.c
22 //
23
24 #include "../client/snd_local.h"
25 #include "unix_local.h"
26
27 cVar_t *s_bits;
28 cVar_t *s_speed;
29 cVar_t *s_channels;
30 cVar_t *s_system;
31
32 typedef enum sndSystem_s {
33 SNDSYS_NONE,
34
35 SNDSYS_ALSA,
36 SNDSYS_OSS,
37 SNDSYS_SDL,
38 } sndSystem_t;
39
40 static const char *s_sysStrings[] = {
41 "None",
42
43 "ALSA",
44 "OSS",
45 "SDL",
46
47 NULL
48 };
49
50 #define S_DEFAULTSYS SNDSYS_SDL
51
52 static sndSystem_t s_curSystem;
53
54 /*
55 =======================================================================
56
57 UNIX SOUND BACKEND
58
59 This attempts access to ALSA, OSS, and SDL audio systems.
60 =======================================================================
61 */
62
63 /*
64 ==============
65 SndImp_Init
66 ===============
67 */
SndImp_Init(void)68 qBool SndImp_Init (void)
69 {
70 sndSystem_t oldSystem;
71 qBool success;
72
73 // Register variables
74 if (!s_bits) {
75 s_bits = Cvar_Register ("s_bits", "16", CVAR_ARCHIVE);
76 s_speed = Cvar_Register ("s_speed", "0", CVAR_ARCHIVE);
77 s_channels = Cvar_Register ("s_channels", "2", CVAR_ARCHIVE);
78 s_system = Cvar_Register ("s_system", s_sysStrings[S_DEFAULTSYS], CVAR_ARCHIVE);
79 }
80
81 // Find the target system
82 oldSystem = s_curSystem;
83 if (!Q_stricmp (s_system->string, "alsa"))
84 s_curSystem = SNDSYS_ALSA;
85 else if (!Q_stricmp (s_system->string, "oss"))
86 s_curSystem = SNDSYS_OSS;
87 else if (!Q_stricmp (s_system->string, "sdl"))
88 s_curSystem = SNDSYS_SDL;
89 else {
90 Com_Printf (PRNT_ERROR, "SndImp_Init: Invalid s_system selection, defaulting to '%s'\n", s_sysStrings[S_DEFAULTSYS]);
91 s_curSystem = S_DEFAULTSYS;
92 }
93
94 mark0:
95 // Initialize the target system
96 success = qFalse;
97 switch (s_curSystem) {
98 case SNDSYS_ALSA:
99 // FIXME
100 break;
101
102 case SNDSYS_OSS:
103 success = OSS_Init ();
104 break;
105
106 case SNDSYS_SDL:
107 // FIXME
108 break;
109 }
110
111 // If failed, fall-back
112 if (!success && s_curSystem > SNDSYS_ALSA) {
113 Com_Printf (PRNT_WARNING, "%s failed, attempting next system\n", s_sysStrings[s_curSystem]);
114 s_curSystem--;
115 goto mark0;
116 }
117
118 // Done
119 return success;
120 }
121
122
123 /*
124 ==============
125 SndImp_Shutdown
126 ===============
127 */
SndImp_Shutdown(void)128 void SndImp_Shutdown (void)
129 {
130 switch (s_curSystem) {
131 case SNDSYS_ALSA:
132 // FIXME
133 break;
134
135 case SNDSYS_OSS:
136 OSS_Shutdown ();
137 break;
138
139 case SNDSYS_SDL:
140 // FIXME
141 break;
142 }
143
144 // Should never reach here
145 return;
146 }
147
148
149 /*
150 ==============
151 SndImp_GetDMAPos
152 ===============
153 */
SndImp_GetDMAPos(void)154 int SndImp_GetDMAPos (void)
155 {
156 switch (s_curSystem) {
157 case SNDSYS_ALSA:
158 // FIXME
159 return qFalse;
160
161 case SNDSYS_OSS:
162 return OSS_GetDMAPos ();
163
164 case SNDSYS_SDL:
165 // FIXME
166 return qFalse;
167 }
168
169 // Should never reach here
170 return 0;
171 }
172
173
174 /*
175 ==============
176 SndImp_BeginPainting
177 ===============
178 */
SndImp_BeginPainting(void)179 void SndImp_BeginPainting (void)
180 {
181 switch (s_curSystem) {
182 case SNDSYS_ALSA:
183 // FIXME
184 break;
185
186 case SNDSYS_OSS:
187 OSS_BeginPainting ();
188 break;
189
190 case SNDSYS_SDL:
191 // FIXME
192 break;
193 }
194 }
195
196
197 /*
198 ==============
199 SndImp_Submit
200
201 Send sound to device if buffer isn't really the DMA buffer
202 ===============
203 */
SndImp_Submit(void)204 void SndImp_Submit (void)
205 {
206 switch (s_curSystem) {
207 case SNDSYS_ALSA:
208 // FIXME
209 break;
210
211 case SNDSYS_OSS:
212 OSS_Submit ();
213 break;
214
215 case SNDSYS_SDL:
216 // FIXME
217 break;
218 }
219 }
220