Listen to the relaxing sound of ocean waves generated by Ruby.
ruby entry.rb
ruby entry.rb seashore.wav 60
The default filename is output.wav
and the default duration is 30 seconds.
Tested with ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +MN +PRISM [arm64-darwin22]
Noise sound is created by applying low-pass/band-pass filter to a white noise signal. Volume of the noise should change over time. This is also calculated by using low-pass filter.
Sound of a single ocean wave is composed of hundreds of water splash sounds. Each water splash sound is composed of thousands of water drops and bubbles. This program creates this complicated sound by repeating sound mixing.
sound2 = mix(sound1.change_pitch(rand), sound1.change_pitch(rand).delay(rand))
sound4 = mix(sound2.change_pitch(rand), sound2.change_pitch(rand).delay(rand))
...
sound32768 = mix(sound16384.change_pitch(rand), sound16384.change_pitch(rand).delay(rand))
splash1 = mix(sound1.delay(rand), sound2.delay(rand), sound4.delay(rand), ..., sound16384.delay(rand))
splash2 = mix(splash1.change_pitch(rand), splash1.change_pitch(rand).delay(rand))
splash4 = mix(splash2.change_pitch(rand), splash2.change_pitch(rand).delay(rand))
...
splash1024 = mix(splash512.change_pitch(rand), splash512.change_pitch(rand).delay(rand))
wave_sound = [splash32, splash64, ..., splash1024].sample
This kind of repetition is often used in fractal rendering. In other words, this operation is rendering a fractal shape to the spectrogram canvas. It's an efficient way to create complex structure with low computational cost.