- [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
{
JA_Music_t *current_music = NULL;
#define MAX_SOUNDS 50
JA_Sound_t *sounds[MAX_SOUNDS];
int current_music = -1;
//#define MAX_SOUNDS 50
//JA_Sound_t *sounds[MAX_SOUNDS];
void init() {
JA_Init(48000, SDL_AUDIO_S16, 1);
for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
jail::audio::init();
//for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
}
void quit() {
if (current_music != NULL) JA_DeleteMusic(current_music);
for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
JA_Quit();
//if (current_music != NULL) JA_DeleteMusic(current_music);
//for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
jail::audio::quit();
}
namespace music
@@ -26,45 +26,45 @@ namespace mini
void play(const char *filename, const int loop) {
int size;
char *buffer = file::getfilebuffer(filename, size);
if (current_music != NULL) JA_DeleteMusic(current_music);
current_music = JA_LoadMusic((Uint8*)buffer, size);
JA_PlayMusic(current_music, loop);
if (current_music != -1) jail::audio::music::destroy(current_music);
current_music = jail::audio::music::load((uint8_t*)buffer, size);
jail::audio::music::play(current_music, loop);
}
void pause() {
JA_PauseMusic();
jail::audio::music::pause();
}
void resume() {
JA_ResumeMusic();
jail::audio::music::resume();
}
void stop(const int t) {
JA_StopMusic();
jail::audio::music::stop();
}
namespace pos {
void set(float value)
{
JA_SetMusicPosition(value);
jail::audio::music::setPosition(value);
}
float get()
{
return JA_GetMusicPosition();
return jail::audio::music::getPosition();
}
}
namespace enable {
void set(const bool value)
{
JA_EnableMusic(value);
jail::audio::music::enable(value);
file::setconfigvalue("music", value?"true":"false");
}
const bool get()
{
return JA_IsMusicEnabled();
return jail::audio::music::isEnabled();
}
}
}
@@ -74,40 +74,32 @@ namespace mini
int load(const char *filename) {
int size;
char *buffer = file::getfilebuffer(filename, size);
int i=0;
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;
return jail::audio::sound::load((uint8_t*)buffer, size);
}
void free(int soundfile) {
JA_DeleteSound(sounds[soundfile]);
sounds[soundfile] = NULL;
return jail::audio::sound::destroy(soundfile);
}
int play(int soundfile, const int volume) {
const int channel = JA_PlaySound(sounds[soundfile], 0);
JA_SetSoundVolume(128);
//Mix_Volume(channel, volume!=-1?volume:MIX_MAX_VOLUME);
return channel;
// [TODO] Ficar el volumen
return jail::audio::sound::play(soundfile, 0);
}
void stop(int soundchannel) {
JA_StopChannel(soundchannel);
//Mix_HaltChannel(soundchannel);
return jail::audio::sound::channel::stop(soundchannel);
}
namespace enable {
void set(const bool value)
{
JA_EnableSound(value);
return jail::audio::sound::enable(value);
file::setconfigvalue("sound", value?"true":"false");
}
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
#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 };
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
namespace jail
{
namespace audio
{
void init(/*const int freq, const SDL_AudioFormat format, const int channels*/);
void quit();
struct JA_Sound_t;
struct JA_Music_t;
namespace music
{
//struct JA_Music_t;
enum state { invalid, playing, paused, stopped, disabled };
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
void JA_Quit();
int load(const char* filename);
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);
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length);
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
void JA_PauseMusic();
void JA_ResumeMusic();
void JA_StopMusic();
void JA_FadeOutMusic(const int milliseconds);
JA_Music_state JA_GetMusicState();
void JA_DeleteMusic(JA_Music_t *music);
float JA_SetMusicVolume(float volume);
void JA_SetMusicPosition(float value);
float JA_GetMusicPosition();
void JA_EnableMusic(const bool value);
const bool JA_IsMusicEnabled();
namespace sound
{
//struct JA_Sound_t;
int create(uint8_t* buffer, uint32_t length);
int load(uint8_t* buffer, uint32_t length);
int load(const char* filename);
int play(int snd, int loop = 0);
int playOnChannel(int snd, int chan, int loop = 0);
void destroy(int snd);
float setVolume(float vol);
void enable(bool value);
bool isEnabled();
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);