Process an Ambient Sound Pattern
| 94 | |
| 95 | // Process an Ambient Sound Pattern |
| 96 | static void ProcessASP(asp *asp) { |
| 97 | // Check for empty ASP |
| 98 | if (!asp->num_sounds) |
| 99 | return; |
| 100 | |
| 101 | // Decrement delay |
| 102 | asp->delay -= Frametime; |
| 103 | |
| 104 | // Time to play? |
| 105 | if (asp->delay < 0.0) { |
| 106 | |
| 107 | // Figure out which sound to play |
| 108 | int roll = (ps_rand() * 100) / (D3_RAND_MAX + 1); // roll = 0..99 |
| 109 | int s; |
| 110 | |
| 111 | for (s = 0; s < asp->num_sounds; s++) |
| 112 | if ((roll -= asp->sounds[s].probability) < 0) |
| 113 | break; |
| 114 | |
| 115 | ASSERT(s < asp->num_sounds); |
| 116 | |
| 117 | // Play sound i |
| 118 | ase *sound = &asp->sounds[s]; |
| 119 | float volume = sound->min_volume + (sound->max_volume - sound->min_volume) * randf(); |
| 120 | Sound_system.Play2dSound(sound->handle, volume); |
| 121 | |
| 122 | // Compute delay until next sound |
| 123 | asp->delay = asp->min_delay + (asp->max_delay - asp->min_delay) * randf(); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Does the ambient sound processing for one frame, maybe playing a sound or two |
| 128 | void DoAmbientSounds() { |
no test coverage detected