- [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 <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 ) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user