diff options
Diffstat (limited to 'NT/src/graph.cpp')
| -rw-r--r-- | NT/src/graph.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp index 50db271..ad89061 100644 --- a/NT/src/graph.cpp +++ b/NT/src/graph.cpp @@ -18,6 +18,71 @@ bool Graph::check_audio(string audio,string path){ } return false; } +bool Graph::load_audio(const std::string &filename) { + Logger& logger = Logger::get(id); + if (filename.size()==0) { + logger.information("ERROR: empty filename for audio analysis"); + return false; + } + libav::audio_decoder loader; + if (!loader.open(filename)) { + logger.error("ERROR: Could not open audio: "+filename); + return false; + } + logger.information("Analysing "+filename); + + duration=loader.get_duration(); + + int rate = loader.get_sample_rate(); + int samples = loader.get_number_samples(); + int channels= loader.get_number_channels(); + int bits = loader.get_bit_depth(); + + vector<Audio_processor*> processors; + //processors.push_back(audio_thumb); + for (auto a: nodes) { + if (dynamic_cast<Audio_processor*>(a.second)){ + processors.push_back(dynamic_cast<Audio_processor*>(a.second)); + } + } + for (auto p: processors) { + if(!p->init(channels,bits,samples,rate) ){ + logger.error("ERROR: Audio plugin failed to initialse"); + return false; + } + } + + bool finished=false; + uint16_t *audio=new uint16_t[1024*loader.get_number_channels()]; + uint64_t sample=0; + + while (!finished&&!cancelled) + { + if (loader.get_samples(audio,sample,1024)) { + //now we can pass the data to the processor(s) + for (auto p: processors) { + p->process_frame((uint8_t*)audio,1024); + } + sample+=1024; + //mutex.lock(); + progress=((double)sample)/samples; //atomic on 64 bit? + //mutex.unlock(); + + } + else finished=true; + } + + loader.cleanup(); + + for (auto p: processors) { + p->cleanup(); + p->print_summary(); + } + + logger.information("Finished audio analysis"); + //audio_loaded=true; + return true; +} bool Graph::load_file(std::string filename,std::string media_path){ Logger& logger = Logger::get(id); Poco::File f=Poco::File(filename); |
