From 2dd6b4479f66031c9579a3a8cc3dea8750921227 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Tue, 8 Apr 2025 21:03:29 +0200 Subject: [PATCH] Mostly working audio but gets out of sync and dies --- src/Backends/Audio/SoftwareMixer/Solaris.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Backends/Audio/SoftwareMixer/Solaris.cpp b/src/Backends/Audio/SoftwareMixer/Solaris.cpp index 689a9972..1b3f84cb 100644 --- a/src/Backends/Audio/SoftwareMixer/Solaris.cpp +++ b/src/Backends/Audio/SoftwareMixer/Solaris.cpp @@ -17,6 +17,7 @@ #include #include +static const int samplesPerGo = 0x400; static const int parkSignal = SIGUSR1; static pthread_t mainThread; static int sndfp; @@ -32,7 +33,7 @@ static void* soundcheckthread(void*) { //sndfp = open("/dev/audio", 0, O_WRONLY); audioDone = true; unsigned long for_as_long_as_it_seems_we_should = 0; - uint16_t out[0x400 * 2]; + uint16_t out[samplesPerGo * 2]; bool firstTime = true; int oldeof; while(1) { @@ -51,8 +52,8 @@ static void* soundcheckthread(void*) { } } */ - long mix[0x400 * 2]; - memset(mix, 0, 0x400 * 2 * sizeof(long)); + long mix[samplesPerGo * 2]; + memset(mix, 0, samplesPerGo * 2 * sizeof(long)); //printf("Cleared mix buffer\n"); // park the main thread since the game probably expects it to not be // doing anything else while we're requesting audio frames. @@ -60,13 +61,13 @@ static void* soundcheckthread(void*) { //pthread_kill(mainThread, parkSignal); //printf("Unparked thread\n"); - parent_callback(mix, 0x400); + parent_callback(mix, samplesPerGo); // unpark the main thread now that we're not using game state anymore audioDone = true; //printf("Audio done\n"); - for(int i = 0; i < 0x400 * 2; i++) { + for(int i = 0; i < samplesPerGo * 2; i++) { //if(i % 2 == 0) { short sample = mix[i]; if(mix[i] > 0x7FFF) { @@ -79,13 +80,13 @@ static void* soundcheckthread(void*) { fputc(sample & 0xFF, sndfile); //} } - //write(sndfp, mix, 0x400 * 2); + //write(sndfp, mix, samplesPerGo * 2); //write(sndfp, NULL, 0); //ioctl(sndfp, AUDIO_GETINFO, &audioInfo); //oldeof = audioInfo.play.eof; - for_as_long_as_it_seems_we_should = ((float)0x400 / (float)8000) * 1000000; + for_as_long_as_it_seems_we_should = ((float)(samplesPerGo - 0x7F) / (float)8000) * 1000000; firstTime = false; } } @@ -110,10 +111,10 @@ unsigned long SoftwareMixerBackend_Init(void (*callback)(long *stream, size_t fr info.sample_rate = 8000; info.channels = 2; - info.precision = 16; + info.precision = 8; info.encoding = AUDIO_ENCODING_LINEAR; info.port = AUDIO_SPEAKER | AUDIO_HEADPHONE; - info.gain = 32; + info.gain = 128; audioInfo.play = info; ioctl(sndfp, AUDIO_SETINFO, &audioInfo);