Rewrite some code for ease of reading

This commit is contained in:
hugova 2025-04-24 15:34:44 +02:00
parent b1d3549723
commit 5448068426

View file

@ -34,25 +34,22 @@ static inline void soundWait() {
audio_info_t audioInfo; audio_info_t audioInfo;
ioctl(sndfp, AUDIO_GETINFO, &audioInfo); ioctl(sndfp, AUDIO_GETINFO, &audioInfo);
int playedBefore = audioInfo.play.samples; int playedBefore = audioInfo.play.samples;
int playedNow = audioInfo.play.samples; while(audioInfo.play.samples - playedBefore < samplesPerGo) {
while(playedNow - playedBefore < samplesPerGo) {
Backend_Delay(10); Backend_Delay(10);
ioctl(sndfp, AUDIO_GETINFO, &audioInfo); ioctl(sndfp, AUDIO_GETINFO, &audioInfo);
playedNow = audioInfo.play.samples;
} }
} }
static inline void feedOutSound(long* mix) { static inline void feedOutSound(long* mix) {
for(int i = 0; i < samplesPerGo * 2; i++) { for(int i = 0; i < samplesPerGo * 2; i++) {
short sample = mix[i];
if(mix[i] > 0x7FFF) { if(mix[i] > 0x7FFF) {
sample = 0x7FFF; mix[i] = 0x7FFF;
} }
if(mix[i] < -0x7FFF) { else if(mix[i] < -0x7FFF) {
sample = -0x7FFF; mix[i] = -0x7FFF;
} }
fputc((sample >> 8) & 0xFF, sndfile); fputc((mix[i] >> 8) & 0xFF, sndfile);
fputc(sample & 0xFF, sndfile); fputc(mix[i] & 0xFF, sndfile);
} }
} }
@ -64,7 +61,7 @@ static void* soundcheckthread(void*) {
setUpSoundFrame(mix); setUpSoundFrame(mix);
feedOutSound(mix); feedOutSound(mix);
while(1) { while(1) {
setUpSoundFrame(mix); setUpSoundFrame(mix);
// Waiting for more to be needed // Waiting for more to be needed