Cabbage Logo
Back to Cabbage Site

Simulating water using vocoder?

Hi, I’m looking into whether it’s viable to use FMOD Studio with Cabbage plugins to create custom sound effects for a Unity game. (I know there’s a direct Unity integration too, but Fmod offers a lot of extra versatility in general, I think.) I’m completely new to Cabbage, Csound and low level sound programming in general.

The reason I stumbled upon Cabbage in the first place is because I saw this video about how to simulate rain or streaming water using a vocoder effect used on white noise:

After installing Cabbage, I tried to see if I could replicate it using the example vocoder in Cabbage. I tried using matching settings for bands and how they’re spaced, and modified the effect so Bandwidth could go beyond 100% like in the video.

However, where the effect in the video gets really interesting is using the gate functionality to emulate control of the “number of water drops”. This can be used to make the sound of just a few water drops dripping infrequently. That, and all the way up to a heavy torrent of water.

In Cabbage’s vocoder there is a “Gate Input” toggle but in my case it makes no difference to the sound and there is no slider anyway for what the gate value is, as far as I can tell. So I didn’t manage to replicate the effect.

Is such gate functionality something that could be handled by a different plugin chained after the vocoder, or would it have to be built into the vocoder effect itself? (As you can tell, I currently have no idea how any of this works.) There probably isn’t much chance of me being able to add it to the vocoder plugin myself, given I have no experience with this type of programming or audio signal engineering.

Thanks for your time!
Rune

Interesting video. I am not that familar with the gate functionality of the @iainmccurdy’s vocoder example. Maybe he can offer some advise on this :slight_smile:

The gate in the Vocoder example is just a very simple noise gate to block noise from a laptop’s built-in microphone when not speaking into it so that the vocoder doesn’t ‘hum’ a note or chord during these pauses. At the top of the csd is the comment:

; Gate Input - Activating this switch will apply a noise gate to the modulator signal. This option might be useful if the microphone used in rather noisy, such as would be the case if using the built-in microphone on a laptop, or if working in a noisy environment.

I wanted to keep it simple and uncluttered so there is only an on/off switch. The relevant code it this:

 ;GATE MODULATOR SIGNAL
 if gkgate==1 then                               ; IF 'Gate Modulator' SWITCH IS ON....
  krms    rms      aMod1 + aMod2                 ; SCAN RMS OF MODUALTOR SIGNAL
  kgate   =        (krms < 0.05 ? 0 : 1)         ; IF RMS OF MODULATOR SIGNAL IS BELOW A THRESHOLD, GATE WILL BE CLOSED (ZERO) OTHERWISE IT WILL BE OPEN ('1'). LOWER THE THRESHOLD IF THE GATE IS CUTTING OUT TOO MUCH DESIRED SIGNAL, RAISE IT IF TOO MUCH EXTRANEOUS NOISE IS ENTERING THE OUTPUT SIGNAL.
  kgate   port     kgate, 0.01                   ; DAMP THE OPENING AND CLOSING OF THE GATE SLIGHTLY
  agate   interp   kgate                         ; INTERPOLATE GATE VALUE AND CREATE AN A-RATE VERSION
  aMod1   *=       agate                         ; APPLY THE GATE TO THE MODULATOR SIGNAL
  aMod2   *=       agate                         ; APPLY THE GATE TO THE MODULATOR SIGNAL
 endif

I think the gating function you are describing and are wanting is something quite different - this is when individual bins of the FFT are silenced if they drop below a defined threshold. So this is operating on a spectrally disassembled audio signal as opposed to a traditional noise gate which is simply applied to the whole signal.

The pvadd opcode has this feature built-in. You could also do this with pvstencil. You can probably achieve a similer effect (though by a slightly different action) using pvstrace.

I hope this is some help. If you get stuck, I might have a go at the implementation myself as it sounds like an interesting idea. I imagine that the FFT size chosen will also have a significant effect on the result.

1 Like

Thanks for the clarification and the pointers! This is beyond me for now, as I haven’t even learned the basics of this programming language yet, but I might give it a spin sometime. :slight_smile:

I don’t know anything about FMOD Studio or Unity. Creating synthesized water in Csound similar to the video seems fairly possible. I would probably go with a procedural audio approach though, the pvs opcodes/vocoder approach could be difficult to mimic in Csound.

One option to consider, it might easier & simpler to work backwords so to speak. Instead of trying to pull frequencies from noise using a multitude of bands & gates, use noise to modulate the frequency and amp of a simple sine wave. This essentially creates something like bandlimited noise which looks quite similar to the video if viewed in a spectrum analyzer. It would likely be more cpu friendly as well, especially when used to sound like drops - the faster the droplets, the more cpu intensive it becomes.

However, if one added noise to droplets instead of just increasing the rate (say to sound like rain or a fast running steam) then that could significantly lower the load as well which might be beneficial for games etc. I didn’t in this case, just to push the concept of water using only “droplets”. Here’s a fairly simple example. This is a single sine oscillator using a few randomization opcodes (random, rspline, gausstrig, betarand). I didn’t spend much time tweaking though, I’m sure one could achieve much better results.

If it won’t play correctly try clicking on the 3 vertical dots & downloading.

Regardless of the software you use, it definitely helps to have a basic understanding of how to add some level of realistic randomization of the parameters involved, to think it thru in a procedural manner. And understanding the basic differences in random distribution methods (gauss, beta etc.).

If this example interests you let me know. The concepts used should be applicable in most audio languages (Csound, Pure Data, FMOD or whatever).

@rorywalsh I tried embedding the dropbox link:
https://www.dropbox.com/scl/fi/wzmyh9bym96mpktlxv2i9/synthesized_water.mp3?rlkey=ob6qdrrn38ah5go84vef2moon&raw=1
but for some reason it only plays for a few seconds. Have you any experience with this?

1 Like

That’s odd, can you just add the mp3 as an attachment directly?

Sure, I guess I just try to avoid uploading larger files in case that’s an issue.

Nice. This reminds me of Barry Truax’s Riverun :slight_smile:

That’s very nice. I particularly like the ‘silveriness’ of the bit at the end. You’ve been able to incorporate the noise in a subtle yet effective way.

I made a start at the FFT approach.
FFTWater.csd (3.0 KB)

Thanks for putting this together. It sounds way more synthetic than the FFT based approach though. And it’s only showing off the “few droplets” end of the spectrum, while what I liked about the FFT based approach is how it could seamlessly go from a few droplets at a time all the way to heavy torrent of water (water stream or rainfall) by adjusting one slider.

Now, it’s possible this approach would also be able to do that, as well as not sounding so synthetic, with more work. But we only really know that for sure if and when someone manages to do that. It could also be the case that this approach is fundamentally more limited and will never be able to produce as good results. And I’m not really interested in doing original research here (nor would I suggest anyone else to), but rather just to replicate an approach that have already been proven to work and be able to produce results of a given quality I considered sufficiently high.

That said, of course anyone can pursue any experiment they want. But I’m just trying to explain why I would not go down this proposed route myself, since it’s not at this point proven to be able to actually work as well.

Oh, nice start of the FFT approach! I can already hear it’s going in the same direction as in the video.

I’ll need to dig into the commands and this programming language at some point to better understand it. The FFT in the video has 40 bands ranging from 80 Hz to 16 kHz, with the bandwiths set to 150%. I couldn’t yet figure out how this relates to FFT size and Number in your code. Is Number the number of bands?

‘Number’ is effectively the maximum number of droplets permitted at any one time. This is enacted using the pvstrace opcode.

‘Gate’ also limits the number of droplets but more like a standard noise gate in that droplets below the defined threshold will be muted (pvstencil). For this reason ‘Number’ and ‘Gate’ can prevent the other from being effective given various settings combinations so understanding of what they are doing is useful.

I would need to take another look at the original video, but bandwidth will be defined by FFT Size. The number of bands will be FFT Size/2 +1 and bins will be evenly spread from 0 Hz up to sr/2 Hz. FFT Size will also vary the duration of droplets.

I would probably develop this by adding parallel layers with each layer addressing a different descriptive component of the overall sound with things like ‘roar’, ‘tinkle’, ‘dribble’, ‘bubble’ etc. This idea of layers corresponding to different distances from a large sources is very much the Walter Murch approach.