- [FIX] El àudio ja se sincronitza correctament
This commit is contained in:
19
APU.cpp
19
APU.cpp
@@ -1,11 +1,10 @@
|
|||||||
#include "APU.h"
|
#include "APU.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
//#include "audio_viewer.h"
|
//#include "audio_viewer.h"
|
||||||
|
|
||||||
namespace APU
|
namespace APU
|
||||||
{
|
{
|
||||||
#define SAMPLING_FREQ 44100
|
#define SAMPLING_FREQ 44100
|
||||||
#define AUDIO_BUFFER_SIZE 8192
|
#define AUDIO_BUFFER_SIZE 2048
|
||||||
const float cycles_per_sample = 4194304.0f / SAMPLING_FREQ;
|
const float cycles_per_sample = 4194304.0f / SAMPLING_FREQ;
|
||||||
|
|
||||||
SDL_AudioDeviceID sdlAudioDevice;
|
SDL_AudioDeviceID sdlAudioDevice;
|
||||||
@@ -78,14 +77,6 @@ namespace APU
|
|||||||
uint16_t LFSR = 0;
|
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()
|
void silence()
|
||||||
{
|
{
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 1);
|
SDL_PauseAudioDevice(sdlAudioDevice, 1);
|
||||||
@@ -98,7 +89,7 @@ namespace APU
|
|||||||
|
|
||||||
void init()
|
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);
|
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||||
resume();
|
resume();
|
||||||
//samples_time=SDL_GetTicks();
|
//samples_time=SDL_GetTicks();
|
||||||
@@ -438,7 +429,11 @@ namespace APU
|
|||||||
|
|
||||||
sound_buffer[(sound_pos++)&(AUDIO_BUFFER_SIZE-1)] = sample;
|
sound_buffer[(sound_pos++)&(AUDIO_BUFFER_SIZE-1)] = sample;
|
||||||
//audio_viewer::addsample(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 ) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,8 +322,8 @@ namespace gbscreen
|
|||||||
if ( (STAT&0x3)==3) {
|
if ( (STAT&0x3)==3) {
|
||||||
uint16_t current_pixel = dots_in_scanline-80;
|
uint16_t current_pixel = dots_in_scanline-80;
|
||||||
if (current_pixel<160) {
|
if (current_pixel<160) {
|
||||||
uint8_t pixel = gb_pixels[current_pixel+LY*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];
|
gb_pixels[current_pixel+LY*160] = line_buffer[current_pixel];// > line_buffer[current_pixel] ? pixel-1 : line_buffer[current_pixel];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
|
|||||||
bool fastload=false;
|
bool fastload=false;
|
||||||
|
|
||||||
// En cada bucle fem 10 pasos de la CPU, sino s'ofega
|
// 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)) {
|
if (debug::isbreak(sm83::getPC(), 9)) {
|
||||||
debug::stop();
|
debug::stop();
|
||||||
gbscreen::redraw();
|
gbscreen::redraw();
|
||||||
|
|||||||
Reference in New Issue
Block a user