normalitzat Audio

This commit is contained in:
2026-04-18 11:42:29 +02:00
parent 34a41ad25c
commit 6246b5d89d
17 changed files with 740 additions and 233 deletions

View File

@@ -30,17 +30,17 @@ namespace Defaults::Video {
namespace Defaults::Audio {
constexpr bool ENABLED = true;
constexpr int VOLUME = 100;
constexpr float VOLUME = 1.0F;
} // namespace Defaults::Audio
namespace Defaults::Music {
constexpr bool ENABLED = true;
constexpr int VOLUME = 100;
constexpr float VOLUME = 0.8F;
} // namespace Defaults::Music
namespace Defaults::Sound {
constexpr bool ENABLED = true;
constexpr int VOLUME = 100;
constexpr float VOLUME = 1.0F;
} // namespace Defaults::Sound
namespace Defaults::Loading {

View File

@@ -8,7 +8,7 @@
#include <iostream> // for basic_ostream, char_traits, operator<<
#include <numeric> // for accumulate
#include "core/audio/jail_audio.hpp" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
#include "core/audio/audio.hpp" // for Audio
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for inputs_e, Input, REPEAT_TRUE, REPEAT_FALSE
#include "core/locale/lang.h" // for Lang
@@ -1307,7 +1307,7 @@ void Game::updateHiScore() {
// Si se supera la máxima puntuación emite sonido
if (hiScoreAchieved == false) {
hiScoreAchieved = true;
JA_PlaySound(hiScoreSound);
Audio::get()->playSound(hiScoreSound);
}
}
}
@@ -1459,9 +1459,9 @@ void Game::updateStage() {
}
}
updateHiScore();
JA_StopMusic();
Audio::get()->stopMusic();
}
JA_PlaySound(stageChangeSound);
Audio::get()->playSound(stageChangeSound);
stageBitmapCounter = 0;
enemySpeed = defaultEnemySpeed;
setBalloonSpeed(enemySpeed);
@@ -1499,7 +1499,7 @@ void Game::updateDeath() {
if (!demo.enabled) {
const Uint8 index = rand() % 4;
JA_Sound_t *sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound};
JA_PlaySound(sound[index], 0);
Audio::get()->playSound(sound[index]);
}
}
} else {
@@ -1746,7 +1746,7 @@ void Game::destroyAllBalloons() {
enemyDeployCounter = 255;
if (!demo.enabled) {
JA_PlaySound(powerBallSound);
Audio::get()->playSound(powerBallSound);
}
effect.flash = true;
effect.shake = true;
@@ -1811,26 +1811,26 @@ void Game::checkPlayerItemCollision(Player *player) {
player->addScore(1000);
updateHiScore();
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n1000Sprite->getWidth() / 2), player->getPosY(), n1000Sprite);
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
break;
case ITEM_POINTS_2_GAVINA:
player->addScore(2500);
updateHiScore();
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n2500Sprite->getWidth() / 2), player->getPosY(), n2500Sprite);
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
break;
case ITEM_POINTS_3_PACMAR:
player->addScore(5000);
updateHiScore();
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
break;
case ITEM_CLOCK:
enableTimeStopItem();
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
break;
case ITEM_COFFEE:
@@ -1840,12 +1840,12 @@ void Game::checkPlayerItemCollision(Player *player) {
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
}
player->giveExtraHit();
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
break;
case ITEM_COFFEE_MACHINE:
player->setPowerUp(true);
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
coffeeMachineEnabled = false;
break;
@@ -1876,7 +1876,7 @@ void Game::checkBulletBalloonCollision() {
// Si no es el modo demo, genera un sonido
if (!demo.enabled) {
JA_PlaySound(balloonSound);
Audio::get()->playSound(balloonSound);
}
// Deshabilita la bala
@@ -1887,7 +1887,7 @@ void Game::checkBulletBalloonCollision() {
if ((droppeditem != NO_KIND) && !(demo.enabled) && !(demo.recording)) {
if (droppeditem != ITEM_COFFEE_MACHINE) {
createItem(droppeditem, balloon->getPosX(), balloon->getPosY());
JA_PlaySound(itemDropSound);
Audio::get()->playSound(itemDropSound);
} else {
createItem(droppeditem, players[index]->getPosX(), 0);
coffeeMachineEnabled = true;
@@ -1945,7 +1945,7 @@ void Game::updateItems() {
if (item->isEnabled()) {
item->update();
if (item->isOnFloor()) {
JA_PlaySound(coffeeMachineSound);
Audio::get()->playSound(coffeeMachineSound);
effect.shake = true;
}
}
@@ -2132,12 +2132,12 @@ void Game::killPlayer(Player *player) {
player->removeExtraHit();
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
if (!demo.enabled) {
JA_PlaySound(coffeeOutSound);
Audio::get()->playSound(coffeeOutSound);
}
} else if (deathSequence.phase == DeathPhase::None) {
if (!demo.enabled) {
JA_PauseMusic();
JA_PlaySound(playerCollisionSound);
Audio::get()->pauseMusic();
Audio::get()->playSound(playerCollisionSound);
}
stopAllBalloons(10);
shakeScreen();
@@ -2167,11 +2167,11 @@ void Game::updateDeathSequence() {
// Espera 500ms antes de completar la muerte
if (SDL_GetTicks() - deathSequence.phaseStartTicks >= 500) {
if (!demo.enabled) {
JA_PlaySound(coffeeOutSound);
Audio::get()->playSound(coffeeOutSound);
if (allPlayersAreDead()) {
JA_StopMusic();
Audio::get()->stopMusic();
} else {
JA_ResumeMusic();
Audio::get()->resumeMusic();
}
}
deathSequence.player->setAlive(false);
@@ -2234,7 +2234,7 @@ void Game::updateEnemyDeployCounter() {
// Actualiza el juego
void Game::update() {
// Actualiza el audio
JA_Update();
Audio::update();
// Actualiza los efectos basados en tiempo real (no en el throttle del juego)
updateDeathShake();
@@ -2541,7 +2541,7 @@ void Game::checkGameInput() {
player->setFireCooldown(10);
// Reproduce el sonido de disparo
JA_PlaySound(bulletSound);
Audio::get()->playSound(bulletSound);
demo.keys.fire = 1;
}
@@ -2555,7 +2555,7 @@ void Game::checkGameInput() {
player->setFireCooldown(10);
// Reproduce el sonido de disparo
JA_PlaySound(bulletSound);
Audio::get()->playSound(bulletSound);
demo.keys.fireLeft = 1;
}
@@ -2569,7 +2569,7 @@ void Game::checkGameInput() {
player->setFireCooldown(10);
// Reproduce el sonido de disparo
JA_PlaySound(bulletSound);
Audio::get()->playSound(bulletSound);
demo.keys.fireRight = 1;
}
@@ -2610,11 +2610,11 @@ void Game::renderMessages() {
if (timeStoppedCounter > 100) {
if (timeStoppedCounter % 30 == 0) {
JA_PlaySound(clockSound, false);
Audio::get()->playSound(clockSound);
}
} else {
if (timeStoppedCounter % 15 == 0) {
JA_PlaySound(clockSound, false);
Audio::get()->playSound(clockSound);
}
}
}
@@ -2652,8 +2652,8 @@ void Game::enableTimeStopItem() {
stopAllBalloons(TIME_STOPPED_COUNTER);
setTimeStopped(true);
incTimeStoppedCounter(TIME_STOPPED_COUNTER);
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
JA_PauseMusic();
if (Audio::getRealMusicState() == Audio::MusicState::PLAYING) {
Audio::get()->pauseMusic();
}
}
@@ -2662,8 +2662,8 @@ void Game::disableTimeStopItem() {
timeStopped = false;
setTimeStoppedCounter(0);
startAllBalloons();
if (JA_GetMusicState() == JA_MUSIC_PAUSED) {
JA_ResumeMusic();
if (Audio::getRealMusicState() == Audio::MusicState::PAUSED) {
Audio::get()->resumeMusic();
}
}
@@ -2729,11 +2729,11 @@ void Game::iterate() {
gameOverInitialized = false;
// Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
if ((Audio::getRealMusicState() == Audio::MusicState::STOPPED) || (Audio::getRealMusicState() == Audio::MusicState::STOPPED)) {
// Reproduce la música (nunca en modo demo: deja sonar la del título)
if (!gameCompleted && !demo.enabled) {
if (players[0]->isAlive()) {
JA_PlayMusic(gameMusic);
Audio::get()->playMusic(gameMusic);
}
}
}
@@ -2781,7 +2781,7 @@ void Game::handleEvent(const SDL_Event *event) {
if (gameCompleted) {
gameOverPostFade = 1;
fade->activateFade();
JA_PlaySound(itemPickUpSound);
Audio::get()->playSound(itemPickUpSound);
}
}
}
@@ -2810,15 +2810,15 @@ void Game::updatePausedGame() {
const bool b = pauseCounter == 60;
const bool c = pauseCounter == 30;
if (a || b || c) {
JA_PlaySound(clockSound);
Audio::get()->playSound(clockSound);
}
pauseCounter--;
} else { // Ha finalizado el contador
section->name = SECTION_PROG_GAME;
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
if (JA_GetMusicState() == JA_MUSIC_PAUSED) {
JA_ResumeMusic();
if (Audio::getRealMusicState() == Audio::MusicState::PAUSED) {
Audio::get()->resumeMusic();
}
}
} else { // Actualiza la lógica del menu de pausa
@@ -2847,7 +2847,7 @@ void Game::updatePausedGame() {
if (fade->hasEnded()) {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
JA_StopMusic();
Audio::get()->stopMusic();
}
}
}
@@ -2897,8 +2897,8 @@ void Game::renderPausedGame() {
// Inicializa el estado de pausa del juego
void Game::enterPausedGame() {
// Pone en pausa la música
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
JA_PauseMusic();
if (Audio::getRealMusicState() == Audio::MusicState::PLAYING) {
Audio::get()->pauseMusic();
}
// Reinicia el menu

View File

@@ -114,7 +114,7 @@ namespace Options {
parseBoolField(aud, "enabled", audio.enabled);
if (aud.contains("volume")) {
try {
audio.volume = std::clamp(aud["volume"].get_value<int>(), 0, 100);
audio.volume = std::clamp(aud["volume"].get_value<float>(), 0.0F, 1.0F);
} catch (...) {}
}
if (aud.contains("music")) {
@@ -122,7 +122,7 @@ namespace Options {
parseBoolField(mus, "enabled", audio.music.enabled);
if (mus.contains("volume")) {
try {
audio.music.volume = std::clamp(mus["volume"].get_value<int>(), 0, 100);
audio.music.volume = std::clamp(mus["volume"].get_value<float>(), 0.0F, 1.0F);
} catch (...) {}
}
}
@@ -131,7 +131,7 @@ namespace Options {
parseBoolField(snd, "enabled", audio.sound.enabled);
if (snd.contains("volume")) {
try {
audio.sound.volume = std::clamp(snd["volume"].get_value<int>(), 0, 100);
audio.sound.volume = std::clamp(snd["volume"].get_value<float>(), 0.0F, 1.0F);
} catch (...) {}
}
}
@@ -307,7 +307,7 @@ namespace Options {
file << " current_crtpi_preset: \"" << video.shader.current_crtpi_preset_name << "\"\n\n";
// AUDIO
file << "# AUDIO (volume range: 0..100)\n";
file << "# AUDIO (volume range: 0.0..1.0)\n";
file << "audio:\n";
file << " enabled: " << boolToString(audio.enabled) << "\n";
file << " volume: " << audio.volume << "\n";

View File

@@ -56,17 +56,17 @@ namespace Options {
struct Music {
bool enabled = Defaults::Music::ENABLED;
int volume = Defaults::Music::VOLUME;
float volume = Defaults::Music::VOLUME;
};
struct Sound {
bool enabled = Defaults::Sound::ENABLED;
int volume = Defaults::Sound::VOLUME;
float volume = Defaults::Sound::VOLUME;
};
struct Audio {
bool enabled = Defaults::Audio::ENABLED;
int volume = Defaults::Audio::VOLUME;
float volume = Defaults::Audio::VOLUME;
Music music;
Sound sound;
};

View File

@@ -6,7 +6,7 @@
#include <iostream> // for char_traits, basic_ostream, operator<<
#include <string> // for basic_string
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
#include "core/audio/audio.hpp" // for Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
#include "core/locale/lang.h" // for Lang
@@ -71,7 +71,7 @@ Instructions::~Instructions() {
void Instructions::update() {
// Bombea el stream de música: si no se llama, el buffer se vacía y la
// música se corta hasta que volvamos a una escena que sí lo haga.
JA_Update();
Audio::update();
// Comprueba las entradas
checkInput();

View File

@@ -4,7 +4,7 @@
#include <string> // for basic_string
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_DeleteMusic, JA_LoadMusic
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
#include "core/locale/lang.h" // for Lang
@@ -149,7 +149,7 @@ Intro::Intro(SDL_Renderer *renderer, section_t *section) {
t->center(GAMECANVAS_CENTER_X);
}
JA_PlayMusic(music, 0);
Audio::get()->playMusic(music, 0);
}
// Destructor
@@ -177,7 +177,7 @@ void Intro::checkInput() {
if (GlobalInputs::handle()) { return; }
if (Input::get()->checkInput(input_pause, REPEAT_FALSE) || Input::get()->checkInput(input_accept, REPEAT_FALSE) || Input::get()->checkInput(input_fire_left, REPEAT_FALSE) || Input::get()->checkInput(input_fire_center, REPEAT_FALSE) || Input::get()->checkInput(input_fire_right, REPEAT_FALSE)) {
JA_StopMusic();
Audio::get()->stopMusic();
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
@@ -307,7 +307,7 @@ void Intro::updateScenes() {
if (bitmaps[5]->hasFinished() && texts[8]->hasFinished()) {
bitmaps[5]->setEnabled(false);
texts[8]->setEnabled(false);
JA_StopMusic();
Audio::get()->stopMusic();
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
@@ -321,7 +321,7 @@ void Intro::updateScenes() {
// Actualiza las variables del objeto
void Intro::update() {
JA_Update();
Audio::update();
checkInput();
if (SDL_GetTicks() - ticks > ticksSpeed) {
@@ -365,7 +365,7 @@ void Intro::render() {
// Bucle principal
void Intro::run() {
JA_PlayMusic(music, 0);
Audio::get()->playMusic(music, 0);
while (section->name == SECTION_PROG_INTRO) {
iterate();

View File

@@ -5,7 +5,7 @@
#include <algorithm> // for min
#include <string> // for basic_string
#include "core/audio/jail_audio.hpp" // for JA_StopMusic
#include "core/audio/audio.hpp" // for Audio::get, Audio::update
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
#include "core/rendering/screen.h" // for Screen
@@ -38,7 +38,7 @@ Logo::Logo(SDL_Renderer *renderer, section_t *section) {
ticks = 0;
ticksSpeed = 15;
JA_StopMusic();
Audio::get()->stopMusic();
}
// Destructor
@@ -85,7 +85,7 @@ void Logo::renderFade() {
// Actualiza las variables del objeto
void Logo::update() {
JA_Update();
Audio::update();
checkInput();
if (SDL_GetTicks() - ticks > ticksSpeed) {
@@ -120,7 +120,7 @@ void Logo::render() {
// Bucle para el logo del juego
void Logo::run() {
JA_StopMusic();
Audio::get()->stopMusic();
while (section->name == SECTION_PROG_LOGO) {
iterate();

View File

@@ -6,7 +6,7 @@
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
#include <string> // for basic_string, operator+, char_traits
#include "core/audio/jail_audio.hpp" // for JA_StopMusic, JA_GetMusicState, JA_Play...
#include "core/audio/audio.hpp" // for Audio
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
#include "core/input/input.h" // for Input, INPUT_USE_GAMECONTROLLER, INPUT_...
#include "core/locale/lang.h" // for Lang, ba_BA, en_UK, es_ES
@@ -212,7 +212,7 @@ void Title::init() {
// Actualiza las variables del objeto
void Title::update() {
// Actualiza el audio
JA_Update();
Audio::update();
// Comprueba las entradas
checkInput();
@@ -243,7 +243,7 @@ void Title::update() {
Screen::get()->blit();
// Reproduce el efecto sonoro
JA_PlaySound(crashSound);
Audio::get()->playSound(crashSound);
}
} break;
@@ -276,8 +276,8 @@ void Title::update() {
// Sección 3 - La pantalla de titulo con el menú y la música
case SUBSECTION_TITLE_3: {
if (counter > 0) { // Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
JA_PlayMusic(titleMusic);
if (Audio::getRealMusicState() == Audio::MusicState::STOPPED) {
Audio::get()->playMusic(titleMusic);
}
dustBitmapR->update();
@@ -291,19 +291,19 @@ void Title::update() {
case 0: // 1 PLAYER
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_1P;
JA_StopMusic();
Audio::get()->stopMusic();
break;
case 1: // 2 PLAYERS
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_2P;
JA_StopMusic();
Audio::get()->stopMusic();
break;
case 2: // QUIT
#ifndef __EMSCRIPTEN__
section->name = SECTION_PROG_QUIT;
JA_StopMusic();
Audio::get()->stopMusic();
#endif
break;

View File

@@ -5,7 +5,8 @@
#include <numeric> // for accumulate
#include <sstream> // for basic_stringstream
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_PlaySound, JA_DeleteSound
#include "core/audio/audio.hpp" // for Audio::get (playSound)
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_DeleteSound (propietat local)
#include "core/input/input.h" // for Input, REPEAT_FALSE, inputs_e
#include "core/rendering/text.h" // for Text
#include "core/resources/asset.h" // for Asset
@@ -758,28 +759,28 @@ void Menu::checkInput() {
if (Input::get()->checkInput(input_up, REPEAT_FALSE)) {
decreaseSelectorIndex();
if (soundMove) {
JA_PlaySound(soundMove);
Audio::get()->playSound(soundMove);
}
}
if (Input::get()->checkInput(input_down, REPEAT_FALSE)) {
increaseSelectorIndex();
if (soundMove) {
JA_PlaySound(soundMove);
Audio::get()->playSound(soundMove);
}
}
if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) {
itemSelected = selector.index;
if (soundAccept) {
JA_PlaySound(soundAccept);
Audio::get()->playSound(soundAccept);
}
}
if (Input::get()->checkInput(input_cancel, REPEAT_FALSE)) {
itemSelected = defaultActionWhenCancel;
if (soundCancel) {
JA_PlaySound(soundCancel);
Audio::get()->playSound(soundCancel);
}
}
}