9 static void player_audio(void)
14 _ding
= glfwGetKey(vg_window
, GLFW_KEY_C
);
25 static double last_revert
= -2000.0;
32 double revert_delta
= vg_time
- last_revert
;
33 if( player
.on_board
&& (!_air
&& l2
) && (fabsf(player
.slip
) > 0.5f
) &&
34 (revert_delta
> 0.7) )
36 audio_player_set_position( &audio_player_extra
, player
.rb
.co
);
37 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
38 audio_player_set_vol( &audio_player_extra
, 2.0f
);
39 audio_player_playclip( &audio_player_extra
, &audio_lands
[rand()%5] );
41 last_revert
= vg_time
;
44 static float air
= 0.0f
;
45 air
= vg_lerpf(air
, player
.in_air
? 1.0f
: 0.0f
, 5.0f
*ktimestep
);
48 v3f ears
= { 1.0f
,0.0f
,0.0f
};
51 float *cam
= player
.camera
[3],
55 audio_player_playclip( &audio_player_extra
, &audio_ding
);
57 audio_player_set_position( &audio_player0
, player
.rb
.co
);
58 audio_player_set_position( &audio_player1
, player
.rb
.co
);
59 audio_player_set_position( &audio_player2
, player
.rb
.co
);
60 audio_player_set_position( &audio_player_gate
, world
.render_gate_pos
);
62 v3_sub( player
.rb
.co
, player
.camera
[3], delta
);
63 v3_normalize( delta
);
64 m3x3_mulv( player
.camera
, ears
, ears
);
66 /* TODO, Make function */
67 v3_copy( ears
, vg_audio
.listener_ears
);
68 v3_copy( player
.camera
[3], vg_audio
.listener_pos
);
70 /* Tunnel / occlusion */
71 audio_sample_occlusion( player
.camera
[3] );
73 int sprite_avail
= -1;
74 for( int i
=0; i
<vg_list_size(ambient_sprites
); i
++ )
76 if( !audio_player_is_playing( &ambient_sprites
[i
] ) )
83 if( sprite_avail
!= -1 )
86 enum audio_sprite_type sprite_type
=
87 audio_sample_sprite_random( player
.rb
.co
, waterpos
);
89 if( sprite_type
!= k_audio_sprite_type_none
)
91 audio_player
*avail
= &ambient_sprites
[ sprite_avail
];
93 audio_player_set_vol( avail
, 20.0f
);
94 audio_player_set_flags( avail
, AUDIO_FLAG_SPACIAL_3D
);
95 audio_player_set_position( avail
, waterpos
);
97 if( sprite_type
== k_audio_sprite_type_grass
)
99 audio_player_playclip( avail
, &audio_grass
[rand()%4] );
101 else if( sprite_type
== k_audio_sprite_type_water
)
103 audio_player_playclip( avail
, &audio_water
[rand()%6] );
108 if( freecam
|| player
.is_dead
|| !player
.on_board
)
110 audio_player_set_vol( &audio_player0
, 0.0f
);
111 audio_player_set_vol( &audio_player1
, 0.0f
);
112 audio_player_set_vol( &audio_player2
, 0.0f
);
115 if( vg_fractf(player
.walk_timer
) > 0.5f
)
120 if( (player
.step_phase
!= walk_phase
) && !player
.in_air
)
122 audio_player_set_flags( &audio_player_extra
, AUDIO_FLAG_SPACIAL_3D
);
123 audio_player_set_position( &audio_player_extra
, player
.rb
.co
);
124 audio_player_set_vol( &audio_player_extra
, 6.0f
);
125 audio_player_playclip( &audio_player_extra
,
126 &audio_footsteps
[rand()%4] );
129 player
.step_phase
= walk_phase
;
134 float speed
= vg_minf(v3_length( player
.rb
.v
)*0.1f
,1.0f
),
136 slide
= vg_clampf( fabsf(player
.slip
), 0.0f
, 1.0f
),
137 vol0
= (1.0f
-air
)*attn
*(1.0f
-slide
),
139 vol2
= (1.0f
-air
)*attn
*slide
;
141 audio_player_set_vol( &audio_player0
, vol0
);
142 audio_player_set_vol( &audio_player1
, vol1
);
143 audio_player_set_vol( &audio_player2
, vol2
);
145 float reverb_amt
= vol0
* audio_occlusion_current
* 0.5f
;
146 audio_player_set_pan( &audio_player3
, 0.0f
);
147 audio_player_set_vol( &audio_player3
, reverb_amt
);
151 world_audio_update( cam
, ears
);
156 #endif /* PLAYER_AUDIO_H */