Hi,
I’m writing my first SC plugin and I’m having some trouble. It’s using a new pitch detector which takes audio samples, pre-processes them (lpf, hpf and compression) and then passes these to the pitch tracker.
I wrote a version which used audio rate (BitstreamAutocorrelation.ar
) and it didn’t seem to work unless I called .poll
on the output. I have no idea why this should be:
# didn't work - crunchy output
SinOsc.ar(A2K.kr(BitstreamAutocorrelation.ar(PlayBuf.ar(1, b, rate, loop:1))));
# did work
SinOsc.ar(A2K.kr(BitstreamAutocorrelation.ar(PlayBuf.ar(1, b, rate, loop:1)).poll));
I’ve been trying to convert it to use control rate instead, but maintaining a full resolution audio input. I used the code from the Amplitude.kr
UGen as a starting point but nothing seems to work. The full code is as follows:
BitstreamAutocorrelation::BitstreamAutocorrelation() :
m_pd(std::make_shared<cycfi::q::pitch_detector>(60_Hz, 600_Hz, sampleRate(), -45_dB)),
m_pp(std::make_shared<cycfi::q::pd_preprocessor>(cfg, 60_Hz, 600_Hz, sampleRate()))
{
m_pp = std::make_shared<cycfi::q::pd_preprocessor>(cfg, 60_Hz, 600_Hz, sampleRate());
m_pd = std::make_shared<cycfi::q::pitch_detector>(60_Hz, 600_Hz, sampleRate(), -45_dB);
mCalcFunc = make_calc_function<BitstreamAutocorrelation, &BitstreamAutocorrelation::next>();
m_frequency = 0.0f;
next(1);
}
void BitstreamAutocorrelation::next(int nSamples) {
auto unit = this;
const float* input = in(0);
for(int i = 0; i < FULLBUFLENGTH; i++) {
float s = m_pp->operator()(input[i]);
bool is_ready = m_pd->operator()(s);
if (is_ready) {
m_frequency = m_pd->get_frequency();
}
}
ZOUT0(0) = std::abs(m_frequency);
}
I’m expecting here that all the audio samples from the input will get processed from each block, and then that the control rate output should be “last frequency wins” which gets output once for each control block. Something seems to be different about the iteration when changing the UGen definition to 'control'
.
Apologies for the long post - any help would be gratefully appreciated!