- Treballant en que funcione al temps correcte

- Treballant en el só
This commit is contained in:
2024-12-01 21:50:20 +01:00
parent 7eb5df248f
commit 7cb6ae527b
2 changed files with 51 additions and 6 deletions

View File

@@ -57,6 +57,8 @@ namespace zx_ula
static uint8_t ear = 0;
static uint8_t mic = 0;
static uint16_t last_1 = 0;
void update_zx_keyboard()
{
const uint8_t *keys = SDL_GetKeyboardState(NULL);
@@ -220,15 +222,33 @@ namespace zx_ula
void audioCallback(void * userdata, uint8_t * stream, int len)
{
const uint16_t top = sound_pos < len ? sound_pos : len;
printf("top: %i, len: %i, pos: %i\n", top, len, sound_pos);
memcpy(stream, sound_buffer, top);
if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
sound_pos=0;
if (top<sound_pos)
{
if (last_1>top)
{
memcpy(sound_buffer, &sound_buffer[top], sound_pos-top);
sound_pos=sound_pos-top;
last_1=last_1-top;
}
else
{
sound_pos=last_1=0;
}
}
else
{
sound_pos=last_1=0;
}
}
void sound_init()
{
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
sound_enable();
}
void sound_enable()
@@ -244,9 +264,20 @@ namespace zx_ula
void sound_update(const uint8_t dt)
{
t_sound += dt;
if (t_sound>=317) {
t_sound-=317;
sound_buffer[sound_pos++] = ear*128;
if (t_sound>=318) {
t_sound-=318;
//sound_pos = (sound_pos+1) & 0x3ff;
//sound_buffer[sound_pos] = ear*128;
if (sound_pos<1024)
{
sound_buffer[sound_pos++] = ear*128;
if (ear) last_1 = sound_pos;
}
/*else
{
printf("WARNING! Sound buffer overflow!\n");
}*/
}
}
}