- [NEW] Adaptació de àudio en progrés

This commit is contained in:
2026-04-17 13:46:22 +02:00
parent 9c4c94093c
commit e6d4833e8b
3 changed files with 675 additions and 535 deletions

View File

@@ -6,19 +6,19 @@ namespace mini
{ {
namespace audio namespace audio
{ {
JA_Music_t *current_music = NULL; int current_music = -1;
#define MAX_SOUNDS 50 //#define MAX_SOUNDS 50
JA_Sound_t *sounds[MAX_SOUNDS]; //JA_Sound_t *sounds[MAX_SOUNDS];
void init() { void init() {
JA_Init(48000, SDL_AUDIO_S16, 1); jail::audio::init();
for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL; //for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
} }
void quit() { void quit() {
if (current_music != NULL) JA_DeleteMusic(current_music); //if (current_music != NULL) JA_DeleteMusic(current_music);
for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]); //for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
JA_Quit(); jail::audio::quit();
} }
namespace music namespace music
@@ -26,45 +26,45 @@ namespace mini
void play(const char *filename, const int loop) { void play(const char *filename, const int loop) {
int size; int size;
char *buffer = file::getfilebuffer(filename, size); char *buffer = file::getfilebuffer(filename, size);
if (current_music != NULL) JA_DeleteMusic(current_music); if (current_music != -1) jail::audio::music::destroy(current_music);
current_music = JA_LoadMusic((Uint8*)buffer, size); current_music = jail::audio::music::load((uint8_t*)buffer, size);
JA_PlayMusic(current_music, loop); jail::audio::music::play(current_music, loop);
} }
void pause() { void pause() {
JA_PauseMusic(); jail::audio::music::pause();
} }
void resume() { void resume() {
JA_ResumeMusic(); jail::audio::music::resume();
} }
void stop(const int t) { void stop(const int t) {
JA_StopMusic(); jail::audio::music::stop();
} }
namespace pos { namespace pos {
void set(float value) void set(float value)
{ {
JA_SetMusicPosition(value); jail::audio::music::setPosition(value);
} }
float get() float get()
{ {
return JA_GetMusicPosition(); return jail::audio::music::getPosition();
} }
} }
namespace enable { namespace enable {
void set(const bool value) void set(const bool value)
{ {
JA_EnableMusic(value); jail::audio::music::enable(value);
file::setconfigvalue("music", value?"true":"false"); file::setconfigvalue("music", value?"true":"false");
} }
const bool get() const bool get()
{ {
return JA_IsMusicEnabled(); return jail::audio::music::isEnabled();
} }
} }
} }
@@ -74,40 +74,32 @@ namespace mini
int load(const char *filename) { int load(const char *filename) {
int size; int size;
char *buffer = file::getfilebuffer(filename, size); char *buffer = file::getfilebuffer(filename, size);
int i=0; return jail::audio::sound::load((uint8_t*)buffer, size);
while (i<MAX_SOUNDS && sounds[i]!=NULL) i++;
if (i==MAX_SOUNDS) { i=0; JA_DeleteSound(sounds[i]); }
sounds[i]=JA_LoadSound((Uint8*)buffer, size);
return i;
} }
void free(int soundfile) { void free(int soundfile) {
JA_DeleteSound(sounds[soundfile]); return jail::audio::sound::destroy(soundfile);
sounds[soundfile] = NULL;
} }
int play(int soundfile, const int volume) { int play(int soundfile, const int volume) {
const int channel = JA_PlaySound(sounds[soundfile], 0); // [TODO] Ficar el volumen
JA_SetSoundVolume(128); return jail::audio::sound::play(soundfile, 0);
//Mix_Volume(channel, volume!=-1?volume:MIX_MAX_VOLUME);
return channel;
} }
void stop(int soundchannel) { void stop(int soundchannel) {
JA_StopChannel(soundchannel); return jail::audio::sound::channel::stop(soundchannel);
//Mix_HaltChannel(soundchannel);
} }
namespace enable { namespace enable {
void set(const bool value) void set(const bool value)
{ {
JA_EnableSound(value); return jail::audio::sound::enable(value);
file::setconfigvalue("sound", value?"true":"false"); file::setconfigvalue("sound", value?"true":"false");
} }
const bool get() const bool get()
{ {
return JA_IsSoundEnabled(); return jail::audio::sound::isEnabled();
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,42 +1,57 @@
#pragma once #pragma once
#include <SDL3/SDL.h> #include <stdint.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED }; namespace jail
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED }; {
namespace audio
{
void init(/*const int freq, const SDL_AudioFormat format, const int channels*/);
void quit();
struct JA_Sound_t; namespace music
struct JA_Music_t; {
//struct JA_Music_t;
enum state { invalid, playing, paused, stopped, disabled };
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels); int load(const char* filename);
void JA_Quit(); int load(const uint8_t* buffer, uint32_t length);
void play(int mus, int loop = -1);
void pause();
void resume();
void stop();
void fadeOut(int milliseconds);
state getState();
void destroy(int mus);
float setVolume(float vol);
void setPosition(float value);
float getPosition();
void enable(bool value);
bool isEnabled();
}
JA_Music_t *JA_LoadMusic(const char* filename); namespace sound
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length); {
void JA_PlayMusic(JA_Music_t *music, const int loop = -1); //struct JA_Sound_t;
void JA_PauseMusic(); int create(uint8_t* buffer, uint32_t length);
void JA_ResumeMusic(); int load(uint8_t* buffer, uint32_t length);
void JA_StopMusic(); int load(const char* filename);
void JA_FadeOutMusic(const int milliseconds); int play(int snd, int loop = 0);
JA_Music_state JA_GetMusicState(); int playOnChannel(int snd, int chan, int loop = 0);
void JA_DeleteMusic(JA_Music_t *music); void destroy(int snd);
float JA_SetMusicVolume(float volume); float setVolume(float vol);
void JA_SetMusicPosition(float value); void enable(bool value);
float JA_GetMusicPosition(); bool isEnabled();
void JA_EnableMusic(const bool value);
const bool JA_IsMusicEnabled(); namespace channel
{
enum state { invalid, free, playing, paused, disabled };
void pause(int chan);
void resume(int chan);
void stop(int chan);
state getState(int chan);
}
}
}
}
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(const char* filename);
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
void JA_PauseChannel(const int channel);
void JA_ResumeChannel(const int channel);
void JA_StopChannel(const int channel);
JA_Channel_state JA_GetChannelState(const int channel);
void JA_DeleteSound(JA_Sound_t *sound);
float JA_SetSoundVolume(float volume);
void JA_EnableSound(const bool value);
const bool JA_IsSoundEnabled();
float JA_SetVolume(float volume);