borg / ofxGist

openFrameworks implementation of GIST real-time sound analysis library
35 stars 5 forks source link

[question] it's posible multiple features onSet callbacks? #5

Open moebiussurfing opened 4 years ago

moebiussurfing commented 4 years ago

Hey @borg , I am looking at the example and trying to add onSet callbacks to more than one feature at the same time. I see on ofxGist.h and it looks like only one feature can be set to trig onSet/threshold detector.

Should I need to run more than one ofxGist instance to allow this? That could not be nice bc all the other features are analyzing too.

DO you think there's any alternative? like add more methods:

ofEvent <GistEvent> GistEvent::ON;
ofEvent <GistEvent> GistEvent::OFF;
moebiussurfing commented 4 years ago

ah ok. Now I see that you can subscribe to the onSet detector several Gist features using:

gist.setUseForOnsetDetection(GIST_SPECTRAL_DIFFERENCE, true);
gist.setUseForOnsetDetection(GIST_ZERO_CROSSING_RATE, true);
...
//or disable
gist.setUseForOnsetDetection(GIST_SPECTRAL_DIFFERENCE, false);

So, if don't misunderstand, you will receive (per one Gist instance) all the subscribed features together on the same callback:

ofAddListener(GistEvent::ON, this, &ofxSoundAnalyzer::onGistNoteOn);
ofAddListener(GistEvent::OFF, this, &ofxSoundAnalyzer::onGistNoteOff);

It's really enough like this... but any tip is appreciated.

Thanks a lot for the addon! it's working nice here!

borg commented 4 years ago

Hi @moebiussurfing. I missed any notification for this, so only just spotted this by chance.

I haven't used this addon for many years myself so my memory is a bit vague, but yes, first you need to turn on the analysis features you want to run. In the example I turn on all like so.

    vector<string> features = ofxGist::getFeatureNames();
    int num = features.size();
    for(int v = 0;v<num;v++){
        GIST_FEATURE f = ofxGist::getFeatureFromName(features[v]);
        gist.setDetect(f);
    }

If I remember correctly there are two types of features, one which is just continuous floats, and one which would trigger events with onsets. You can only use event listeners to the latter and the former you just read from the gist instance directly, like so

float v0 = gist.getValue(GIST_PEAK_ENERGY);

When it comes to running several instances, you mean to analyse different audio at the same time? I don't see why not...I mean you should be able to pipe different audio to different instances. But if you are referring to the same audio, I can't imagine that working, since the onset detection requires some kind of buffer, and that would get messed up.

I would refer to the original source though. https://github.com/adamstark/Gist

Also, feel free to update this library if Adam has made any more contributions. PR's welcome. (I started a develop branch, for that purpose, but not sure where I got to.)