Add sound volume

This commit is contained in:
Miloslav Číž 2020-02-06 08:42:39 +01:00
parent 67fa410751
commit f71479e5ec
3 changed files with 23 additions and 2 deletions

15
main.c
View File

@ -1358,11 +1358,24 @@ void SFG_explodeBarrel(uint8_t itemIndex, RCL_Unit x, RCL_Unit y, RCL_Unit z)
SFG_createExplosion(x,y,z);
}
uint8_t SFG_distantSoundVolume(RCL_Unit x, RCL_Unit y, RCL_Unit z)
{
RCL_Unit distance = SFG_taxicabDistance(x,y,z,
SFG_player.camera.position.x,
SFG_player.camera.position.y,
SFG_player.camera.height);
if (distance >= SFG_SFX_MAX_DISTANCE)
return 0;
return 255 - (distance * 255) / SFG_SFX_MAX_DISTANCE;
}
void SFG_createExplosion(RCL_Unit x, RCL_Unit y, RCL_Unit z)
{
SFG_ProjectileRecord explosion;
SFG_playSound(2,255);
SFG_playSound(2,SFG_distantSoundVolume(x,y,z));
explosion.type = SFG_PROJECTILE_EXPLOSION;

View File

@ -192,8 +192,10 @@ void audioFillCallback(void *userdata, uint8_t *s, int l)
void SFG_playSound(uint8_t soundIndex, uint8_t volume)
{
uint8_t volumeStep = volume / 16;
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
audioBuff[i] = SFG_GET_SFX_SAMPLE(soundIndex,i) * 16;
audioBuff[i] = SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep;
audioPos = 0;

View File

@ -175,6 +175,12 @@
*/
#define SFG_ELEMENT_DISTANCES_CHECKED_PER_FRAME 8
/**
Maximum distance at which sound effects (SFX) will be played. The SFX volume
will gradually drop towards this distance.
*/
#define SFG_SFX_MAX_DISTANCE (1024 * 20)
/**
Says the intensity of background image blur. 0 means no blur, improves
performance and lowers memory usage.