diff src/libmlk-core/core/sound.c @ 343:9eb25198d706

js: add sound bindings
author David Demelier <markand@malikania.fr>
date Sat, 16 Oct 2021 22:17:09 +0200
parents 8f9937403749
children 12367bfc2df6
line wrap: on
line diff
--- a/src/libmlk-core/core/sound.c	Sat Oct 16 09:47:10 2021 +0200
+++ b/src/libmlk-core/core/sound.c	Sat Oct 16 22:17:09 2021 +0200
@@ -23,6 +23,8 @@
 
 #include "error.h"
 #include "sound.h"
+#include "vfs.h"
+#include "vfs_p.h"
 
 int
 sound_open(struct sound *snd, const char *path)
@@ -52,6 +54,22 @@
 }
 
 int
+sound_openvfs(struct sound *snd, struct vfs_file *file)
+{
+	assert(snd);
+	assert(vfs_file_ok(file));
+
+	SDL_RWops *ops;
+
+	if (!(ops = vfs_to_rw(file)))
+		return -1;
+	if (!(snd->handle = Mix_LoadWAV_RW(ops, 1)))
+		return errorf("%s", SDL_GetError());
+
+	return 0;
+}
+
+int
 sound_ok(const struct sound *snd)
 {
 	return snd && snd->handle;