LEAF icon indicating copy to clipboard operation
LEAF copied to clipboard

tDualPitchDetector Broken or Unclear

Open BOBONA opened this issue 1 year ago • 1 comments

This is a really neat library and I'm hoping to use the pitch detector algorithm. The regular tPitchDetector seems to work as expected (though I did find the API a bit confusing). I wanted to test tDualPitchDetector to see if it is more accurate, but it doesn't seem to work at all. I don't really understand how the algorithm works but it seems like tPeriodDetection is not finishing its work and returns a period of 0, which is a problem in this line Lfloat f1 = 1.0f / tPeriodDetection_getPeriod(&p->_pd1);

I'm assuming this is an issue in the way I'm using the algorithm, however my code does work fine when I use tPitchDetector:

LEAF leaf;
tDualPitchDetector pitchDetector;

const size_t memorySize = 50000;
char memory[memorySize];
LEAF_init(&leaf, float(sampleRate), memory, memorySize, []() -> float { return Random().nextFloat(); });
tDualPitchDetector_init(&pitchDetector, 50, 20000, &leaf);
for (int i = 0; i < numSamples; i++)
{
    bool ready = audioBuffer->getNumChannels() == 2 ? 
        tDualPitchDetector_tick(&pitchDetector, (audioBuffer->getSample(0, sampleStart + i) + audioBuffer->getSample(1, sampleStart + i)) / 2.f) :
        tDualPitchDetector_tick(&pitchDetector, audioBuffer->getSample(0, sampleStart + i));
    if (ready)
        break;
}
pitch = double(tDualPitchDetector_predictFrequency(&pitchDetector));
tDualPitchDetector_free(&pitchDetector);

BOBONA avatar Feb 19 '24 19:02 BOBONA

I’ll check this out, there may be something messed up about the dual pitch detector

Composer, musician, instrument designer scattershot.org * @snyderphonics

On Mon, Feb 19, 2024 at 2:05 PM Binyamin Friedman @.***> wrote:

This is a really neat library and I'm hoping to use the pitch detector algorithm. The regular tPitchDetector seems to work as expected (though I did find the API a bit confusing). I wanted to test tDualPitchDetector to see if it is more accurate, but it doesn't seem to work at all. I don't really understand how the algorithm works but it seems like tPeriodDetection is not finishing its work and returns a period of 0, which is a problem in this line Lfloat f1 = 1.0f / tPeriodDetection_getPeriod(&p->_pd1);

I'm assuming this is an issue in the way I'm using the algorithm, however my code does work fine when I use tPitchDetector:

LEAF leaf;tDualPitchDetector pitchDetector; const size_t memorySize = 50000;char memory[memorySize];LEAF_init(&leaf, float(sampleRate), memory, memorySize, -> float { return Random().nextFloat(); });tDualPitchDetector_init(&pitchDetector, 50, 20000, &leaf);for (int i = 0; i < numSamples; i++) { bool ready = audioBuffer->getNumChannels() == 2 ? tDualPitchDetector_tick(&pitchDetector, (audioBuffer->getSample(0, sampleStart + i) + audioBuffer->getSample(1, sampleStart + i)) / 2.f) : tDualPitchDetector_tick(&pitchDetector, audioBuffer->getSample(0, sampleStart + i)); if (ready) break; }pitch = double(tDualPitchDetector_predictFrequency(&pitchDetector));tDualPitchDetector_free(&pitchDetector);

— Reply to this email directly, view it on GitHub https://github.com/spiricom/LEAF/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGAY7GY4WVE32BRERPRCX3YUOO6FAVCNFSM6AAAAABDP6A5ZOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2DEOJYHEZDOOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

spiricom avatar Feb 19 '24 19:02 spiricom