kettek2/wiki/games/newsboy/Newsboy_0x00/engine/Music.c

71 lines
1.7 KiB
C

#include "Music.h"
#include "string.h"
#include "globals.h"
struct Music *loadMusic(const char *name) {
char *full_path = malloc(1);
full_path = setStringF(full_path, "%s%s%s", MUSIC_DIR, name, MUSIC_EXT);
struct Music *music = malloc(sizeof(struct Music));
music->name = malloc(1);
music->name = copyString(music->name, name);
music->music = Mix_LoadMUS(full_path);
if (music->music == NULL) {
report(ERROR, "loadMusic", "Mix_LoadMUS(\"%s\"): %s", full_path, Mix_GetError());
// dunno
}
free(full_path);
return music;
}
void freeMusic(struct Music *music) {
free(music->name);
Mix_FreeMusic(music->music);
music->music = NULL;
free(music);
}
int playMusic(struct Music *music) {
if (music == NULL) return 1;
if (music->music == NULL) return 2;
Mix_FadeInMusic(music->music, -1, 1000);
return 0;
}
int stopMusic() {
Mix_FadeOutMusic(1000);
return 0;
}
struct Sound *loadSound(const char *name) {
char *full_path = malloc(1);
full_path = setStringF(full_path, "%s%s%s", SFX_DIR, name, SFX_EXT);
struct Sound *sound = malloc(sizeof(struct Sound));
sound->name = malloc(1);
sound->name = copyString(sound->name, name);
sound->sound = Mix_LoadWAV(full_path);
if (sound->sound == NULL) {
report(ERROR, "loadSound", "Mix_LoadWAV(\"%s\"): %s", full_path, Mix_GetError());
// dunno
}
free(full_path);
return sound;
}
void freeSound(struct Sound *sound) {
free(sound->name);
Mix_FreeChunk(sound->sound);
sound->sound = NULL;
free(sound);
}
int playSound(struct Sound *sound) {
if (sound == NULL) return 1;
if (sound->sound == NULL) return 2;
Mix_PlayChannel(-1, sound->sound, 0);
return 0;
}
int stopSound() {
return 0;
}