Update the sound on the terrain
| 2810 | |
| 2811 | // Update the sound on the terrain |
| 2812 | void UpdateTerrainSound() { |
| 2813 | // Update fade in/out (for inside/outside transitions) |
| 2814 | if (OBJECT_OUTSIDE(Player_object)) { |
| 2815 | if (Terrain_sound_fade < 1.0) { // fading in |
| 2816 | Terrain_sound_fade += Frametime / FADE_TIME; |
| 2817 | if (Terrain_sound_fade > 1.0) |
| 2818 | Terrain_sound_fade = 1.0; |
| 2819 | } |
| 2820 | } else { |
| 2821 | if (Terrain_sound_fade > 0.0) { // fading out |
| 2822 | Terrain_sound_fade -= Frametime / FADE_TIME; |
| 2823 | if (Terrain_sound_fade < 0.0) |
| 2824 | Terrain_sound_fade = 0.0; |
| 2825 | } else |
| 2826 | return; // already faded out |
| 2827 | } |
| 2828 | |
| 2829 | // Get player altitude |
| 2830 | int alt = Player_object->pos.y / TERRAIN_HEIGHT_INCREMENT; |
| 2831 | if (alt > 255) { |
| 2832 | alt = 255; |
| 2833 | } |
| 2834 | |
| 2835 | // Update each sound |
| 2836 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) { |
| 2837 | terrain_sound_band *tb = &Terrain_sound_bands[b]; |
| 2838 | if (tb->sound_index != -1) { |
| 2839 | float volume; |
| 2840 | |
| 2841 | if ((alt < tb->low_alt) || (alt > tb->high_alt)) |
| 2842 | volume = 0.0; |
| 2843 | else |
| 2844 | volume = |
| 2845 | tb->low_volume + ((tb->high_volume - tb->low_volume) * (alt - tb->low_alt) / (tb->high_alt - tb->low_alt)); |
| 2846 | |
| 2847 | Sound_system.Update2dSound(Terrain_sound_handles[b], volume * Terrain_sound_fade, 0.0); |
| 2848 | } |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | // Clear out all the terrain sound bands |
| 2853 | void ClearTerrainSound() { |
no test coverage detected