Crash with error code 2 for mixer

This commit is contained in:
Mylloon 2023-05-03 18:21:12 +02:00
parent 5ec256d701
commit ed442f1aec
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,4 +1,5 @@
#include "../includes/audio.h"
#include <stdio.h>
// Stocke les données à propos de la musique
static double average;
@ -16,13 +17,22 @@ void callback(void *_, Uint8 *stream, int size) {
void initMusic(Mix_Music *music, const char *filename) {
Mix_Init(MIX_INIT_MID);
Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 1024);
music = Mix_LoadMUS(filename);
if (Mix_OpenAudio(44100, AUDIO_S16LSB, 1, 1024)) {
fprintf(stderr, "Erreur Mix_OpenAudio\n");
exit(2);
};
if (!(music = Mix_LoadMUS(filename))) {
fprintf(stderr, "Erreur Mix_LoadMUS\n");
exit(2);
}
Mix_VolumeMusic(MIX_MAX_VOLUME / 10);
Mix_SetPostMix(callback, NULL);
Mix_PlayMusic(music, 1);
if (Mix_PlayMusic(music, 1)) {
fprintf(stderr, "Erreur Mix_PlayMusic\n");
exit(2);
};
}
void freeMusic(Mix_Music *music) {