I read somewhere that Audacity doesn’t necessarily call a plugin only once for one marked section of sound, but divides the section into smaller chunks and runs the plugin on each chunk in turn. And the coder should consider this, when writing the code. I think this was true both for Nyquist and LADSPA. I write LANDSPA plugins.
I’m struggling with some code and I get strange results. It seems I can’t mark large sections of sound and run my effect. My effect seems ok up to about 500,000 samples from the beginning. Then there’s a strange cut, exactly as if the parmeters would have been reset. As if I had operated only on 500,000 samples, then marked the rest and operated on it. This screws up my effect totally.
Is there a passed parameter that I can read in my code that tells me that my plugin is called, not for samples 1 to 500,000 but for samples 500,001 to x?
I can’t tell if Nyquist and other plug-ins are comparable.
Direct sample access is done by a 1020 sample buffer size (in Nyquist).
You can e.g fetch 10000 samples and this results in 10 buffers of 1020 = 10200 samples that have to be read and stored in memory.
However, this behaviour becomes seldom visible because sounds are almost always copied in all nyquist commands and the object looks therefore continuous.
A 500000 samble limit seems rather strange.
The chunk size on the hard disk (project data folder) is 262144 samples at default 44100 Hz/32 bit.
I’ve moved this topic to the General Audio Programming section as it is not specifically about Nyquist plug-ins.
Audacity stores the audio data in “block files” (see here for an overview: http://manual.audacityteam.org/o/man/audacity_projects.html)
When processing an audio track, “blocks” are called sequentially. If your effect needs to carry data over from one sample value to the next (as is typical with filters and such like) then you need to ensure that the data survives from one block to the next.
Have a look at the code for the “Bass and Treble” effect. That is a fairly simple effect and it has to hold sample data over from one block to the next in the biquad filter code.
I have to look into that code. Btw, where is the source for Bass and treble? Meanwhile…
factor = 2. * M_PI * nofr / SampleCount; // calculate the angular increment for each sample
for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
alfa = factor * lSampleIndex; // calculate the angle for this loop
sinalfa = sin(alfa); // precalculate sin and cos, because they are used twice
cosalfa = cos(alfa);
l = *(pfInputL++); // fetch the samples, left and right
r = *(pfInputR++);
ltw = l*cosalfa - r*sinalfa; // twist the point (l, r) the
rtw = r*cosalfa + l*sinalfa;
*(pfOutputL++) = ltw; // place the twisted point as left
*(pfOutputR++) = rtw; // and right samples
This is the troublesome code. pfInputL and pfInputR are the arrays with the samples from a stereo track in Audacity. Either the whole track or a marked section, it should make no difference here. And pfOutputL and pfOutputR are the arrays that will replace the section. SampleCount should be the length of the section in samples. But it appears that somehow my pluginn is called three times instead of once. If I select a 30 second track and run my plugin, the reslut looks like if I had first marked 12 s and ran the plugin, then from 12 s to 25 s, and then from 25 s to the end. Here:
If Audacity (the LADSPA host) really calls my plugin in three turns (in this case), my code needs to know more than just the SampleCount and the in and out buffers. It needs to know the start position of the chunk. When the second chunk is processed, my plugin needs to know that the start position is at some 522,000 samples and not at 0. And my plugin needs the total length of my 30 second selection, not only the length of the chunk.
The source code for Audacity is available here: https://code.google.com/p/audacity/source/checkout
“Bass and Treble” is here: https://code.google.com/p/audacity/source/browse/audacity-src/trunk#trunk%2Fsrc%2Feffects
I don’t know how LADSPA plug-ins work, but I’d suggest looking at the LADSPA code in Audacity here: https://code.google.com/p/audacity/source/browse/audacity-src/trunk#trunk%2Fsrc%2Feffects%2Fladspa
We don’t see many programmers/developers on the forum very often, and I only have rudimentary understanding of C++, so if you get stuck it may be worth asking on the developer’s mailing list: http://audacityteam.org/contact/lists