- [FIX] La música ja sona be en un auricularet
- [CHG] El joc ja no usa SDL_Mixer, sinó JailAudio - [FIX] La música de game over ja no fa bucle - [FIX] Tanquem les coses abans d'eixir pa que Valgrind no s'enfade
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "jaudio.h"
|
||||
#include "jail_audio.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <stdio.h>
|
||||
#include "jfile.h"
|
||||
#include <vector>
|
||||
@@ -11,30 +11,29 @@ namespace audio
|
||||
struct sound_cache_t
|
||||
{
|
||||
std::string name;
|
||||
Mix_Chunk *chunk;
|
||||
JA_Sound_t *chunk;
|
||||
};
|
||||
|
||||
char *music_buffer = nullptr;
|
||||
Mix_Music *music = nullptr;
|
||||
//char *music_buffer = nullptr;
|
||||
JA_Music_t *music = nullptr;
|
||||
std::vector<sound_cache_t> sounds;
|
||||
std::string musica_actual = "";
|
||||
|
||||
// Inicialitza el sistema de só
|
||||
void init()
|
||||
{
|
||||
//int result =
|
||||
Mix_Init(MIX_INIT_OGG);// | MIX_INIT_WAVPACK);
|
||||
// Al final he ficat la configuració automàtica i au. Si en el futur necesitem canviar-ho pos se canvia
|
||||
//result =
|
||||
Mix_OpenAudio(48000, AUDIO_S16, 2, 512);
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
//Mix_Init(MIX_INIT_OGG);// | MIX_INIT_WAVPACK);
|
||||
//Mix_OpenAudio(48000, AUDIO_S16, 2, 512);
|
||||
}
|
||||
|
||||
// Tanca el sistema de só (no shit, sherlock)
|
||||
void quit()
|
||||
{
|
||||
for (auto sound : sounds) Mix_FreeChunk(sound.chunk);
|
||||
if (music) JA_DeleteMusic(music);
|
||||
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
|
||||
sounds.clear();
|
||||
Mix_CloseAudio();
|
||||
JA_Quit(); // Mix_CloseAudio();
|
||||
}
|
||||
|
||||
// Comença a reproduïr la música en questió
|
||||
@@ -42,46 +41,49 @@ namespace audio
|
||||
{
|
||||
if (!config::isMusicEnabled()) return;
|
||||
// Si hi havia musica carregada, alliberem memòria
|
||||
if (music_buffer) free(music_buffer);
|
||||
if (music) Mix_FreeMusic(music);
|
||||
//if (music_buffer) free(music_buffer);
|
||||
if (music) JA_DeleteMusic(music); //Mix_FreeMusic(music);
|
||||
|
||||
int size;
|
||||
music_buffer = file::getFileBuffer(filename, size);
|
||||
auto rwops = SDL_RWFromMem(music_buffer, size);
|
||||
auto mus = Mix_LoadMUS_RW(rwops, 1);
|
||||
char *buffer = file::getFileBuffer(filename, size);
|
||||
music = JA_LoadMusic((uint8_t*)buffer, size);
|
||||
free(buffer);
|
||||
//auto rwops = SDL_RWFromMem(music_buffer, size);
|
||||
//auto mus = Mix_LoadMUS_RW(rwops, 1);
|
||||
//free(music_buffer); // [RZC 03/10/2024] Si allibere el buffer, no funciona la música. Porca miseria! Per aixó l'allibere abans de carregar si ja estava usat.
|
||||
Mix_PlayMusic((Mix_Music *)mus, loop);
|
||||
//Mix_PlayMusic((Mix_Music *)mus, loop);
|
||||
JA_PlayMusic(music, loop);
|
||||
musica_actual = filename;
|
||||
}
|
||||
|
||||
// Pausa la música que està sonant ara
|
||||
void pauseMusic()
|
||||
{
|
||||
Mix_PauseMusic();
|
||||
JA_PauseMusic(); //Mix_PauseMusic();
|
||||
}
|
||||
|
||||
// Continua la música pausada
|
||||
void resumeMusic()
|
||||
{
|
||||
if (!config::isMusicEnabled()) return;
|
||||
Mix_ResumeMusic();
|
||||
JA_ResumeMusic(); //Mix_ResumeMusic();
|
||||
}
|
||||
|
||||
// Para la música que estava sonant
|
||||
void stopMusic()
|
||||
{
|
||||
Mix_HaltMusic();
|
||||
JA_StopMusic(); //Mix_HaltMusic();
|
||||
musica_actual = "";
|
||||
}
|
||||
|
||||
// Obté el estat actual de la música
|
||||
const music_state getMusicState()
|
||||
{
|
||||
if (Mix_PausedMusic())
|
||||
if (JA_GetMusicState() == JA_MUSIC_PAUSED)
|
||||
{
|
||||
return MUSIC_PAUSED;
|
||||
}
|
||||
else if (Mix_PlayingMusic())
|
||||
else if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
||||
{
|
||||
return MUSIC_PLAYING;
|
||||
}
|
||||
@@ -104,8 +106,11 @@ namespace audio
|
||||
{
|
||||
int size;
|
||||
char *buffer = file::getFileBuffer(filename, size);
|
||||
auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||
if (!chunk) printf("ERROR: %s\n", SDL_GetError());
|
||||
auto chunk = JA_LoadSound((uint8_t *)buffer, size);
|
||||
free(buffer);
|
||||
|
||||
//auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||
//if (!chunk) printf("ERROR: %s\n", SDL_GetError());
|
||||
sound_cache_t sound = { filename, chunk };
|
||||
sounds.push_back(sound);
|
||||
}
|
||||
@@ -116,7 +121,7 @@ namespace audio
|
||||
if (priority < config::getSoundMode()) return -1;
|
||||
for (auto sound : sounds)
|
||||
{
|
||||
if (sound.name == name) return Mix_PlayChannel(-1, sound.chunk, loop);
|
||||
if (sound.name == name) return JA_PlaySound(sound.chunk, loop); // Mix_PlayChannel(-1, sound.chunk, loop);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -125,37 +130,37 @@ namespace audio
|
||||
void pauseChannel(const int channel)
|
||||
{
|
||||
if (channel == -1) return;
|
||||
Mix_Pause(channel);
|
||||
JA_PauseChannel(channel); // Mix_Pause(channel);
|
||||
}
|
||||
|
||||
// Continua un canal pausat
|
||||
void resumeChannel(const int channel)
|
||||
{
|
||||
if (channel == -1) return;
|
||||
Mix_Resume(channel);
|
||||
JA_ResumeChannel(channel); // Mix_Resume(channel);
|
||||
}
|
||||
|
||||
// Para un canal que estava reproduïnt un só
|
||||
void stopChannel(const int channel)
|
||||
{
|
||||
if (channel == -1) return;
|
||||
Mix_HaltChannel(channel);
|
||||
JA_StopChannel(channel); // Mix_HaltChannel(channel);
|
||||
}
|
||||
|
||||
// Para tots els canals
|
||||
void stopAllChannel()
|
||||
{
|
||||
Mix_HaltChannel(-1);
|
||||
JA_StopChannel(-1); // Mix_HaltChannel(-1);
|
||||
}
|
||||
|
||||
// Obté l'estat d'un canal
|
||||
const channel_state getChannelState(const int channel)
|
||||
{
|
||||
if (Mix_Paused(channel))
|
||||
if (JA_GetChannelState(channel) == JA_CHANNEL_PAUSED)
|
||||
{
|
||||
return CHANNEL_PAUSED;
|
||||
}
|
||||
else if (Mix_Playing(channel))
|
||||
else if (JA_GetChannelState(channel) == JA_CHANNEL_PLAYING)
|
||||
{
|
||||
return CHANNEL_PLAYING;
|
||||
}
|
||||
@@ -168,6 +173,6 @@ namespace audio
|
||||
// Estableix el volum general
|
||||
const int setVolume(int volume)
|
||||
{
|
||||
return Mix_Volume(-1, volume);
|
||||
return JA_SetVolume(volume); // Mix_Volume(-1, volume);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user