VST audio plugin and .txt output file

2 views (last 30 days)
earmello
earmello on 13 Mar 2024
Edited: jibrahim on 15 Mar 2024
Hello,
I have written a VST plugin that processes input signals and would like to save the results of these calculations in a .txt file, but I don't understand how to do this.
Can anyone help me?
Thank you

Answers (1)

jibrahim
jibrahim on 14 Mar 2024
It is not clear from the question if you want this writing capability to be part of the plugin, or if it is something you want to run outside the plugin as part of a script for example. either way, refer to dsp.BinaryFIleWriter for real-time use case for writing data to binary files:
  2 Comments
earmello
earmello on 15 Mar 2024
What I want is for the writing capability to be part of the plugin. I also want to be able to choose from the plugin interface the destination and the name of the .txt file where the processing data is to be stored.
In the meantime, thank you for the information.
jibrahim
jibrahim on 15 Mar 2024
Edited: jibrahim on 15 Mar 2024
Here is the pattern to write results from within the plugin:
classdef myPlugin < audioPlugin
properties (Access = private)
fid
end
methods
function plugin = myPlugin
plugin.fid = fopen('results.bin','w');
end
function y = process(plugin,x)
y = x;
fwrite(plugin.fid,y,class(x));
end
end
end
Here is an example with the generated plugin:
generateAudioPlugin myPlugin
p = loadAudioPlugin("myPlugin.dll");
process(p,1.5*ones(1024,2));
% Read results
reader = dsp.BinaryFileReader('results.bin');
reader()
It is currently not possible to specify the desired output binary file name on the plugin interface.
Here is a workaround where you specify the desired output file name in a txt file. The plugin will use that name. to write data.
classdef myPlugin < audioPlugin
properties (Access = private)
fid
end
methods
function plugin = myPlugin
% Get the desired file name
fid0 = fopen('name.txt');
name = char(fread(fid0)).';
plugin.fid = fopen(name,'w');
end
function y = process(plugin,x)
y = x;
fwrite(plugin.fid,y,class(x));
end
end
end
For example:
First, set the string in name.txt to myresults.bin:
generateAudioPlugin myPlugin
p = loadAudioPlugin("myPlugin.dll");
p = loadAudioPlugin("myPlugin.dll");
process(p,1.5*ones(1e3,2));
reader = dsp.BinaryFileReader('myresults.bin','SamplesPerFrame',1000);
Now change the name in name.txt to myresults2.bin
p = loadAudioPlugin("myPlugin.dll");
process(p,pi*ones(1e3,2));
reader = dsp.BinaryFileReader('myresults2.bin','SamplesPerFrame',1000);
reader()
Notice that you only have to generate the plugin once, and can write to your desired location.

Sign in to comment.

Categories

Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!