From c07e09cebda0924b89a8cf5c3ee6c938507867c6 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 27 Nov 2024 13:33:52 +0100 Subject: [PATCH] - [FIX] Aplicat un fix de JailAudio --- jail_audio.cpp | 19 ++++++++++++++++--- mini.cpp | 30 +++++++++++++++++------------- version.h | 2 +- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/jail_audio.cpp b/jail_audio.cpp index d561221..55ab056 100644 --- a/jail_audio.cpp +++ b/jail_audio.cpp @@ -41,7 +41,7 @@ SDL_AudioDeviceID sdlAudioDevice = 0; void audioCallback(void * userdata, uint8_t * stream, int len) { SDL_memset(stream, 0, len); if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) { - const int size = SDL_min(len, current_music->samples*2-current_music->pos); + const int size = SDL_min(len, (current_music->samples-current_music->pos)*2); SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_musicVolume); current_music->pos += size/2; if (size < len) { @@ -74,14 +74,26 @@ void audioCallback(void * userdata, uint8_t * stream, int len) { } } -void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) { +void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) +{ + #ifdef DEBUG + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); + #endif + + SDL_Log("Iniciant JailAudio..."); JA_freq = freq; JA_format = format; JA_channels = channels; SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL}; if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice); sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0); - if (sdlAudioDevice==0) printf("Failed to initialize SDL audio!\n"); + if (sdlAudioDevice==0) + { + SDL_Log("FAILED!\n"); + SDL_Log("Failed to initialize SDL audio!\n"); + } else { + SDL_Log("OK!\n"); + } SDL_PauseAudioDevice(sdlAudioDevice, 0); } @@ -102,6 +114,7 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length) SDL_AudioCVT cvt; SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq); + SDL_Log("Music length: %f\n", float(music->samples)/float(JA_freq)); if (cvt.needed) { cvt.len = music->samples * chan * 2; cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult); diff --git a/mini.cpp b/mini.cpp index b0738e2..89b6042 100644 --- a/mini.cpp +++ b/mini.cpp @@ -113,21 +113,21 @@ char* get_value_from_line(char* line) { void read_ini() { int size; - printf("Carregant 'game.ini'..."); + SDL_Log("Carregant 'game.ini'..."); FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r"); char line[1024]; - if (f == NULL) { printf("FAIL!\n"); return; } - printf("OK!\n"); + if (f == NULL) { SDL_Log("FAIL!\n"); return; } + SDL_Log("OK!\n"); while (fgets(line, sizeof(line), f)) { char *value = get_value_from_line(line); if (value != NULL) { value[strlen(value)-1] = '\0'; - if (strcmp(line, "title") == 0) { strcpy(window_title, value); printf("-title=%s\n", window_title); } - else if (strcmp(line, "config") == 0) { strcpy(config_folder, value); printf("-config=%s\n", config_folder); } - else if (strcmp(line, "width") == 0) { screen_width = atoi(value); printf("-screen width=%i\n", screen_width); } - else if (strcmp(line, "height") == 0) { screen_height = atoi(value); printf("-screen height=%i\n", screen_height); } - else if (strcmp(line, "zoom") == 0) { screen_zoom = atoi(value); printf("-screen zoom=%i\n", screen_zoom); } - else if (strcmp(line, "fullscreen") == 0) { screen_fullscreen = atoi(value); printf("-screen sullscreen=%i\n", screen_fullscreen); } + if (strcmp(line, "title") == 0) { strcpy(window_title, value); SDL_Log("-title=%s\n", window_title); } + else if (strcmp(line, "config") == 0) { strcpy(config_folder, value); SDL_Log("-config=%s\n", config_folder); } + else if (strcmp(line, "width") == 0) { screen_width = atoi(value); SDL_Log("-screen width=%i\n", screen_width); } + else if (strcmp(line, "height") == 0) { screen_height = atoi(value); SDL_Log("-screen height=%i\n", screen_height); } + else if (strcmp(line, "zoom") == 0) { screen_zoom = atoi(value); SDL_Log("-screen zoom=%i\n", screen_zoom); } + else if (strcmp(line, "fullscreen") == 0) { screen_fullscreen = atoi(value); SDL_Log("-screen sullscreen=%i\n", screen_fullscreen); } //else if (strcmp(line, "files") == 0) { //lua_files = (char*)malloc(strlen(value)); // strcpy(lua_files, value); @@ -135,7 +135,7 @@ void read_ini() { } } fclose(f); - printf("FET\n"); + SDL_Log("'game.ini' carregat!\n"); } void pset_fast(int x, int y) { @@ -153,7 +153,7 @@ void pset_pattern(int x, int y) { } void reinit() { - printf("REINIT\n"); + SDL_Log("REINIT\n"); do_pset = pset_fast; ds::pen_color = 6; ds::back_color = 0; @@ -173,8 +173,8 @@ void reinit() { } void initaudio() { - printf("Iniciant JailAudio..."); - JA_Init(44100, AUDIO_S16, 1); + SDL_Log("Iniciant JailAudio..."); + JA_Init(48000, AUDIO_S16, 1); for (int i=0;i1) { file_setresourcefolder("./"); diff --git a/version.h b/version.h index 9b0cb30..d3f5343 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "0.9.97d" +#define MINI_VERSION "0.9.97e"