7 static float audio_occlusion_current
= 0.0f
,
8 k_audio_occlusion_rate
= 1.0f
;
10 static int k_audio_debug_soundscape
= 0;
12 sfx_vol_control audio_vol_all
= { .val
= 1.0f
, .name
= "All" };
16 .sources
= "sound/skate.ogg\0"
22 sfx_system audio_player0
=
26 .vol_src
= &audio_vol_all
,
28 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
31 sfx_system audio_player1
=
35 .vol_src
= &audio_vol_all
,
37 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
40 sfx_system audio_player2
=
44 .vol_src
= &audio_vol_all
,
46 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
49 sfx_system audio_player3
=
53 .vol_src
= &audio_vol_all
,
55 .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
58 static void audio_init(void)
60 sfx_set_init( &audio_board
, NULL
);
61 sfx_set_play( &audio_board
, &audio_player0
, 0 );
62 sfx_set_play( &audio_board
, &audio_player1
, 1 );
63 sfx_set_play( &audio_board
, &audio_player2
, 2 );
64 sfx_set_play( &audio_board
, &audio_player3
, 3 );
66 vg_convar_push( (struct vg_convar
){
67 .name
= "aud_debug_soundscape",
68 .data
= &k_audio_debug_soundscape
,
69 .data_type
= k_convar_dtype_i32
,
70 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
74 vg_convar_push( (struct vg_convar
){
75 .name
= "aud_occlusion_rate",
76 .data
= &k_audio_occlusion_rate
,
77 .data_type
= k_convar_dtype_f32
,
78 .opt_f32
= { .clamp
= 0 },
83 static void audio_free(void)
85 sfx_set_free( &audio_board
);
88 static void audio_sample_occlusion( v3f origin
)
95 for( int i
=0; i
<sample_count
; i
++ )
102 v3_muls( dir
, 2.0f
, dir
);
103 v3_sub( dir
, (v3f
){1.0f
,1.0f
,1.0f
}, dir
);
108 contact
.dist
= 15.0f
;
110 if( ray_world( origin
, dir
, &contact
) )
114 vg_line( origin
, contact
.pos
, 0xff0000ff );
115 vg_line_pt3( contact
.pos
, 0.1f
, 0xff0000ff );
120 v3_muladds( origin
, dir
, sample_dist
, p1
);
121 vg_line( origin
, p1
, 0xffcccccc );
127 float occlusion
= 1.0f
- (d
* (1.0f
/(sample_dist
*(float)sample_count
))),
128 rate
= ktimestep
* k_audio_occlusion_rate
,
129 target
= powf( occlusion
, 6.0f
);
130 audio_occlusion_current
= vg_lerpf( audio_occlusion_current
, target
, rate
);
133 static void audio_debug_soundscapes(void)
135 if( !k_audio_debug_soundscape
) return;
138 snprintf( buf
, 31, "occlusion: %.5f", audio_occlusion_current
);
140 ui_global_ctx
.cursor
[0] = 10;
141 ui_global_ctx
.cursor
[1] = 10;
142 ui_global_ctx
.cursor
[2] = audio_occlusion_current
* 200.0f
;
143 ui_global_ctx
.cursor
[3] = 20;
145 gui_fill_rect( ui_global_ctx
.cursor
, 0x55cccccc );
146 gui_text( ui_global_ctx
.cursor
, buf
, 1, 0 );