- [FIX] Ajustat el buffer de audio

This commit is contained in:
2026-05-16 08:19:51 +02:00
parent d4e91ac56d
commit 672f4278e0
2 changed files with 42 additions and 44 deletions
+11 -13
View File
@@ -152,24 +152,19 @@ void reinit() {
void pump_audio() { void pump_audio() {
if (audio_state == AUDIO_NONE) return; if (audio_state == AUDIO_NONE) return;
const int TARGET_MS = 20; // latencia deseada const int TARGET_MS = 20;
const int BYTES_PER_MS = 44; // 44100 Hz, 8-bit mono const int BYTES_PER_MS = 22; // 44100 Hz, 8-bit mono
const int TARGET_BYTES = TARGET_MS * BYTES_PER_MS; const int TARGET_BYTES = TARGET_MS * BYTES_PER_MS;
const int CHUNK = 256; // bloque pequeño y constante
int queued = SDL_GetAudioStreamAvailable(audio_stream); int queued = SDL_GetAudioStreamAvailable(audio_stream);
// Si ya hay suficiente audio en cola, no generamos nada while (queued < TARGET_BYTES) {
if (queued >= TARGET_BYTES)
return;
// Cuánto falta para llegar al objetivo int to_generate = CHUNK;
int missing = TARGET_BYTES - queued;
if (missing > sizeof(mix_buffer))
missing = sizeof(mix_buffer);
// Generar exactamente "missing" bytes
uint8_t* out = mix_buffer; uint8_t* out = mix_buffer;
int remaining = missing; int remaining = to_generate;
while (remaining > 0) { while (remaining > 0) {
@@ -210,7 +205,10 @@ void pump_audio() {
} }
} }
SDL_PutAudioStreamData(audio_stream, mix_buffer, missing); SDL_PutAudioStreamData(audio_stream, mix_buffer, to_generate);
queued += to_generate;
}
} }
void romcpy() { void romcpy() {
+1 -1
View File
@@ -420,7 +420,7 @@ bool lua_is_playing() {
return lua_state == STATE_PLAYING; return lua_state == STATE_PLAYING;
} }
const char boot[] = "function init()mode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.7.0',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end"; const char boot[] = "function init()mode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.7.1',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
void lua_init(const char* filename, const bool start_playing) { void lua_init(const char* filename, const bool start_playing) {
if (lua_state != STATE_STOPPED) lua_quit(); if (lua_state != STATE_STOPPED) lua_quit();