I’m trying to figure out how to render a visual representation of the output from a track without writing to a file. Specifically, I’d like to be able to render an FFT of the audio after it has passed through the plugins on a track. There’s probably a dead simple way to do this but I couldn’t figure it out from the examples/API docs. I really just want access to the audio buffer after it leaves the last (or some arbitrary) plugin in the track’s plugin list. Any pointers on where to look would be helpful. ![]()
Do you want a FFT analyzer (like the one in most digital EQ plugins)?
If so, it is NOT a simple task. My approach is:
- on the audio thread: push sample to lock-free FIFO
- on a background thread: pull sample from that FIFO, perform FFT, interpolate and update paths (the last step has a lock)
- on the message thread: get paths updated (from the background thread, has a try lock) and paint
If you want the average over the whole track, you need to play the whole track, then let the plugin accumulate FFT results and take the average.
Thanks for the feedback. Yes, an EQ style FFT is one of the things I’d like to achieve. I’m familiar with the process of sharing a FIFO between the RT and the main threads. What I’m stumbling on is how to populate a FIFO with the audio data coming out of a plugin. My first thought was to pass a FIFO to a custom plugin but it doesn’t seem to be possible to pass anything when adding a plugin to a track. I couldn’t find anything in the Track API to gain access to the audio output of a track either.
I see. So the problem is how to obtain a reference/pointer to the audio buffer from the track (after processing by that track). Unfortunately I not very familiar with Tracktion engine. Hopefully someone else can provide some guidance here.
You’d just create a custom Plugin subclass and insert it at the end of the plugin chain. You can always hide it in your UI.
Then you’d grab the data in the process applyToBuffer using a FIFO or similar to pass it to the UI thread.
Gotcha. Thanks for your help @dave96. I assume this implies that I’d just cast the Plugin::Ptr returned by the PluginManager. This seems to work:
auto plugin = edit.getPluginCache().createNewPlugin(
MyPlugin::xmlTypeName,
{}
);
getTrack()->pluginList.insertPlugin(plugin, 0, nullptr);
auto plug = static_cast<MyPlugin*>(plugin.getObject());
plug->setFifo(...)
Yes, but you should use a dynamic_cast for up-casting as it’s safer.
