From a880b4bc5e1a1c99fd1cc8928e671ceb9744dd58 Mon Sep 17 00:00:00 2001 From: Xavier Lizarraga Date: Wed, 2 Oct 2024 11:30:10 +0200 Subject: [PATCH 1/7] Initial implementation of a TempoCNN file extractor --- src/examples/standard_tempo_cnn.cpp | 94 +++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/examples/standard_tempo_cnn.cpp diff --git a/src/examples/standard_tempo_cnn.cpp b/src/examples/standard_tempo_cnn.cpp new file mode 100644 index 000000000..9b0b90538 --- /dev/null +++ b/src/examples/standard_tempo_cnn.cpp @@ -0,0 +1,94 @@ +/* + * 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 +#include +#include +#include +#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; + + AlgorithmFactory& factory = AlgorithmFactory::instance(); + + Algorithm* audioLoader = factory.create("MonoLoader", + "filename", audioFilename, + "sampleRate", sampleRate); + + Algorithm* tempoCNN = factory.create("TempoCNN", + "graphFilename", graphFilePath); + + // inputs and outputs + vector audio; + Real globalTempo; + vector localTempo; + vector 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(); + + // 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; +} From 2f2232b7252c0a0c1e6e9d8afe8676ab80d9dd4d Mon Sep 17 00:00:00 2001 From: Xavier Lizarraga Date: Wed, 2 Oct 2024 12:49:11 +0200 Subject: [PATCH 2/7] Define resample quality --- src/examples/standard_tempo_cnn.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/examples/standard_tempo_cnn.cpp b/src/examples/standard_tempo_cnn.cpp index 9b0b90538..23267ae93 100644 --- a/src/examples/standard_tempo_cnn.cpp +++ b/src/examples/standard_tempo_cnn.cpp @@ -48,12 +48,14 @@ int main(int argc, char* argv[]) { /////// PARAMS ////////////// Real sampleRate = 11025.0; + int resampleQuality = 4; AlgorithmFactory& factory = AlgorithmFactory::instance(); Algorithm* audioLoader = factory.create("MonoLoader", "filename", audioFilename, - "sampleRate", sampleRate); + "sampleRate", sampleRate, + "resampleQuality", resampleQuality); Algorithm* tempoCNN = factory.create("TempoCNN", "graphFilename", graphFilePath); From 2d168e71f8f7eb25bb2344763e575cbbf0479231 Mon Sep 17 00:00:00 2001 From: xaviliz Date: Fri, 4 Oct 2024 15:35:51 +0200 Subject: [PATCH 3/7] Small fix --- src/examples/standard_tempo_cnn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/standard_tempo_cnn.cpp b/src/examples/standard_tempo_cnn.cpp index 23267ae93..aeb11ae16 100644 --- a/src/examples/standard_tempo_cnn.cpp +++ b/src/examples/standard_tempo_cnn.cpp @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) { string outputFilename = argv[2]; // define graphFilePath - string graphFilePath = argv[3] + string graphFilePath = argv[3]; // register the algorithms in the factory(ies) essentia::init(); From 9a0e58e9ca5ace03f667be2db3042643ee4e736f Mon Sep 17 00:00:00 2001 From: xaviliz Date: Fri, 4 Oct 2024 15:36:14 +0200 Subject: [PATCH 4/7] List new file extractor --- src/examples/wscript | 1 + 1 file changed, 1 insertion(+) diff --git a/src/examples/wscript b/src/examples/wscript index 67c158bd9..0fc0ca2c8 100644 --- a/src/examples/wscript +++ b/src/examples/wscript @@ -43,6 +43,7 @@ example_sources_fileio = [ ('standard_loudnessebur128_double_input', ), ('standard_saturationdetector', ), ('standard_snr', ), + ('standard_tempo_cnn',), ('standard_welch', ), ('streaming_humdetector', ), From df01e730487e1718a3d8efefdf540c298132fe80 Mon Sep 17 00:00:00 2001 From: xaviliz Date: Mon, 21 Oct 2024 14:09:03 +0200 Subject: [PATCH 5/7] Add ouputs to Pool --- src/examples/standard_tempo_cnn.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/examples/standard_tempo_cnn.cpp b/src/examples/standard_tempo_cnn.cpp index aeb11ae16..0dad10834 100644 --- a/src/examples/standard_tempo_cnn.cpp +++ b/src/examples/standard_tempo_cnn.cpp @@ -76,6 +76,10 @@ int main(int argc, char* argv[]) { 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; From 949077adb41a1ca15b4fb1c7897b5375d3cd39b0 Mon Sep 17 00:00:00 2001 From: xaviliz Date: Wed, 23 Oct 2024 11:20:15 +0200 Subject: [PATCH 6/7] Rename the file to standard_tempocnn --- src/examples/{standard_tempo_cnn.cpp => standard_tempocnn.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/examples/{standard_tempo_cnn.cpp => standard_tempocnn.cpp} (100%) diff --git a/src/examples/standard_tempo_cnn.cpp b/src/examples/standard_tempocnn.cpp similarity index 100% rename from src/examples/standard_tempo_cnn.cpp rename to src/examples/standard_tempocnn.cpp From e997644ecdec77679f15ee6fa61300df36003c40 Mon Sep 17 00:00:00 2001 From: Xavi Lizarraga Date: Wed, 23 Oct 2024 12:37:55 +0200 Subject: [PATCH 7/7] Update example name in wscript --- src/examples/wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/wscript b/src/examples/wscript index 0fc0ca2c8..ce0b521a5 100644 --- a/src/examples/wscript +++ b/src/examples/wscript @@ -43,7 +43,7 @@ example_sources_fileio = [ ('standard_loudnessebur128_double_input', ), ('standard_saturationdetector', ), ('standard_snr', ), - ('standard_tempo_cnn',), + ('standard_tempocnn',), ('standard_welch', ), ('streaming_humdetector', ),