|
| 1 | +/* |
| 2 | + * Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra |
| 3 | + * |
| 4 | + * This file is part of Essentia |
| 5 | + * |
| 6 | + * Essentia is free software: you can redistribute it and/or modify it under |
| 7 | + * the terms of the GNU Affero General Public License as published by the Free |
| 8 | + * Software Foundation (FSF), either version 3 of the License, or (at your |
| 9 | + * option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 14 | + * details. |
| 15 | + * |
| 16 | + * You should have received a copy of the Affero GNU General Public License |
| 17 | + * version 3 along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | + */ |
| 19 | + |
| 20 | +#include <iostream> |
| 21 | +#include <fstream> |
| 22 | +#include <essentia/algorithmfactory.h> |
| 23 | +#include <essentia/pool.h> |
| 24 | +#include "credit_libav.h" |
| 25 | +using namespace std; |
| 26 | +using namespace essentia; |
| 27 | +using namespace standard; |
| 28 | + |
| 29 | +int main(int argc, char* argv[]) { |
| 30 | + |
| 31 | + if (argc != 4) { |
| 32 | + cout << "Error: incorrect number of arguments." << endl; |
| 33 | + cout << "Usage: " << argv[0] << " audio_input output_file graph_file" << endl; |
| 34 | + creditLibAV(); |
| 35 | + exit(1); |
| 36 | + } |
| 37 | + |
| 38 | + string audioFilename = argv[1]; |
| 39 | + string outputFilename = argv[2]; |
| 40 | + |
| 41 | + // define graphFilePath |
| 42 | + string graphFilePath = argv[3]; |
| 43 | + |
| 44 | + // register the algorithms in the factory(ies) |
| 45 | + essentia::init(); |
| 46 | + |
| 47 | + Pool pool; |
| 48 | + |
| 49 | + /////// PARAMS ////////////// |
| 50 | + Real sampleRate = 11025.0; |
| 51 | + int resampleQuality = 4; |
| 52 | + |
| 53 | + AlgorithmFactory& factory = AlgorithmFactory::instance(); |
| 54 | + |
| 55 | + Algorithm* audioLoader = factory.create("MonoLoader", |
| 56 | + "filename", audioFilename, |
| 57 | + "sampleRate", sampleRate, |
| 58 | + "resampleQuality", resampleQuality); |
| 59 | + |
| 60 | + Algorithm* tempoCNN = factory.create("TempoCNN", |
| 61 | + "graphFilename", graphFilePath); |
| 62 | + |
| 63 | + // inputs and outputs |
| 64 | + vector<Real> audio; |
| 65 | + Real globalTempo; |
| 66 | + vector<Real> localTempo; |
| 67 | + vector<Real> localTempoProbabilities; |
| 68 | + |
| 69 | + // process |
| 70 | + audioLoader->output("audio").set(audio); |
| 71 | + audioLoader->compute(); |
| 72 | + |
| 73 | + tempoCNN->input("audio").set(audio); |
| 74 | + tempoCNN->output("globalTempo").set(globalTempo); |
| 75 | + tempoCNN->output("localTempo").set(localTempo); |
| 76 | + tempoCNN->output("localTempoProbabilities").set(localTempoProbabilities); |
| 77 | + tempoCNN->compute(); |
| 78 | + |
| 79 | + pool.add("tempoCNN.global_tempo", globalTempo); |
| 80 | + pool.add("tempoCNN.localTempo", localTempo); |
| 81 | + pool.add("tempoCNN.localTempoProbabilities", localTempoProbabilities); |
| 82 | + |
| 83 | + // output results |
| 84 | + cout << "------------- writing results to file " << outputFilename << " -------------" << endl; |
| 85 | + |
| 86 | + Algorithm* json = factory.create("YamlOutput", |
| 87 | + "filename", outputFilename, |
| 88 | + "format", "json"); |
| 89 | + json->input("pool").set(pool); |
| 90 | + json->compute(); |
| 91 | + |
| 92 | + // cleanup |
| 93 | + delete audioLoader; |
| 94 | + delete tempoCNN; |
| 95 | + delete json; |
| 96 | + |
| 97 | + essentia::shutdown(); |
| 98 | + |
| 99 | + return 0; |
| 100 | +} |
0 commit comments