- [FIX] Arreglat el audio del 48K amb lo aprés del emu de gameboy
This commit is contained in:
69
zx_ula.cpp
69
zx_ula.cpp
@@ -2,8 +2,6 @@
|
||||
#include "z80.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define AUDIO_BUFFER_SIZE 2048
|
||||
|
||||
namespace zx_ula
|
||||
{
|
||||
#define KEY_SHIFT 0
|
||||
@@ -234,52 +232,21 @@ namespace zx_ula
|
||||
void set_ear(const uint8_t val) { ear = val; }
|
||||
|
||||
|
||||
#define SAMPLING_FREQ 44100
|
||||
#define AUDIO_BUFFER_SIZE 2048
|
||||
|
||||
|
||||
float cycles_per_sample;
|
||||
SDL_AudioDeviceID sdlAudioDevice;
|
||||
uint8_t sound_buffer[AUDIO_BUFFER_SIZE];
|
||||
uint16_t sound_pos=0;
|
||||
uint16_t sound_start=0;
|
||||
uint16_t t_sound=0;
|
||||
uint32_t samples_generated=0;
|
||||
uint32_t samples_time =0;
|
||||
uint32_t samples_t=0;
|
||||
|
||||
void audioCallback(void * userdata, uint8_t * stream, int len)
|
||||
{
|
||||
//const uint16_t top = sound_pos < len ? sound_pos : len;
|
||||
//if (top<len) printf("top: %i, len: %i, pos: %i\n", top, len, sound_pos);
|
||||
//memcpy(stream, sound_buffer, top);
|
||||
for (int i=0;i<len;++i)
|
||||
{
|
||||
stream[i] = sound_buffer[(sound_start++)&(AUDIO_BUFFER_SIZE-1)];
|
||||
}
|
||||
//if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
|
||||
/*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, AUDIO_BUFFER_SIZE>>2, 0, 0, &audioCallback, NULL};
|
||||
SDL_AudioSpec audioSpec{SAMPLING_FREQ, AUDIO_U8, 1, 0, AUDIO_BUFFER_SIZE>>2, 0, 0, NULL, NULL};
|
||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||
cycles_per_sample = z80::getClock() / SAMPLING_FREQ;
|
||||
sound_enable();
|
||||
samples_time=SDL_GetTicks();
|
||||
}
|
||||
|
||||
void sound_enable()
|
||||
@@ -295,27 +262,15 @@ namespace zx_ula
|
||||
void sound_update(const uint8_t dt)
|
||||
{
|
||||
t_sound += dt;
|
||||
samples_t += dt;
|
||||
if (t_sound>=317) {
|
||||
t_sound-=317;
|
||||
samples_generated++;
|
||||
/*if (samples_t >=z80::getClock()) {
|
||||
//printf("%i\n", samples_generated);
|
||||
samples_generated=0;
|
||||
samples_t = 0;
|
||||
}*/
|
||||
/*if (SDL_GetTicks()>=samples_time+1000) {
|
||||
printf("%i\n", samples_generated);
|
||||
samples_generated=0;
|
||||
samples_time = SDL_GetTicks();
|
||||
}*/
|
||||
//sound_pos = (sound_pos+1) & 0x3ff;
|
||||
//sound_buffer[sound_pos] = ear*128;
|
||||
|
||||
//if (sound_pos>=AUDIO_BUFFER_SIZE) sound_pos = last_1 = 0;
|
||||
if (t_sound>=cycles_per_sample) {
|
||||
t_sound-=cycles_per_sample;
|
||||
|
||||
sound_buffer[(sound_pos++)&(AUDIO_BUFFER_SIZE-1)] = ear*128;
|
||||
//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