Add sound

This commit is contained in:
Miloslav Ciz 2025-01-29 16:27:47 +01:00
parent be11c582b1
commit 67e0814afb
8 changed files with 124 additions and 94 deletions

31
audio.h
View file

@ -1,4 +1,8 @@
/*
#ifndef _LCR_AUDIO
#define _LCR_AUDIO
/** @file audio.h
Licar audio
This file implements the audio system. The module only computes audio samples
@ -7,9 +11,6 @@
file, left to be optionally loaded and played by the frontend).
*/
#ifndef _LCR_AUDIO
#define _LCR_AUDIO
#define LCR_SOUND_NONE 0
#define LCR_SOUND_CLICK 1
#define LCR_SOUND_CRASH_SMALL 2
@ -58,7 +59,7 @@ void LCR_audioSetEngineIntensity(uint8_t value)
}
/**
Tells the audio system to play certain sound (see the sound constants).
Tells the audio system to play a certain sound (see the sound constants).
*/
void LCR_audioPlaySound(uint8_t sound)
{
@ -67,6 +68,16 @@ void LCR_audioPlaySound(uint8_t sound)
LCR_audio.soundPlayedFrame = 0;
}
/**
Same as LCR_audioPlaySound, but only plays the sound if no other sound is
playing.
*/
void LCR_audioPlaySoundIfFree(uint8_t sound)
{
if (LCR_audio.soundPlayed == LCR_SOUND_NONE)
LCR_audioPlaySound(sound);
}
uint8_t _LCR_audioNoise(void)
{
LCR_audio.noise = LCR_audio.noise * 32310901 + 37;
@ -106,6 +117,16 @@ uint8_t LCR_audioGetNextSample(void)
break;
}
case LCR_SOUND_ACCELERATOR:
result = putchar(((LCR_audio.soundPlayedFrame * 14 +
(((LCR_audio.soundPlayedFrame >> 2) * (LCR_audio.soundPlayedFrame >> 6))
>> 4)) & 0x0f));
if (LCR_audio.soundPlayedFrame >= 4000)
LCR_audio.soundPlayed = LCR_SOUND_NONE;
break;
case LCR_SOUND_CLICK:
{
int v = ((LCR_audio.soundPlayedFrame >> 6) *