Fix sound

This commit is contained in:
Miloslav Číž 2020-09-19 13:31:50 +02:00
parent 98d8c47f59
commit d06ce1c684
2 changed files with 16 additions and 2 deletions

4
game.h
View File

@ -101,8 +101,8 @@ static inline void SFG_setPixel(uint16_t x, uint16_t y, uint8_t colorIndex);
/**
Play given sound effect (SFX). This function may or may not use the sound
samples provided in sounds.h, and it may or may not ignore the volume
parameter (which is 0 to 255). Depending on the platform the function can play
samples provided in sounds.h, and it may or may not ignore the (logarithmic)
volume parameter (0 to 255). Depending on the platform the function can play
completely different samples or even e.g. just beeps. If the platform can't
play sounds, this function implementation can simply be left empty. This
function doesn't have to implement safety measures, the back end takes cares

View File

@ -245,6 +245,19 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume)
{
uint16_t pos = audioPos;
uint8_t volumeShift = 15 - volume / 16;
uint16_t baseLevel = AUDIO_ZERO - (0x8000 >> volumeShift);
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
{
audioBuff[pos] = mixSamples(audioBuff[pos],baseLevel +
((SFG_GET_SFX_SAMPLE(soundIndex,i) << 8) >> volumeShift));
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0;
}
/*
int8_t volumeShift = volume / 16 - 7; // -7 to 8
uint16_t baseLevel = AUDIO_ZERO - (0x0001 << (volumeShift + 7));
@ -258,6 +271,7 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume)
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0;
}
*/
}
int main(int argc, char *argv[])