5 #include "vg/vg_audio.h"
9 audio_pack audio_birds
=
11 .sources
= "sound/bird0.ogg\0"
15 .source_mode
= k_audio_source_compressed
19 static float k_audio_random_freq
= 1.0f
/10.0f
,
20 k_audio_random_hz
= 1.0f
;
22 static double world_audio_last_tick
= 0.0;
24 static struct world_ambient_layer
29 world_ambient_layers
[8];
31 static void world_audio_init(void)
34 audio_pack_init( &audio_birds
);
36 vg_convar_push( (struct vg_convar
){
37 .name
= "aud_random_freq",
38 .data
= &k_audio_random_freq
,
39 .data_type
= k_convar_dtype_f32
,
40 .opt_f32
= { .clamp
= 0 },
44 for( int i
=0; i
<vg_list_size(world_ambient_layers
); i
++ )
46 struct world_ambient_layer
*layer
= &world_ambient_layers
[i
];
47 audio_player
*sys
= &layer
->sys
;
50 sys
->name
= "ambient";
51 sys
->flags
= SFX_FLAG_PERSISTENT
;
56 static void world_audio_spawn_random( v3f around
)
59 for( int i
=0; i
<vg_list_size(world_ambient_layers
); i
++ )
61 struct world_ambient_layer
*layer
= &world_ambient_layers
[i
];
63 if( !layer
->sys
.is_playing
)
65 sfx_set_playrnd( &audio_birds
, &layer
->sys
, 0, 3 );
68 vg_rand_sphere( chance
);
69 v3_muladds( around
, chance
, 100.0f
, layer
->pos
);
77 static void world_audio_update( v3f around
, v3f ears
)
80 if( world_audio_last_tick
+ (double)k_audio_random_hz
< vg_time
)
82 world_audio_last_tick
= vg_time
;
84 float chance
= vg_randf();
85 if( chance
< k_audio_random_freq
)
87 world_audio_spawn_random( around
);
92 for( int i
=0; i
<vg_list_size(world_ambient_layers
); i
++ )
94 struct world_ambient_layer
*layer
= &world_ambient_layers
[i
];
96 if( layer
->sys
.is_playing
)
97 audio_player_spacialize(&layer
->sys
, layer
->pos
, around
, ears
, 30.0f
);
102 static void world_audio_debug(void)
105 for( int i
=0; i
<vg_list_size(world_ambient_layers
); i
++ )
107 struct world_ambient_layer
*layer
= &world_ambient_layers
[i
];
109 if( layer
->sys
.is_playing
)
111 vg_line_pt3( layer
->pos
, 1.0f
, 0xffff00ff );
117 #endif /* WORLD_AUDIO_H */