From 1e06f59586892ca2e5357eccb8514005df4e510c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 18 Apr 2020 14:42:33 +0200 Subject: [PATCH] Update pokitto --- platform_pokitto.h | 28 ++++++++++++++++++++-------- sounds.h | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/platform_pokitto.h b/platform_pokitto.h index 1a74e94..6368d7c 100644 --- a/platform_pokitto.h +++ b/platform_pokitto.h @@ -17,7 +17,7 @@ #include "settings.h" -#define SFG_LOG(str) printf("game: %s\n",str); // for debug only +//#define SFG_LOG(str) printf("game: %s\n",str); // for debug only #define SFG_TEXTURE_DISTANCE 5000 @@ -97,13 +97,29 @@ void SFG_getMouseOffset(int16_t *x, int16_t *y) uint8_t audioBuff[SFG_SFX_SAMPLE_COUNT]; uint16_t audioPos = 0; +uint8_t musicOn = 1; + +void SFG_enableMusic(uint8_t enable) +{ + musicOn = enable; +} + +static inline uint8_t mixSamples(uint8_t sample1, uint8_t sample2) +{ + return (sample1 >> 1) + (sample2 >> 1); +} + void onTimer() // for sound { if (Chip_TIMER_MatchPending(LPC_TIMER32_0, 1)) { Chip_TIMER_ClearMatch(LPC_TIMER32_0, 1); - Pokitto::dac_write(audioBuff[audioPos]); + Pokitto::dac_write( + musicOn ? + mixSamples(audioBuff[audioPos],SFG_getNextMusicSample() / 2) : + audioBuff[audioPos] + ); audioBuff[audioPos] = 127; @@ -136,12 +152,8 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume) for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i) { - int16_t mixedValue = - audioBuff[pos] - 127 + SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep; - - mixedValue = (mixedValue > 0) ? ((mixedValue < 255) ? mixedValue : 255) : 0; - - audioBuff[pos] = mixedValue;// SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep; + audioBuff[pos] = + mixSamples(audioBuff[pos],SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep); pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0; } diff --git a/sounds.h b/sounds.h index 9b38c83..bc2fd7c 100644 --- a/sounds.h +++ b/sounds.h @@ -61,7 +61,7 @@ uint8_t SFG_getNextMusicSample() SFG_MusicState.n11t = 0; } - uint8_t result; + uint32_t result; #define t SFG_MusicState.t #define t2 SFG_MusicState.t2