212ed9f19d8231a13e004122d5c5b7a39d8ae994
2 static void audio_spacialize( sfx_system
*sys
,
3 v3f pos
, v3f camera
, v3f ears
, float vol
);
10 static float audio_occlusion_current
= 0.0f
,
11 k_audio_occlusion_rate
= 1.0f
;
13 static int k_audio_debug_soundscape
= 0;
17 .sources
= "sound/skate.ogg\0"
23 sfx_system audio_player0
=
27 .vol_src
= &audio_vol_all
,
29 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
32 sfx_system audio_player1
=
36 .vol_src
= &audio_vol_all
,
38 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
41 sfx_system audio_player2
=
45 .vol_src
= &audio_vol_all
,
47 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
50 sfx_system audio_player3
=
54 .vol_src
= &audio_vol_all
,
56 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
59 static void audio_init(void)
61 sfx_set_init( &audio_board
, NULL
);
62 sfx_set_play( &audio_board
, &audio_player0
, 0 );
63 sfx_set_play( &audio_board
, &audio_player1
, 1 );
64 sfx_set_play( &audio_board
, &audio_player2
, 2 );
65 sfx_set_play( &audio_board
, &audio_player3
, 3 );
67 vg_convar_push( (struct vg_convar
){
68 .name
= "aud_debug_soundscape",
69 .data
= &k_audio_debug_soundscape
,
70 .data_type
= k_convar_dtype_i32
,
71 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
75 vg_convar_push( (struct vg_convar
){
76 .name
= "aud_occlusion_rate",
77 .data
= &k_audio_occlusion_rate
,
78 .data_type
= k_convar_dtype_f32
,
79 .opt_f32
= { .clamp
= 0 },
84 static void audio_free(void)
86 sfx_set_free( &audio_board
);
89 static void audio_spacialize( sfx_system
*sys
,
90 v3f pos
, v3f camera
, v3f ears
, float vol
)
92 float attn
= (v3_dist( pos
, camera
) / vol
) +1.0f
;
95 v3_sub( pos
, camera
, delta
);
96 v3_normalize( delta
);
98 float pan
= v3_dot( ears
, delta
);
100 sys
->vol
= 1.0f
/(attn
*attn
);
104 static void audio_sample_occlusion( v3f origin
)
107 sample_dist
= 880.0f
;
109 int sample_count
= 8;
111 for( int i
=0; i
<sample_count
; i
++ )
117 contact
.dist
= 15.0f
;
119 if( ray_world( origin
, dir
, &contact
) )
123 vg_line( origin
, contact
.pos
, 0xff0000ff );
124 vg_line_pt3( contact
.pos
, 0.1f
, 0xff0000ff );
129 v3_muladds( origin
, dir
, sample_dist
, p1
);
130 vg_line( origin
, p1
, 0xffcccccc );
136 float occlusion
= 1.0f
- (d
* (1.0f
/(sample_dist
*(float)sample_count
))),
137 rate
= ktimestep
* k_audio_occlusion_rate
,
138 target
= powf( occlusion
, 6.0f
);
139 audio_occlusion_current
= vg_lerpf( audio_occlusion_current
, target
, rate
);
142 static void audio_debug_soundscapes(void)
144 if( !k_audio_debug_soundscape
) return;
147 snprintf( buf
, 31, "occlusion: %.5f", audio_occlusion_current
);
149 ui_global_ctx
.cursor
[0] = 250;
150 ui_global_ctx
.cursor
[1] = 10;
151 ui_global_ctx
.cursor
[2] = audio_occlusion_current
* 200.0f
;
152 ui_global_ctx
.cursor
[3] = 20;
154 gui_fill_rect( ui_global_ctx
.cursor
, 0x55cccccc );
155 gui_text( ui_global_ctx
.cursor
, buf
, 1, 0 );