MTG / essentia

C++ library for audio and music analysis, description and synthesis, including Python bindings
http://essentia.upf.edu
GNU Affero General Public License v3.0
2.81k stars 525 forks source link

RingBufferInput / RingBufferOutput cannot be created with AlgorithmFactory #641

Open giuliomoro opened 7 years ago

giuliomoro commented 7 years ago

This is because of the following:

a) They are missing the description field.

b) they are not registered, so you have to manually call

        essentia::streaming::AlgorithmFactory::Registrar<essentia::streaming::RingBufferOutput> regRingBufferOutput;

and

        essentia::streaming::AlgorithmFactory::Registrar<essentia::streaming::RingBufferInput> regRingBufferInput;

a) is the real issue, while b) can be worked-around by the user, though it would be nice to fix b) as well.

giuliomoro commented 7 years ago

Also note that my current build does not build src/examples/streaming_ringbuffertofile.cpp but I believe the file would fail at compile time because of

   StreamingAlgorithm* ringBufferInput = streaming::AlgorithmFactory::create("RingBufferInput");
   StreamingAlgorithm* ringBufferOutput = streaming::AlgorithmFactory::create("RingBufferOutput");
carthach commented 6 years ago

Just include those RingBuffer headers explicitly like we do here:-

https://github.com/GiantSteps/MC-Sonaar/blob/master/essentiaRT~/EssentiaOnset.h

giuliomoro commented 6 years ago

Thanks, what should that fix? When including those headers I see no change in issues a) and b) described above (and I would not expect any). Note that I fixed a) here https://github.com/MTG/essentia/pull/642

dbogdanov commented 6 years ago

Any specific reason you want to instantiate them using AlgorithmFactory?

They are "special" algorithm just like "DevNull" or "VectorInput" and others. They were deliberately put in src/essentia/streaming/algorithms at some point in time. These algorithms form a core part of Essentia streaming C++ API and they aren't included in Python bindings.

giuliomoro commented 6 years ago

I could not make much sense of the documentation and the two examples I found which were using RingBuffer were not compiling:

So I had to find my own way through, which involved the above patch and so I could do

        essentia::streaming::AlgorithmFactory::Registrar<essentia::streaming::RingBufferInput> regRingBufferInput;
        ringBufferInput = dynamic_cast<RingBufferInput*>(factory.create("RingBufferInput", "bufferSize", 16384));

instead of

        ParameterMap pars;
        pars.add("bufferSize", 16384);

        ringBufferInput = new RingBufferInput();
        ringBufferInput->declareParameters();
        ringBufferInput->setParameters(pars);
        ringBufferInput->configure();

I felt that the latter solution was less elegant and more error-prone than the former.