Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tempo cnn extractor #1445

Merged
merged 7 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/examples/standard_tempocnn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
*
* This file is part of Essentia
*
* Essentia is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation (FSF), either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the Affero GNU General Public License
* version 3 along with this program. If not, see http://www.gnu.org/licenses/
*/

#include <iostream>
#include <fstream>
#include <essentia/algorithmfactory.h>
#include <essentia/pool.h>
#include "credit_libav.h"
using namespace std;
using namespace essentia;
using namespace standard;

int main(int argc, char* argv[]) {

if (argc != 4) {
cout << "Error: incorrect number of arguments." << endl;
cout << "Usage: " << argv[0] << " audio_input output_file graph_file" << endl;
creditLibAV();
exit(1);
}

string audioFilename = argv[1];
string outputFilename = argv[2];

// define graphFilePath
string graphFilePath = argv[3];

// register the algorithms in the factory(ies)
essentia::init();

Pool pool;

/////// PARAMS //////////////
Real sampleRate = 11025.0;
int resampleQuality = 4;

AlgorithmFactory& factory = AlgorithmFactory::instance();

Algorithm* audioLoader = factory.create("MonoLoader",
"filename", audioFilename,
"sampleRate", sampleRate,
"resampleQuality", resampleQuality);

Algorithm* tempoCNN = factory.create("TempoCNN",
"graphFilename", graphFilePath);

// inputs and outputs
vector<Real> audio;
Real globalTempo;
vector<Real> localTempo;
vector<Real> localTempoProbabilities;

// process
audioLoader->output("audio").set(audio);
audioLoader->compute();

tempoCNN->input("audio").set(audio);
tempoCNN->output("globalTempo").set(globalTempo);
tempoCNN->output("localTempo").set(localTempo);
tempoCNN->output("localTempoProbabilities").set(localTempoProbabilities);
tempoCNN->compute();

pool.add("tempoCNN.global_tempo", globalTempo);
pool.add("tempoCNN.localTempo", localTempo);
pool.add("tempoCNN.localTempoProbabilities", localTempoProbabilities);

// output results
cout << "------------- writing results to file " << outputFilename << " -------------" << endl;

Algorithm* json = factory.create("YamlOutput",
"filename", outputFilename,
"format", "json");
json->input("pool").set(pool);
json->compute();

// cleanup
delete audioLoader;
delete tempoCNN;
delete json;

essentia::shutdown();

return 0;
}
1 change: 1 addition & 0 deletions src/examples/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ example_sources_fileio = [
('standard_loudnessebur128_double_input', ),
('standard_saturationdetector', ),
('standard_snr', ),
('standard_tempocnn',),
('standard_welch', ),
('streaming_humdetector', ),

Expand Down
Loading