some clean up and violent thrashing

This commit is contained in:
John Lorentzson 2025-04-08 22:00:54 +02:00
parent 2dd6b4479f
commit 3b0418a25f

View file

@ -17,7 +17,7 @@
#include <sys/audioio.h>
#include <pthread.h>
static const int samplesPerGo = 0x400;
static const int samplesPerGo = 0x200;
static const int parkSignal = SIGUSR1;
static pthread_t mainThread;
static int sndfp;
@ -30,42 +30,28 @@ static void soundSetup() {
static void* soundcheckthread(void*) {
printf("Entered sound thread.\n");
//sndfp = open("/dev/audio", 0, O_WRONLY);
audioDone = true;
unsigned long for_as_long_as_it_seems_we_should = 0;
uint16_t out[samplesPerGo * 2];
bool firstTime = true;
int oldeof;
int counter = 0;
while(1) {
//printf("Starting audio thread loop\n");
bool ready = false;
audio_info_t audioInfo;
//printf("eepy\n");
usleep(for_as_long_as_it_seems_we_should);
//printf("i live again\n");
/*
while(ready == false && firstTime == false) {
ioctl(sndfp, AUDIO_GETINFO, &audioInfo);
if(audioInfo.play.eof > oldeof) {
ready = true;
}
}
*/
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.
audioDone = false;
//pthread_kill(mainThread, parkSignal);
//printf("Unparked thread\n");
parent_callback(mix, samplesPerGo);
// unpark the main thread now that we're not using game state anymore
audioDone = true;
//printf("Audio done\n");
for_as_long_as_it_seems_we_should = ((float)(samplesPerGo) / (float)8000) * 1000000;
audio_info_t audioInfo;
ioctl(sndfp, AUDIO_GETINFO, &audioInfo);
//printf("%d\n", audioInfo.play.error);
if(counter > 4 && audioInfo.play.error == 0) {
usleep(for_as_long_as_it_seems_we_should);
} else {
printf("ae\n");
audioInfo.play.error = 0;
ioctl(sndfp, AUDIO_SETINFO, &audioInfo);
}
for(int i = 0; i < samplesPerGo * 2; i++) {
//if(i % 2 == 0) {
@ -80,13 +66,8 @@ static void* soundcheckthread(void*) {
fputc(sample & 0xFF, sndfile);
//}
}
//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)(samplesPerGo - 0x7F) / (float)8000) * 1000000;
counter += 1;
firstTime = false;
}
}