- [CHG] Més neteja de basura
- [FIX] Intentant arreglar un "pop" que fa el só al inici, he descobert que no fa falta més sincronització que la del àudio! - [CHG] De fet, ara en compte de fer 20 cicles de cpu cada iteració, faig un cicle per iteració i nomes refresque events cada 125ms. No detecte canvis, pero seria molt més net. A vore que tal. - [NEW] Comence la classe directora "gameboy"
This commit is contained in:
+5
-4
@@ -1,6 +1,6 @@
|
||||
#include "apu.h"
|
||||
#include <SDL2/SDL.h>
|
||||
//#include "audio_viewer.h"
|
||||
|
||||
namespace apu
|
||||
{
|
||||
#define SAMPLING_FREQ 44100
|
||||
@@ -10,9 +10,7 @@ namespace apu
|
||||
SDL_AudioDeviceID sdlAudioDevice;
|
||||
uint8_t sound_buffer[AUDIO_BUFFER_SIZE];
|
||||
uint16_t sound_pos=0;
|
||||
uint16_t sound_start=0;
|
||||
float t_sound = 0.0f;
|
||||
uint32_t samples_generated=0;
|
||||
|
||||
#define CH1 channels[0]
|
||||
#define CH2 channels[1]
|
||||
@@ -87,9 +85,11 @@ namespace apu
|
||||
|
||||
void init()
|
||||
{
|
||||
for (int i=0; i<AUDIO_BUFFER_SIZE; ++i) sound_buffer[i] = 128;
|
||||
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();
|
||||
SDL_QueueAudio(sdlAudioDevice, sound_buffer, 2000);
|
||||
}
|
||||
|
||||
void reset()
|
||||
@@ -428,7 +428,8 @@ namespace apu
|
||||
if (sound_pos>=1000) {
|
||||
SDL_QueueAudio(sdlAudioDevice, sound_buffer, sound_pos);
|
||||
sound_pos = 0;
|
||||
while (SDL_GetQueuedAudioSize(sdlAudioDevice) > 4096 ) {}
|
||||
while (SDL_GetQueuedAudioSize(sdlAudioDevice) > 4096 ) { SDL_Delay(1); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user