]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/sound_samples.c
(#553) Remove labels->enabled
[nothing.git] / src / game / sound_samples.c
index de5cbf72d0ee4e4f08439037aa9c0ee8d1b56f1b..d1e9d7efe4968fd1ea8184835835bba455be5e96 100644 (file)
@@ -6,8 +6,9 @@
 
 #include "math/pi.h"
 #include "sound_samples.h"
-#include "system/error.h"
+#include "system/log.h"
 #include "system/lt.h"
+#include "system/nth_alloc.h"
 
 struct Sound_samples
 {
@@ -39,18 +40,16 @@ Sound_samples *create_sound_samples(const char *sample_files[],
         return NULL;
     }
 
-    Sound_samples *sound_samples = PUSH_LT(lt, malloc(sizeof(Sound_samples)), free);
+    Sound_samples *sound_samples = PUSH_LT(lt, nth_alloc(sizeof(Sound_samples)), free);
     if (sound_samples == NULL) {
-        throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
     }
 
     sound_samples->samples = PUSH_LT(
         lt,
-        malloc(sizeof(Mix_Chunk*) * sample_files_count),
+        nth_alloc(sizeof(Mix_Chunk*) * sample_files_count),
         free);
     if (sound_samples->samples == NULL) {
-        throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
     }
 
@@ -60,7 +59,7 @@ Sound_samples *create_sound_samples(const char *sample_files[],
             Mix_LoadWAV(sample_files[i]),
             Mix_FreeChunk);
         if (sound_samples->samples[i] == NULL) {
-            throw_error(ERROR_TYPE_SDL2_MIXER);
+            log_fail("Could not load '%s': %s\n", sample_files[i], Mix_GetError());
             RETURN_LT(lt, NULL);
         }
     }
@@ -88,7 +87,7 @@ int sound_samples_play_sound(Sound_samples *sound_samples,
     if (sound_index < sound_samples->samples_count) {
         const int free_channel = mix_get_free_channel();
 
-        printf("Found free channel: %d\n", free_channel);
+        log_info("Found free channel: %d\n", free_channel);
 
         if (free_channel >= 0) {
             return Mix_PlayChannel(free_channel, sound_samples->samples[sound_index], loops);