83 lines
1.3 KiB
C
83 lines
1.3 KiB
C
|
/**
|
||
|
audio: this file implements the audio system.
|
||
|
*/
|
||
|
|
||
|
#ifndef _LCR_AUDIO
|
||
|
#define _LCR_AUDIO
|
||
|
|
||
|
#define LCR_SOUND_NONE 0
|
||
|
#define LCR_SOUND_CLICK 1
|
||
|
#define LCR_SOUND_CRASH 2
|
||
|
#define LCR_SOUND_ACCELERATOR 3
|
||
|
|
||
|
#define LCR_AUDIO_MIN_RPM 128
|
||
|
#define LCR_AUDIO_MAX_RPM 2048
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
uint32_t frame;
|
||
|
uint8_t soundPlayed;
|
||
|
uint16_t soundPlayedSample;
|
||
|
uint32_t noise;
|
||
|
|
||
|
|
||
|
int engineIntensity;
|
||
|
int engineOsc;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
} LCR_audio;
|
||
|
|
||
|
void LCR_audioInit(void)
|
||
|
{
|
||
|
LCR_LOG0("initializing audio");
|
||
|
LCR_audio.frame = 0;
|
||
|
LCR_audio.soundPlayed = LCR_SOUND_NONE;
|
||
|
LCR_audio.soundPlayedSample = 0;
|
||
|
LCR_audio.noise = 0;
|
||
|
|
||
|
LCR_audio.engineOsc = 0;
|
||
|
LCR_audio.engineIntensity = 0;
|
||
|
|
||
|
}
|
||
|
|
||
|
void LCR_audioSetEngineIntensity(uint8_t value)
|
||
|
{
|
||
|
LCR_audio.engineIntensity = value;
|
||
|
}
|
||
|
|
||
|
void LCR_audioPlaySound(uint8_t sound)
|
||
|
{
|
||
|
LCR_audio.soundPlayed = sound;
|
||
|
LCR_audio.soundPlayedSample = 0;
|
||
|
}
|
||
|
|
||
|
uint8_t _LCR_audioNoise(void)
|
||
|
{
|
||
|
LCR_audio.noise = LCR_audio.noise * 32310901 + 37;
|
||
|
return LCR_audio.noise >> 16;
|
||
|
}
|
||
|
|
||
|
uint8_t LCR_audioGetNextSample(void)
|
||
|
{
|
||
|
unsigned char result = 128;
|
||
|
|
||
|
if (LCR_audio.engineIntensity > 5)
|
||
|
{
|
||
|
LCR_audio.engineOsc +=
|
||
|
((_LCR_audioNoise() % 256) <
|
||
|
(30 + LCR_audio.engineIntensity));
|
||
|
|
||
|
result += LCR_audio.engineOsc;
|
||
|
}
|
||
|
|
||
|
LCR_audio.frame++;
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#endif // guard
|