comparison libmlk-core/mlk/core/sys.c @ 471:3761e33d429e

core: sys -> mlk_sys
author David Demelier <markand@malikania.fr>
date Mon, 27 Feb 2023 11:18:52 +0100
parents 4607eea0eabc
children d6757c30658e
comparison
equal deleted inserted replaced
470:5690bbf12528 471:3761e33d429e
46 #include "panic.h" 46 #include "panic.h"
47 #include "sound.h" 47 #include "sound.h"
48 #include "sys.h" 48 #include "sys.h"
49 #include "sys_p.h" 49 #include "sys_p.h"
50 50
51 ALCdevice *audio_dev = NULL; 51 ALCdevice *mlk__audio_dev = NULL;
52 ALCcontext *audio_ctx = NULL; 52 ALCcontext *mlk__audio_ctx = NULL;
53 53
54 static struct { 54 static struct {
55 char organization[128]; 55 char organization[128];
56 char name[128]; 56 char name[128];
57 } info = { 57 } info = {
74 74
75 return str; 75 return str;
76 } 76 }
77 77
78 static const char * 78 static const char *
79 user_directory(enum sys_dir kind) 79 user_directory(enum mlk_sys_dir kind)
80 { 80 {
81 /* Kept for future use. */ 81 /* Kept for future use. */
82 (void)kind; 82 (void)kind;
83 83
84 static char path[PATH_MAX]; 84 static char path[PATH_MAX];
169 return MLK_ERR_NO_MEM; 169 return MLK_ERR_NO_MEM;
170 } 170 }
171 } 171 }
172 172
173 int 173 int
174 sys_init(const char *organization, const char *name) 174 mlk_sys_init(const char *organization, const char *name)
175 { 175 {
176 #if defined(__MINGW64__) 176 #if defined(__MINGW64__)
177 /* On MinGW buffering leads to painful debugging. */ 177 /* On MinGW buffering leads to painful debugging. */
178 setbuf(stderr, NULL); 178 setbuf(stderr, NULL);
179 setbuf(stdout, NULL); 179 setbuf(stdout, NULL);
196 SetEnvironmentVariable("ALSOFT_LOGLEVEL", "0"); 196 SetEnvironmentVariable("ALSOFT_LOGLEVEL", "0");
197 #else 197 #else
198 putenv("ALSOFT_LOGLEVEL=0"); 198 putenv("ALSOFT_LOGLEVEL=0");
199 #endif 199 #endif
200 200
201 if (!(audio_dev = alcOpenDevice(NULL))) 201 if (!(mlk__audio_dev = alcOpenDevice(NULL)))
202 return errorf("unable to create audio device"); 202 return errorf("unable to create audio device");
203 if (!(audio_ctx = alcCreateContext(audio_dev, NULL))) 203 if (!(mlk__audio_ctx = alcCreateContext(mlk__audio_dev, NULL)))
204 return errorf("unable to create audio context"); 204 return errorf("unable to create audio context");
205 205
206 alcMakeContextCurrent(audio_ctx); 206 alcMakeContextCurrent(mlk__audio_ctx);
207 207
208 return 0; 208 return 0;
209 } 209 }
210 210
211 const char * 211 const char *
212 sys_dir(enum sys_dir kind) 212 mlk_sys_dir(enum mlk_sys_dir kind)
213 { 213 {
214 return user_directory(kind); 214 return user_directory(kind);
215 } 215 }
216 216
217 int 217 int
218 sys_mkdir(const char *directory) 218 mlk_sys_mkdir(const char *directory)
219 { 219 {
220 char path[PATH_MAX], *p; 220 char path[PATH_MAX], *p;
221 221
222 /* Copy the directory to normalize and iterate over '/'. */ 222 /* Copy the directory to normalize and iterate over '/'. */
223 mlk_util_strlcpy(path, directory, sizeof (path)); 223 mlk_util_strlcpy(path, directory, sizeof (path));
246 246
247 return mkpath(path); 247 return mkpath(path);
248 } 248 }
249 249
250 void 250 void
251 sys_finish(void) 251 mlk_sys_finish(void)
252 { 252 {
253 TTF_Quit(); 253 TTF_Quit();
254 IMG_Quit(); 254 IMG_Quit();
255 SDL_Quit(); 255 SDL_Quit();
256 256
257 alcMakeContextCurrent(NULL); 257 alcMakeContextCurrent(NULL);
258 258
259 if (audio_ctx) { 259 if (mlk__audio_ctx) {
260 alcDestroyContext(audio_ctx); 260 alcDestroyContext(mlk__audio_ctx);
261 audio_ctx = NULL; 261 mlk__audio_ctx = NULL;
262 } 262 }
263 if (audio_dev) { 263 if (mlk__audio_dev) {
264 alcCloseDevice(audio_dev); 264 alcCloseDevice(mlk__audio_dev);
265 audio_dev = NULL; 265 mlk__audio_dev = NULL;
266 } 266 }
267 } 267 }
268 268
269 static int 269 static int
270 create_audiostream(struct audiostream **ptr, SNDFILE *file, const SF_INFO *info) 270 create_audiostream(struct mlk__audiostream **ptr, SNDFILE *file, const SF_INFO *info)
271 { 271 {
272 struct audiostream *stream; 272 struct mlk__audiostream *stream;
273 int ret = 0; 273 int ret = 0;
274 274
275 stream = mlk_alloc_new(1, sizeof (*stream)); 275 stream = mlk_alloc_new(1, sizeof (*stream));
276 stream->samplerate = info->samplerate; 276 stream->samplerate = info->samplerate;
277 stream->samplesz = info->frames * info->channels; 277 stream->samplesz = info->frames * info->channels;
299 299
300 return ret; 300 return ret;
301 } 301 }
302 302
303 int 303 int
304 audiostream_open(struct audiostream **stream, const char *path) 304 mlk__audiostream_open(struct mlk__audiostream **stream, const char *path)
305 { 305 {
306 assert(path); 306 assert(path);
307 307
308 SF_INFO info; 308 SF_INFO info;
309 SNDFILE *file; 309 SNDFILE *file;
313 313
314 return create_audiostream(stream, file, &info); 314 return create_audiostream(stream, file, &info);
315 } 315 }
316 316
317 int 317 int
318 audiostream_openmem(struct audiostream **stream, const void *data, size_t datasz) 318 mlk__audiostream_openmem(struct mlk__audiostream **stream, const void *data, size_t datasz)
319 { 319 {
320 assert(data); 320 assert(data);
321 321
322 SF_VIRTUAL_IO io = { 322 SF_VIRTUAL_IO io = {
323 .get_filelen = vio_get_filelen, 323 .get_filelen = vio_get_filelen,
337 337
338 return create_audiostream(stream, file, &info); 338 return create_audiostream(stream, file, &info);
339 } 339 }
340 340
341 void 341 void
342 audiostream_finish(struct audiostream *s) 342 mlk__audiostream_finish(struct mlk__audiostream *s)
343 { 343 {
344 assert(s); 344 assert(s);
345 345
346 alDeleteBuffers(1, &s->buffer); 346 alDeleteBuffers(1, &s->buffer);
347 alSourcei(s->source, AL_BUFFER, 0); 347 alSourcei(s->source, AL_BUFFER, 0);