- [FIX] El àudio ja se sincronitza correctament

This commit is contained in:
2025-01-30 16:09:13 +01:00
parent dffbb9c741
commit 454cce304f
3 changed files with 10 additions and 15 deletions

19
APU.cpp
View File

@@ -1,11 +1,10 @@
#include "APU.h"
#include <SDL2/SDL.h>
//#include "audio_viewer.h"
namespace APU
{
#define SAMPLING_FREQ 44100
#define AUDIO_BUFFER_SIZE 8192
#define AUDIO_BUFFER_SIZE 2048
const float cycles_per_sample = 4194304.0f / SAMPLING_FREQ;
SDL_AudioDeviceID sdlAudioDevice;
@@ -78,14 +77,6 @@ namespace APU
uint16_t LFSR = 0;
void audioCallback(void * userdata, uint8_t * stream, int len)
{
for (int i=0;i<len;++i)
{
stream[i] = sound_buffer[(sound_start++)&(AUDIO_BUFFER_SIZE-1)];
}
}
void silence()
{
SDL_PauseAudioDevice(sdlAudioDevice, 1);
@@ -98,7 +89,7 @@ namespace APU
void init()
{
SDL_AudioSpec audioSpec{SAMPLING_FREQ, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE>>1, 0, 0, &audioCallback, NULL};
SDL_AudioSpec audioSpec{SAMPLING_FREQ, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE, 0, 0, NULL, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
resume();
//samples_time=SDL_GetTicks();
@@ -438,7 +429,11 @@ namespace APU
sound_buffer[(sound_pos++)&(AUDIO_BUFFER_SIZE-1)] = sample;
//audio_viewer::addsample(sample);
//if (ear) last_1 = sound_pos;
}
if (sound_pos>=1000) {
SDL_QueueAudio(sdlAudioDevice, sound_buffer, sound_pos);
sound_pos = 0;
while (SDL_GetQueuedAudioSize(sdlAudioDevice) > 4096 ) {}
}
}
}

View File

@@ -322,8 +322,8 @@ namespace gbscreen
if ( (STAT&0x3)==3) {
uint16_t current_pixel = dots_in_scanline-80;
if (current_pixel<160) {
uint8_t pixel = gb_pixels[current_pixel+LY*160];
gb_pixels[current_pixel+LY*160] = pixel > line_buffer[current_pixel] ? pixel-1 : line_buffer[current_pixel];
//uint8_t pixel = gb_pixels[current_pixel+LY*160];
gb_pixels[current_pixel+LY*160] = line_buffer[current_pixel];// > line_buffer[current_pixel] ? pixel-1 : line_buffer[current_pixel];
}
}

View File

@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
bool fastload=false;
// En cada bucle fem 10 pasos de la CPU, sino s'ofega
for (int i=0;i<5;++i) {
for (int i=0;i<20;++i) {
if (debug::isbreak(sm83::getPC(), 9)) {
debug::stop();
gbscreen::redraw();