ja funciona el audio

This commit is contained in:
2025-03-27 18:34:04 +01:00
parent e2339bd54a
commit c6288918b2
10 changed files with 221 additions and 184 deletions

View File

@@ -98,11 +98,9 @@ void Director::init()
loadScoreFile(); // Carga el fichero de puntuaciones
// Inicializa y crea el resto de objetos
initSDL();
SDL_HideCursor();
initJailAudio();
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
Screen::init(window_, renderer_);
Screen::init();
initJailAudio();
Resource::init();
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
bindInputs();
@@ -124,9 +122,6 @@ void Director::close()
JA_Quit();
SDL_DestroyRenderer(renderer_);
SDL_DestroyWindow(window_);
SDL_Quit();
#ifdef ARCADE
@@ -267,109 +262,27 @@ void Director::bindInputs()
// Inicializa JailAudio
void Director::initJailAudio()
{
JA_Init(48000, SDL_AUDIO_S16LE, 2);
if (options.audio.enabled)
{
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
}
else
{
JA_SetMusicVolume(0);
JA_SetSoundVolume(0);
}
}
// Arranca SDL y crea la ventana
bool Director::initSDL()
{
// Indicador de éxito
auto success = true;
// Inicializa SDL
if (!SDL_Init(SDL_INIT_VIDEO || SDL_INIT_AUDIO || SDL_INIT_GAMEPAD))
if (!SDL_Init(SDL_INIT_AUDIO))
{
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
success = false;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
}
else
{
// Obtiene información sobre la pantalla
int i, num_displays = 0;
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
if (displays)
JA_Init(48000, SDL_AUDIO_S16LE, 2);
if (options.audio.enabled)
{
for (i = 0; i < num_displays; ++i)
{
SDL_DisplayID instance_id = displays[i];
const char *name = SDL_GetDisplayName(instance_id);
SDL_Log("Display %" SDL_PRIu32 ": %s", instance_id, name ? name : "Unknown");
}
auto DM = SDL_GetCurrentDisplayMode(displays[0]);
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
options.video.window.max_zoom = std::min(DM->w / param.game.width, DM->h / param.game.height);
options.video.window.zoom = std::min(options.video.window.zoom, options.video.window.max_zoom);
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
std::cout << "\nCurrent display mode: " << DM->w << "x" << DM->h << " @ " << DM->refresh_rate << "Hz" << std::endl;
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.zoom << std::endl;
options.video.info = std::to_string(DM->w) + " X " + std::to_string(DM->h) + " AT " + std::to_string(DM->refresh_rate) + " HZ";
SDL_free(displays);
}
// Establece el filtro de la textura
/*if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
{
std::cout << "Warning: texture filtering not enabled!\n";
}*/
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
{
std::cout << "Warning: opengl not enabled!\n";
}
// Crea la ventana
window_ = SDL_CreateWindow(WINDOW_CAPTION, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_OPENGL);
if (!window_)
{
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
success = false;
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume));
}
else
{
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
// Uint32 flags = 0;
if (options.video.v_sync)
{
// flags = SDL_RENDERER_PRESENTVSYNC;
}
// La aceleración se activa según el define
// flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
renderer_ = SDL_CreateRenderer(window_, nullptr);
if (!renderer_)
{
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
success = false;
}
else
{
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.fullscreen));
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
}
JA_SetMusicVolume(0);
JA_SetSoundVolume(0);
}
}
std::cout << std::endl;
return success;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO: Initialization complete.");
}
}
// Crea el indice de ficheros