From 3eeb4d7fc2e2594c66d229ddb4fe3533b4f4dc7f Mon Sep 17 00:00:00 2001 From: drummyfish Date: Tue, 24 Dec 2024 01:41:45 +0100 Subject: [PATCH] Continue engine --- audio.h | 26 ++++++++++++++++++++------ game.h | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/audio.h b/audio.h index 0619c1d..062e9b0 100644 --- a/audio.h +++ b/audio.h @@ -23,7 +23,7 @@ struct int engineIntensity; int engineOsc; - +int engineInc; @@ -38,8 +38,12 @@ void LCR_audioInit(void) LCR_audio.noise = 0; LCR_audio.engineOsc = 0; + +LCR_audio.engineInc = 1; + LCR_audio.engineIntensity = 0; + } void LCR_audioSetEngineIntensity(uint8_t value) @@ -59,17 +63,27 @@ uint8_t _LCR_audioNoise(void) return LCR_audio.noise >> 16; } + uint8_t LCR_audioGetNextSample(void) { unsigned char result = 128; - if (LCR_audio.engineIntensity > 5) + //if (LCR_audio.engineIntensity) { - LCR_audio.engineOsc += - ((_LCR_audioNoise() % 256) < - (30 + LCR_audio.engineIntensity)); + LCR_audio.engineOsc += + LCR_audio.engineInc ? + (((_LCR_audioNoise() % 256) < + (10 + LCR_audio.engineIntensity))) : -31; - result += LCR_audio.engineOsc; + if (LCR_audio.engineInc && LCR_audio.engineOsc > + (90 + (LCR_audio.engineIntensity / 8))) + LCR_audio.engineInc = 0; + else if ((!LCR_audio.engineInc) && LCR_audio.engineOsc < 10) + LCR_audio.engineInc = 1; + + result += + LCR_audio.engineIntensity < 20 ? + LCR_audio.engineOsc / 2 : LCR_audio.engineOsc; } LCR_audio.frame++; diff --git a/game.h b/game.h index 14b225e..6581ad2 100644 --- a/game.h +++ b/game.h @@ -396,7 +396,7 @@ LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT - int val = LCR_carSpeedKMH(); -LCR_audioSetEngineIntensity(val < 256 ? val : 255); +LCR_audioSetEngineIntensity((2 * val) < 256 ? (2 * val) : 255); if (val < 5) // don't show tiny oscillations when still val = 0;