Fix sound issues for good with triple/double buffering.

The source code needed some changes before this happened
This commit is contained in:
gameblabla 2020-10-13 15:17:29 +02:00
parent 91442a39c5
commit 600d1ed6a5
No known key found for this signature in database
GPG Key ID: B24EFBB23B5F76CB
7 changed files with 35 additions and 23 deletions

View File

@ -4,7 +4,7 @@ CC = gcc
# Possible choices : rs97, k3s (PAP K3S), sdl, amini, fbdev
PORT = sdl
# Possible choices : alsa, pulse (pulseaudio), oss, sdl12 (SDL 1.2 sound output), portaudio, libao
SOUND_OUTPUT = alsa
SOUND_OUTPUT = pulse
# Possible choices : crabemu_sn76489 (less accurate, GPLv2), maxim_sn76489 (somewhat problematic license but good accuracy)
SOUND_ENGINE = maxim_sn76489
# Possible choices : z80 (accurate but proprietary), eighty (EightyZ80's core, GPLv2)
@ -22,8 +22,8 @@ OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
OBJ_CP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CP)))
OBJS = $(OBJ_C) $(OBJ_CP)
CFLAGS = -O0 -g -Wextra -Wall
CFLAGS += -DLSB_FIRST -std=gnu99 -DALIGN_DWORD
CFLAGS = -O0 -g3 -Wall -Wextra
CFLAGS += -DLSB_FIRST -std=gnu99 -DALIGN_DWORD -DNOYUV
CFLAGS += -Isource -Isource/cpu_cores/$(Z80_CORE) -Isource/scalers -Isource/ports/$(PORT) -I./source/sound -Isource/unzip -Isource/sdl -Isource/sound/$(SOUND_ENGINE) -Isource/sound_output
SRCDIR += ./source/text/fb

View File

@ -4,7 +4,7 @@ CC = /opt/rs90-toolchain/bin/mipsel-linux-gcc
# Possible choices : rs97, k3s (PAP K3S), sdl, amini, fbdev
PORT = rs90
# Possible choices : alsa, pulse (pulseaudio), oss, sdl12 (SDL 1.2 sound output), portaudio, libao
SOUND_OUTPUT = alsa
SOUND_OUTPUT = sdl12
# Possible choices : crabemu_sn76489 (less accurate, GPLv2), maxim_sn76489 (somewhat problematic license but good accuracy)
SOUND_ENGINE = maxim_sn76489
# Possible choices : z80 (accurate but proprietary), eighty (EightyZ80's core, GPLv2)
@ -13,7 +13,7 @@ PROFILE = 0
ZIP_SUPPORT = 1
SRCDIR = ./source ./source/cpu_cores/$(Z80_CORE) ./source/sound ./source/unzip
SRCDIR += ./source/scalers ./source/ports/$(PORT) ./source/sound/$(SOUND_ENGINE) ./source/sound_output/$(SOUND_OUTPUT)
SRCDIR += ./source/ports/$(PORT) ./source/sound/$(SOUND_ENGINE) ./source/sound_output/$(SOUND_OUTPUT)
VPATH = $(SRCDIR)
SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
SRC_CP = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.cpp))
@ -21,9 +21,10 @@ OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
OBJ_CP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CP)))
OBJS = $(OBJ_C) $(OBJ_CP)
CFLAGS = -Ofast -fdata-sections -ffunction-sections -mplt -mframe-header-opt -fno-common -march=mips32 -mtune=mips32 -flto
CFLAGS += -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 -fsingle-precision-constant
CFLAGS += -DALIGN_DWORD -D_8BPP_COLOR -DNOBLANKING_LEFTCOLUM
CFLAGS = -Ofast -fdata-sections -ffunction-sections -mplt -mno-shared -mframe-header-opt -fno-common -march=mips32 -mtune=mips32 -flto=auto
CFLAGS += -falign-functions=4 -falign-jumps=4 -falign-loops=4 -falign-labels=4 -fsingle-precision-constant
CFLAGS += -mno-fp-exceptions -mno-check-zero-division -fno-common -fno-short-enums -ffinite-math-only -funsafe-math-optimizations -fsection-anchors -fgcse-las -fgcse-sm
CFLAGS += -DALIGN_DWORD -D_8BPP_COLOR -DNOBLANKING_LEFTCOLUM -DNONBLOCKING_AUDIO
CFLAGS += -DLSB_FIRST
CFLAGS += -Isource -Isource/cpu_cores/$(Z80_CORE) -Isource/scalers -Isource/ports/$(PORT) -I./source/sound -Isource/unzip -Isource/sdl -Isource/sound/$(SOUND_ENGINE) -Isource/sound_output
@ -54,7 +55,7 @@ CFLAGS += -Isource/scale2x
SRCDIR += ./source/scale2x
endif
LDFLAGS += -lc -lgcc -lSDL -Wl,--as-needed -Wl,--gc-sections -flto -s
LDFLAGS += -lc -lgcc -lSDL -Wl,--as-needed -Wl,--gc-sections -flto=auto -s
ifeq ($(SOUND_OUTPUT), portaudio)
LDFLAGS += -lportaudio
@ -71,7 +72,7 @@ endif
# Rules to make executable
$(PRGNAME): $(OBJS)
$(CC) -o $(PRGNAME) $^ $(LDFLAGS)
$(CC) $(CFLAGS) -o $(PRGNAME) $^ $(LDFLAGS)
$(OBJ_C) : %.o : %.c
$(CC) $(CFLAGS) -std=gnu99 -c -o $@ $<

View File

@ -38,10 +38,9 @@ static const uint32_t upscalers_available = 1
+1
#endif
;
uint16_t real_FPS;
double real_FPS;
Uint32 start;
static void video_update(void)
{
uint32_t dst_x, dst_y, dst_w, dst_h, hide_left;
@ -107,7 +106,9 @@ static void video_update(void)
}
SDL_Flip(sdl_screen);
if(real_FPS > SDL_GetTicks()-start) SDL_Delay(real_FPS-(SDL_GetTicks()-start));
#ifdef NONBLOCKING_AUDIO
if(real_FPS > SDL_GetTicks()-start) usleep((real_FPS-(SDL_GetTicks()-start))*1000);
#endif
}
void smsp_state(uint8_t slot_number, uint8_t mode)
@ -684,7 +685,7 @@ int main (int argc, char *argv[])
SDL_Init(SDL_INIT_VIDEO);
sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (!sdl_screen)
{
fprintf(stdout, "Could not create display, exiting\n");
@ -717,8 +718,8 @@ int main (int argc, char *argv[])
sms.use_fm = 1;
}
if (sms.display == DISPLAY_PAL) real_FPS = 1000 / 50;
else real_FPS = 1000 / 60;
if (sms.display == DISPLAY_PAL) real_FPS = 1000 / 49.701459;
else real_FPS = 1000 / 59.922743;
printf("sms.display %d, PAL is %d\n", sms.display, DISPLAY_PAL);
@ -732,8 +733,9 @@ int main (int argc, char *argv[])
// Loop until the user closes the window
while (!quit)
{
#ifdef NONBLOCKING_AUDIO
start = SDL_GetTicks();
#endif
if (selectpressed == 1)
{
Menu();

View File

@ -21,6 +21,7 @@ void Sound_Init()
uint32_t channels = 2;
uint32_t format = AFMT_S16_LE;
int32_t err_ret;
int32_t tmp;
tmp = option.sndrate;
@ -60,7 +61,7 @@ void Sound_Init()
void Sound_Update(int16_t* sound_buffer, unsigned long len)
{
if (!oss_audio_fd) return;
write(oss_audio_fd, sound_buffer, len);
write(oss_audio_fd, sound_buffer, len * 4);
}
void Sound_Close()

View File

@ -22,7 +22,8 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
void *userData )
{
/* Cast data passed through stream to our structure. */
uint16_t *out = (uint16_t*)snd.output;
snd.output = (int16_t*)outputBuffer;
int32_t i;
(void) inputBuffer; /* Prevent unused variable warning. */
return 0;

View File

@ -19,12 +19,19 @@ static pa_simple *pulse_stream;
void Sound_Init()
{
pa_sample_spec ss;
pa_buffer_attr paattr;
ss.format = PA_SAMPLE_S16LE;
ss.channels = 2;
ss.rate = option.sndrate;
paattr.tlength = snd.buffer_size * 4;
paattr.prebuf = -1;
paattr.maxlength = -1;
paattr.minreq = snd.buffer_size;
/* Create a new playback stream */
pulse_stream = pa_simple_new(NULL, "smsplusgx", PA_STREAM_PLAYBACK, NULL, "smsplusgx", &ss, NULL, NULL, NULL);
pulse_stream = pa_simple_new(NULL, "SMS Plus GX", PA_STREAM_PLAYBACK, NULL, "SMS Plus GX", &ss, NULL, &paattr, NULL);
if (!pulse_stream)
{
fprintf(stderr, "PulseAudio: pa_simple_new() failed!\n");
@ -34,7 +41,7 @@ void Sound_Init()
void Sound_Update(int16_t* sound_buffer, unsigned long len)
{
if (pa_simple_write(pulse_stream, sound_buffer, len, NULL) < 0)
if (pa_simple_write(pulse_stream, sound_buffer, len * 4, NULL) < 0)
{
fprintf(stderr, "PulseAudio: pa_simple_write() failed!\n");
}

View File

@ -136,7 +136,7 @@ void Sound_Init()
void Sound_Update(int16_t* sound_buffer, unsigned long len)
{
SDL_LockAudio();
sdl_write_buffer(sound_buffer, len);
sdl_write_buffer(sound_buffer, len * 4);
SDL_UnlockAudio();
}