refactor(core/audio): unificar format/canals/freq a Defaults::Audio (HC-02)
{SDL_AUDIO_S16, 2, 48000} apareixia com a literal a tres llocs de
jail_audio (Sound/Music/audio_spec) i audio.cpp:208 passava SDL_AUDIO_S16LE
i 2 canals per separat — dues convencions de format conviuen i els 2
canals eren número màgic.
Defaults::Audio guanya FORMAT (SDL_AUDIO_S16) i CHANNELS (2). Audio::
initSDLAudio passa ambdós junts a Ja::init. jail_audio obté un fallback
local Ja::DEFAULT_SPEC que consolida les tres instàncies; es queda
independent del projecte (no inclou utils/defaults.hpp) perquè l'engine
és reutilitzable.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6f0626c31f
commit
deb0fc2a4b
4 files changed
+13
-6
No files matched your search
@@ -19,7 +19,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|
|||||||
| ID | Título | Estado |
|
| ID | Título | Estado |
|
||||||
|----|--------|--------|
|
|----|--------|--------|
|
||||||
| COUP-01 | Encapsular globals `Ja::` en clase (engine sin estado global) | PENDING |
|
| COUP-01 | Encapsular globals `Ja::` en clase (engine sin estado global) | PENDING |
|
||||||
| HC-02 | Formato/canales/freq hardcodeado en 3+ sitios | PENDING |
|
| HC-02 | Formato/canales/freq hardcodeado en 3+ sitios | DONE |
|
||||||
| INCONS-02 | Doble `MusicState` + `getRealMusicState` como cache paralelo | PENDING |
|
| INCONS-02 | Doble `MusicState` + `getRealMusicState` como cache paralelo | PENDING |
|
||||||
| HC-01 | Parámetros de audio no configurables (viola convención del proyecto) | DONE |
|
| HC-01 | Parámetros de audio no configurables (viola convención del proyecto) | DONE |
|
||||||
| PATCH-01 | `toggleEnabled/toggleSound/toggleMusic` no reaplican volumen | PENDING |
|
| PATCH-01 | `toggleEnabled/toggleSound/toggleMusic` no reaplican volumen | PENDING |
|
||||||
@@ -41,7 +41,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|
|||||||
| ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas |
|
| ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas |
|
||||||
|----|---------------|----------|-----------|--------|-------|
|
|----|---------------|----------|-----------|--------|-------|
|
||||||
| HC-01 | `audio.hpp:53-55` | `VOLUME_STEP`, `FREQUENCY`, `DEFAULT_CROSSFADE_MS` viven en la clase, no en `Defaults::Audio` | Importante | DONE | Movidos a `Defaults::Audio::{VOLUME_STEP, FREQUENCY, CROSSFADE_MS}` en `utils/defaults.hpp` |
|
| HC-01 | `audio.hpp:53-55` | `VOLUME_STEP`, `FREQUENCY`, `DEFAULT_CROSSFADE_MS` viven en la clase, no en `Defaults::Audio` | Importante | DONE | Movidos a `Defaults::Audio::{VOLUME_STEP, FREQUENCY, CROSSFADE_MS}` en `utils/defaults.hpp` |
|
||||||
| HC-02 | `jail_audio.hpp:57,76,110` + `audio.cpp:208` | `{SDL_AUDIO_S16, 2, 48000}` literal en 3 sitios; `S16LE` vs `S16` inconsistente | Importante | PENDING | Constantes `DEFAULT_FORMAT/CHANNELS/FREQ` compartidas |
|
| HC-02 | `jail_audio.hpp:57,76,110` + `audio.cpp:208` | `{SDL_AUDIO_S16, 2, 48000}` literal en 3 sitios; `S16LE` vs `S16` inconsistente | Importante | DONE | `Defaults::Audio::{FORMAT,CHANNELS,FREQUENCY}` al call-site d'`Audio::initSDLAudio`; `Ja::DEFAULT_SPEC` com a fallback local perquè l'engine no depengui del projecte |
|
||||||
| HC-03 | `jail_audio.hpp:53-54` | `MAX_SIMULTANEOUS_CHANNELS=20`, `MAX_GROUPS=2` fijos sin justificación | Menor | PENDING | `Defaults::Audio::MAX_CHANNELS/MAX_GROUPS` + `static_assert` |
|
| HC-03 | `jail_audio.hpp:53-54` | `MAX_SIMULTANEOUS_CHANNELS=20`, `MAX_GROUPS=2` fijos sin justificación | Menor | PENDING | `Defaults::Audio::MAX_CHANNELS/MAX_GROUPS` + `static_assert` |
|
||||||
| HC-04 | `jail_audio.hpp:131,134` | `MUSIC_CHUNK_SHORTS=8192`, `MUSIC_LOW_WATER_SECONDS=0.5F` tuning hidden | Menor | PENDING | Mover a `Defaults::Audio` |
|
| HC-04 | `jail_audio.hpp:131,134` | `MUSIC_CHUNK_SHORTS=8192`, `MUSIC_LOW_WATER_SECONDS=0.5F` tuning hidden | Menor | PENDING | Mover a `Defaults::Audio` |
|
||||||
| HC-05 | `jail_audio.hpp:266` | `fill(sound_volume, 0.5F)` valor mágico que se sobreescribe enseguida | Menor | PENDING | Eliminar o nombrar |
|
| HC-05 | `jail_audio.hpp:266` | `fill(sound_volume, 0.5F)` valor mágico que se sobreescribe enseguida | Menor | PENDING | Eliminar o nombrar |
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ void Audio::initSDLAudio() {
|
|||||||
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||||
std::cout << "SDL_AUDIO could not initialize! SDL Error: " << SDL_GetError() << '\n';
|
std::cout << "SDL_AUDIO could not initialize! SDL Error: " << SDL_GetError() << '\n';
|
||||||
} else {
|
} else {
|
||||||
Ja::init(Defaults::Audio::FREQUENCY, SDL_AUDIO_S16LE, 2);
|
Ja::init(Defaults::Audio::FREQUENCY, Defaults::Audio::FORMAT, Defaults::Audio::CHANNELS);
|
||||||
sound_enabled_ = config_.sound_enabled;
|
sound_enabled_ = config_.sound_enabled;
|
||||||
music_enabled_ = config_.music_enabled;
|
music_enabled_ = config_.music_enabled;
|
||||||
enable(config_.enabled);
|
enable(config_.enabled);
|
||||||
|
|||||||
@@ -53,8 +53,13 @@ namespace Ja {
|
|||||||
inline constexpr int MAX_SIMULTANEOUS_CHANNELS = 20;
|
inline constexpr int MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||||
inline constexpr int MAX_GROUPS = 2;
|
inline constexpr int MAX_GROUPS = 2;
|
||||||
|
|
||||||
|
// Spec de fallback del dispositiu. S'aplica abans de Ja::init() i com a valor
|
||||||
|
// inicial de Sound/Music. L'spec real d'ús l'imposa Ja::init(), que la capa
|
||||||
|
// Audio alimenta des de Defaults::Audio — única font de veritat del projecte.
|
||||||
|
inline constexpr SDL_AudioSpec DEFAULT_SPEC{SDL_AUDIO_S16, 2, 48000};
|
||||||
|
|
||||||
struct Sound {
|
struct Sound {
|
||||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
SDL_AudioSpec spec{DEFAULT_SPEC};
|
||||||
Uint32 length{0};
|
Uint32 length{0};
|
||||||
// Buffer descomprimit (PCM) propietat del sound. Reservat per SDL_LoadWAV
|
// Buffer descomprimit (PCM) propietat del sound. Reservat per SDL_LoadWAV
|
||||||
// via SDL_malloc; el deleter `SdlFreeDeleter` allibera amb SDL_free.
|
// via SDL_malloc; el deleter `SdlFreeDeleter` allibera amb SDL_free.
|
||||||
@@ -73,7 +78,7 @@ namespace Ja {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Music {
|
struct Music {
|
||||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
SDL_AudioSpec spec{DEFAULT_SPEC};
|
||||||
|
|
||||||
// OGG comprimit en memòria. Propietat nostra; es copia des del buffer
|
// OGG comprimit en memòria. Propietat nostra; es copia des del buffer
|
||||||
// d'entrada una sola vegada en loadMusic i es descomprimix en chunks
|
// d'entrada una sola vegada en loadMusic i es descomprimix en chunks
|
||||||
@@ -107,7 +112,7 @@ namespace Ja {
|
|||||||
inline Music* current_music{nullptr};
|
inline Music* current_music{nullptr};
|
||||||
inline Channel channels[MAX_SIMULTANEOUS_CHANNELS];
|
inline Channel channels[MAX_SIMULTANEOUS_CHANNELS];
|
||||||
|
|
||||||
inline SDL_AudioSpec audio_spec{SDL_AUDIO_S16, 2, 48000};
|
inline SDL_AudioSpec audio_spec{DEFAULT_SPEC};
|
||||||
inline float music_volume{1.0F};
|
inline float music_volume{1.0F};
|
||||||
inline float sound_volume[MAX_GROUPS];
|
inline float sound_volume[MAX_GROUPS];
|
||||||
inline bool music_enabled{true};
|
inline bool music_enabled{true};
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ namespace Defaults {
|
|||||||
constexpr float VOLUME_STEP = 0.05F; // Pas estàndard per a la UI (5%).
|
constexpr float VOLUME_STEP = 0.05F; // Pas estàndard per a la UI (5%).
|
||||||
constexpr int FREQUENCY = 48000; // Freqüència de mostreig del dispositiu (Hz).
|
constexpr int FREQUENCY = 48000; // Freqüència de mostreig del dispositiu (Hz).
|
||||||
constexpr int CROSSFADE_MS = 1500; // Durada per defecte del crossfade entre pistes (ms).
|
constexpr int CROSSFADE_MS = 1500; // Durada per defecte del crossfade entre pistes (ms).
|
||||||
|
constexpr SDL_AudioFormat FORMAT = SDL_AUDIO_S16; // Format PCM 16-bit signat natiu.
|
||||||
|
constexpr int CHANNELS = 2; // Nombre de canals de sortida (estèreo).
|
||||||
} // namespace Audio
|
} // namespace Audio
|
||||||
|
|
||||||
namespace KeysGame {
|
namespace KeysGame {
|
||||||
|
|||||||
Reference in new issue
Block a user