+ audio_lock();
+
+ float air = s->state.activity <= k_skate_activity_air_to_grind? 1.0f: 0.0f,
+ speed = v3_length( player->rb.v ),
+ attn = vg_minf( 1.0f, speed*0.1f ),
+ slide = vg_clampf( fabsf(s->state.slip), 0.0f, 1.0f );
+
+ if( s->state.activity >= k_skate_activity_grind_any ){
+ slide = 0.0f;
+ }
+
+ f32 gate = 1.0f-menu.factive,
+ vol_main = sqrtf( (1.0f-air)*attn*(1.0f-slide) * 0.4f ) * gate,
+ vol_air = sqrtf( air *attn * 0.5f ) * gate,
+ vol_slide = sqrtf( (1.0f-air)*attn*slide * 0.25f ) * gate;
+
+ const u32 flags = AUDIO_FLAG_SPACIAL_3D|AUDIO_FLAG_LOOP;
+
+ if( !s->aud_air ){
+ s->aud_air = audio_get_first_idle_channel();
+ if( s->aud_air )
+ audio_channel_init( s->aud_air, &audio_board[1], flags );
+ }
+
+ if( !s->aud_slide ){
+ s->aud_slide = audio_get_first_idle_channel();
+ if( s->aud_slide )
+ audio_channel_init( s->aud_slide, &audio_board[2], flags );
+ }
+
+
+ /* brrrrrrrrrrrt sound for tiles and stuff
+ * --------------------------------------------------------*/
+ float sidechain_amt = 0.0f,
+ hz = vg_maxf( speed * 2.0f, 2.0f );
+
+ if( (s->surface == k_surface_prop_tiles) &&
+ (s->state.activity < k_skate_activity_grind_any) )
+ sidechain_amt = 1.0f;
+ else
+ sidechain_amt = 0.0f;
+
+ audio_set_lfo_frequency( 0, hz );
+ audio_set_lfo_wave( 0, k_lfo_polynomial_bipolar,
+ vg_lerpf( 250.0f, 80.0f, attn ) );
+
+ if( s->sample_change_cooldown > 0.0f ){
+ s->sample_change_cooldown -= vg.time_frame_delta;
+ }
+ else{
+ int sample_type = k_skate_sample_concrete;
+
+ if( s->state.activity == k_skate_activity_grind_5050 ){
+ if( s->surface == k_surface_prop_metal )
+ sample_type = k_skate_sample_metal_scrape_generic;
+ else
+ sample_type = k_skate_sample_concrete_scrape_metal;
+ }
+ else if( (s->state.activity == k_skate_activity_grind_back50) ||
+ (s->state.activity == k_skate_activity_grind_front50) )
+ {
+ if( s->surface == k_surface_prop_metal ){
+ sample_type = k_skate_sample_metal_scrape_generic;
+ }
+ else{
+ float a = v3_dot( player->rb.to_world[2], s->grind_dir );
+ if( fabsf(a) > 0.70710678118654752f )
+ sample_type = k_skate_sample_concrete_scrape_wood;
+ else
+ sample_type = k_skate_sample_concrete_scrape_metal;
+ }
+ }
+ else if( s->state.activity == k_skate_activity_grind_boardslide ){
+ if( s->surface == k_surface_prop_metal )
+ sample_type = k_skate_sample_metal_scrape_generic;
+ else
+ sample_type = k_skate_sample_concrete_scrape_wood;
+ }
+
+ audio_clip *relevant_samples[] = {
+ &audio_board[0],
+ &audio_board[0],
+ &audio_board[7],
+ &audio_board[6],
+ &audio_board[5]
+ };
+
+ if( (s->main_sample_type != sample_type) || (!s->aud_main) ){
+ s->aud_main =
+ audio_channel_crossfade( s->aud_main, relevant_samples[sample_type],
+ 0.06f, flags );
+ s->sample_change_cooldown = 0.1f;
+ s->main_sample_type = sample_type;
+ }
+ }
+
+ if( s->aud_main ){
+ s->aud_main->colour = 0x00103efe;
+ audio_channel_set_spacial( s->aud_main, player->rb.co, 40.0f );
+ //audio_channel_slope_volume( s->aud_main, 0.05f, vol_main );
+ audio_channel_edit_volume( s->aud_main, vol_main, 1 );
+ audio_channel_sidechain_lfo( s->aud_main, 0, sidechain_amt );
+
+ float rate = 1.0f + (attn-0.5f)*0.2f;
+ audio_channel_set_sampling_rate( s->aud_main, rate );
+ }
+
+ if( s->aud_slide ){
+ s->aud_slide->colour = 0x00103efe;
+ audio_channel_set_spacial( s->aud_slide, player->rb.co, 40.0f );
+ //audio_channel_slope_volume( s->aud_slide, 0.05f, vol_slide );
+ audio_channel_edit_volume( s->aud_slide, vol_slide, 1 );
+ audio_channel_sidechain_lfo( s->aud_slide, 0, sidechain_amt );
+ }
+
+ if( s->aud_air ){
+ s->aud_air->colour = 0x00103efe;
+ audio_channel_set_spacial( s->aud_air, player->rb.co, 40.0f );
+ //audio_channel_slope_volume( s->aud_air, 0.05f, vol_air );
+ audio_channel_edit_volume( s->aud_air, vol_air, 1 );
+ }
+
+ audio_unlock();