Update pokitto

This commit is contained in:
Miloslav Číž 2020-04-18 14:42:33 +02:00
parent f7072f7158
commit 1e06f59586
2 changed files with 21 additions and 9 deletions

View File

@ -17,7 +17,7 @@
#include "settings.h" #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 #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]; uint8_t audioBuff[SFG_SFX_SAMPLE_COUNT];
uint16_t audioPos = 0; 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 void onTimer() // for sound
{ {
if (Chip_TIMER_MatchPending(LPC_TIMER32_0, 1)) if (Chip_TIMER_MatchPending(LPC_TIMER32_0, 1))
{ {
Chip_TIMER_ClearMatch(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; 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) for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
{ {
int16_t mixedValue = audioBuff[pos] =
audioBuff[pos] - 127 + SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep; mixSamples(audioBuff[pos],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;
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0; pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0;
} }

View File

@ -61,7 +61,7 @@ uint8_t SFG_getNextMusicSample()
SFG_MusicState.n11t = 0; SFG_MusicState.n11t = 0;
} }
uint8_t result; uint32_t result;
#define t SFG_MusicState.t #define t SFG_MusicState.t
#define t2 SFG_MusicState.t2 #define t2 SFG_MusicState.t2