Ambient sound
Add ambient sound — ongoing background sound — which is influenced by the surroundings of the player character. These sounds may be caused by:
- Blocks which are considered to emit sound as long as they exist (e.g. electric hums, grass rustling); not including sounds occurring when a block actually does something. This will need to be a new block attribute.
- Wind noise from the player moving or an assumed amount of background air movement. This would be part of the
SpacePhysics, I suppose.
These sounds (and non-ambient sounds occurring in the area) may be modified by:
- Absorption by blocks, causing frequency-dependent attenuation (filtering)
- Reflection by blocks, causing reverberation dependent on their distance from each other
We can collect information about the ambient sound environment by casting rays from the viewpoint, in the same way that this is already done for camera exposure. (Reverb will need secondary rays too, but even just one normal to the surface should produce nice results, I think.) To efficiently synthesize the sound, we can accumulate all this information to drive shared banks of oscillators (or granular sample players) and filters — as opposed to individual sound sources per cube, which would require more resources and stricter timing.
This issue is being split off from the broader issue https://github.com/kpreid/all-is-cubes/issues/307.
A conversation (prompted by the video A First Look At Raytraced Audio) made me realize that, if we have a reasonable set of rays describing reflections in the environment, their lengths directly correspond to time delays in an impulse response. Therefore, in principle, if for each ray striking a surface (or through however many bounces) we can choose or compute an impulse response representing that reflection, then we can sum the impulse responses from many rays to produce a single impulse response usable in a convolution filter — at least for a single sound source. Using a single filter for multiple sound sources makes the assumption that the sound takes equivalent paths.
I have a just-barely-working implementation of the basic ideas of ambient sound, and am polishing the pieces to mergeable state. As of 20a5824b8b0dab7772fb1873c6edc6ccbeaab84a, we have ambient sound data able to be stored in blocks, but nothing collects or plays it.
As of 044e6e33c0ba23ad1aee0eee08e1185ea1ce3782, the entire ambient sound system is wired up. Further work:
- https://github.com/kpreid/all-is-cubes/issues/704
- https://github.com/kpreid/all-is-cubes/issues/705
- https://github.com/kpreid/all-is-cubes/issues/706