6 #include <SDL2/SDL_mixer.h>
9 #include "./sound_sample.h"
18 sound_sample_t *create_sound_sample_from_file(const char *filepath)
22 lt_t *lt = create_lt();
27 sound_sample_t *sound_sample = PUSH_LT(lt, malloc(sizeof(sound_sample_t)), free);
28 if (sound_sample == NULL) {
29 throw_error(ERROR_TYPE_LIBC);
33 sound_sample->chunk = PUSH_LT(lt, Mix_LoadWAV(filepath), Mix_FreeChunk);
34 if (sound_sample->chunk == NULL) {
35 throw_error(ERROR_TYPE_SDL2_MIXER);
39 sound_sample->lt = lt;
44 void destroy_sound_sample(sound_sample_t *sound_sample)
47 RETURN_LT0(sound_sample->lt);
50 int sound_sample_play(sound_sample_t *sound_sample, int channel)
53 return Mix_PlayChannel(channel, sound_sample->chunk, 1);