stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / audio.h
diff --git a/audio.h b/audio.h
index 0572d6dcf52b623fc7a3f313c370e0d70e0f4d7c..212ed9f19d8231a13e004122d5c5b7a39d8ae994 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -1,7 +1,10 @@
+#include "common.h"
+static void audio_spacialize( sfx_system *sys,
+                              v3f pos, v3f camera, v3f ears, float vol );
+
 #ifndef AUDIO_H
 #define AUDIO_H
 
-#include "common.h"
 #include "world.h"
 
 static float audio_occlusion_current = 0.0f,
@@ -9,8 +12,6 @@ static float audio_occlusion_current = 0.0f,
 
 static int   k_audio_debug_soundscape = 0;
 
-sfx_vol_control audio_vol_all = { .val = 1.0f, .name = "All" };
-
 sfx_set audio_board =
 {
    .sources = "sound/skate.ogg\0"
@@ -85,6 +86,21 @@ static void audio_free(void)
    sfx_set_free( &audio_board );
 }
 
+static void audio_spacialize( sfx_system *sys,
+                              v3f pos, v3f camera, v3f ears, float vol )
+{
+   float attn = (v3_dist( pos, camera ) / vol) +1.0f;
+
+   v3f delta;
+   v3_sub( pos, camera, delta );
+   v3_normalize( delta );
+   
+   float pan = v3_dot( ears, delta );
+
+   sys->vol = 1.0f/(attn*attn);
+   sys->pan = pan;
+}
+
 static void audio_sample_occlusion( v3f origin )
 {
    float d = 0.0f,
@@ -95,14 +111,7 @@ static void audio_sample_occlusion( v3f origin )
    for( int i=0; i<sample_count; i++ )
    {
       v3f dir;
-      dir[0] = vg_randf();
-      dir[1] = vg_randf();
-      dir[2] = vg_randf();
-
-      v3_muls( dir, 2.0f, dir );
-      v3_sub( dir, (v3f){1.0f,1.0f,1.0f}, dir );
-
-      v3_normalize( dir );
+      vg_rand_dir( dir );
 
       ray_hit contact;
       contact.dist = 15.0f;
@@ -137,7 +146,7 @@ static void audio_debug_soundscapes(void)
    char buf[64];
    snprintf( buf, 31, "occlusion: %.5f", audio_occlusion_current );
 
-   ui_global_ctx.cursor[0] = 10;
+   ui_global_ctx.cursor[0] = 250;
    ui_global_ctx.cursor[1] = 10;
    ui_global_ctx.cursor[2] = audio_occlusion_current * 200.0f;
    ui_global_ctx.cursor[3] = 20;