audio samplers

Godot sound sampler example

PopcornFX enables you to create audio-driven visual effects. The source of audio for said effects can be exported as an attribute sampler to be set inside the plugin.

This means you can have audio from your game impact your visual effects.

You can learn how to use audio samplers inside the PopcornFX editor on this page.

Quickstart

Let us assume you have created an audio-reactive PopcornFX effect which exports one audio attribute sampler called sound. Your objective is to have this effect react to your game’s audio bus called Music. Let’s walk through the steps to make it work inside Godot.

First, as usual, add a PKEmitter3D to your scene. In the inspector, set its Effect property to your audio-reactive effect. You should see that in the inspector panel, sound has been added to the list of attribute samplers.

Godot inspector audio sampler highlighted

Now, open Godot’s Audio panel. It is assumed you know how to set up your audio on the Godot side, and that you have already created an audio bus called Music aswell as an AudioStreamPlayer that feeds into it. If not, you may want to consult the Godot documentation on audio buses.

On your Music bus, add a PKCapture audio effect. It will take care of passing the audio from Godot to the PopcornFX runtime.
Godot audio capture

Finally, in your sound attribute sampler, set Bus Name dropdown to the name of your Godot bus (here, Music), and set Effect Index dropdown to the 0-based index of your PKCapture in the bus. For example, if you added a filter effect before the PKCapture, Effect Index`should be `1.

Now, if you play the music from your AudioStreamPlayer inside the Godot editor or in your game, the effect will react to it !

Godot sound sampler example

The other properties available in the audio attribute sampler are explained further down this page.

How PopcornFX channels work

PopcornFX has a notion of audio channels. Just like Godot buses, they allow routing audio from one or multiple sources to one or multiple destinations. They are mostly working under the runtime’s hat, therefore the only thing you need to know about them is that they are uniquely defined by their name.

An audio attribute sampler targets one channel. Multiple samplers can target the same channel. In the editor, you can "sample" a sampler to access the data of its targeted channel.

In Godot, you are able to send data from Godot into the channel of an audio sampler targets. You can also change the targeted channel by changing its name (no need to "create" it beforehand), or make this sampler’s targeted channel local, meaning only this sampler can send or use data from this channel (the name then becomes irrelevant).

The PKCapture audio effect

In order to pass audio from Godot to the PopcornFX runtime, you need to use a custom Godot audio effect called PKCapture.

There are a few key things to keep in mind about PKFXCapture:
* Contrary to Godot’s audio capture, you can safely use the same one as the source of multiple audio attribute samplers.
* Moving a PKCapture used by attribute samplers to a different index or bus may cause strange issues. If you move one, it is advised that you update the Bus name and Effect index of your attribute samplers immediately, even if they still seem to be working as intended.

Available properties

The plugin allows you to modify the following properties of your audio sampler:

Godot inspector audio sampler highlighted

  • Is PK Channel Global: Whether the target PopcornFX Channel is global:

    • If yes: All the samplers who share the same channel name share the data. This lets you centralize the audio acquisition if a lot of effect instances use the same audio source

    • If no: This sampler has its own channel, preventing unwanted "collisions" if you have effects that shouldn’t use the same audio data but have the same channel name.

  • Target Popcorn Channel: The name of the PopcornFX channel to send the captured audio data to, and read from.

  • Bus Name: The name of the Godot bus to sample from. The bus should contain a PKCapture in its effect stack. Leave it empty (in the inspector, set it to "(None)") if this sampler shouldn’t actively sample audio (Its channel may still get data from another sampler).

  • Audio Effect Index: The index of the PKCapture to sample. In the inspector, when a Bus Name is set, this property is set to the first PKCapture on the selected bus. If you set Bus Name by code, you also need to set the index youself.

  • Smoothing Factor: Interpolation factor between last frame’s and the current frame’s data. Acts on the audio captured by this sampler, not on the other data that may be in the popcorn channel.

    • 0 means no interpolation. The result may look jittery.

    • 1 means last frame’s data. Your effect will effectively get the same audio data each frame.

    • Values in-between will increasingly smoothen the value temporally. It will also make them smaller. You may use the Scale Factor property in order to correct this if needed.

  • Scale Factor: Scales the sampled values. For example, a scale of 2.0 will give values twice as big.