phantasia

Phantasia - 2D SDL3 RPG prototype.
git clone git://git.beep.wimdupont.com/phantasia.git
Log | Files | Refs | README | LICENSE

audio.c (428B)


      1 #include "engine/audio.h"
      2 
      3 #include <math.h>
      4 
      5 float
      6 ph_audio_distance_gain(float listener_x, float listener_y,
      7 	float source_x, float source_y, float max_distance)
      8 {
      9 	float dx;
     10 	float dy;
     11 	float distance;
     12 
     13 	if (max_distance <= 0.0f) return 0.0f;
     14 	dx = source_x - listener_x;
     15 	dy = source_y - listener_y;
     16 	distance = sqrtf(dx * dx + dy * dy);
     17 	if (distance >= max_distance) return 0.0f;
     18 	return 1.0f - distance / max_distance;
     19 }