aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-08-30 03:14:11 +0200
committerkdx <kikoodx@paranoici.org>2023-08-30 03:23:43 +0200
commitae4af8c1f825d904eaea3be5cdf02e097e30a30f (patch)
tree1fe909e14991cce9d50f07ba4066940ce7424282
parentac6731996d2137d44d60acf4e41f903081a57512 (diff)
downloadtzr-ae4af8c1f825d904eaea3be5cdf02e097e30a30f.tar.gz
soloud wav playback
-rw-r--r--headers/TZR_types.h6
-rw-r--r--sources/TZR_DestroyResource.c5
-rw-r--r--sources/TZR_DirectResourceLoad.c14
-rw-r--r--sources/TZR_PlaySound.c12
4 files changed, 35 insertions, 2 deletions
diff --git a/headers/TZR_types.h b/headers/TZR_types.h
index 58aee45..f796930 100644
--- a/headers/TZR_types.h
+++ b/headers/TZR_types.h
@@ -93,9 +93,15 @@ struct TZR_Image {
SDL_Texture *ptr;
};
+#ifdef TZR_SOLOUD
+struct TZR_Sound {
+ Wav *ptr;
+};
+#else
struct TZR_Sound {
Mix_Chunk *ptr;
};
+#endif
struct TZR_Resource {
TZR_ResourceType type;
diff --git a/sources/TZR_DestroyResource.c b/sources/TZR_DestroyResource.c
index 8112a09..7536017 100644
--- a/sources/TZR_DestroyResource.c
+++ b/sources/TZR_DestroyResource.c
@@ -16,8 +16,13 @@ TZR_DestroyResource(TZR_Resource *res, int free_path)
SDL_DestroyTexture(res->image.ptr);
break;
case TZR_RES_SOUND:
+#ifdef TZR_SOLOUD
+ if (res->sound.ptr != NULL)
+ Wav_destroy(res->sound.ptr);
+#else
if (res->sound.ptr != NULL)
Mix_FreeChunk(res->sound.ptr);
+#endif
break;
default:
fprintf(stderr, "unknown resource type %u\n", res->type);
diff --git a/sources/TZR_DirectResourceLoad.c b/sources/TZR_DirectResourceLoad.c
index 6bbbc5c..7b53a5e 100644
--- a/sources/TZR_DirectResourceLoad.c
+++ b/sources/TZR_DirectResourceLoad.c
@@ -100,6 +100,19 @@ TZR_DirectResourceLoad(TZR_Resource *res, const void *data, int size)
SDL_Log("audio mixer disabled, skip loading");
return -1;
}
+#ifdef TZR_SOLOUD
+ Wav *wav = Wav_create();
+ if (wav == NULL) {
+ SDL_Log("Wav_create failed");
+ return -1;
+ }
+ if (Wav_loadMemEx(wav, data, size, true, false)) {
+ SDL_Log("Wav_loadMem failed");
+ Wav_destroy(wav);
+ return -1;
+ }
+ res->sound.ptr = wav;
+#else
SDL_RWops *const rw = SDL_RWFromConstMem(data, size);
if (rw == NULL)
return sdl_error(-1);
@@ -108,6 +121,7 @@ TZR_DirectResourceLoad(TZR_Resource *res, const void *data, int size)
if (chunk == NULL)
return sdl_error(-1);
res->sound.ptr = chunk;
+#endif
} break;
default:
fprintf(stderr, "invalid type\n");
diff --git a/sources/TZR_PlaySound.c b/sources/TZR_PlaySound.c
index 2fe6cb3..aa0d862 100644
--- a/sources/TZR_PlaySound.c
+++ b/sources/TZR_PlaySound.c
@@ -8,18 +8,26 @@ int
_TZR_PlaySound(const TZR_PlaySoundArgs *args)
{
if (args->id == 0) {
- fprintf(stderr, "args->id is 0\n");
+ SDL_Log("args->id is 0");
return -1;
}
if (TZR_GetResourceType(args->id) != TZR_RES_SOUND) {
- fprintf(stderr, "%u isn't a sound\n", args->id);
+ SDL_Log("%u isn't a sound", args->id);
return -1;
}
TZR_Sound *const sound = &TZR_GetResourcePointer(args->id)->sound;
+
+#ifdef TZR_SOLOUD
+ const unsigned handle = Soloud_play(___tzr_soloud, sound->ptr);
+ Soloud_setVolume(___tzr_soloud, handle, args->volume);
+ Soloud_setLooping(___tzr_soloud, handle, args->loop);
+#else
Mix_VolumeChunk(sound->ptr, args->volume * MIX_MAX_VOLUME);
if (Mix_PlayChannel(-1, sound->ptr, args->loop) < 0)
return sdl_error(-1);
+#endif
+
return 0;
}