summaryrefslogtreecommitdiff
path: root/rotord/src
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src')
-rw-r--r--rotord/src/graph.cpp55
-rw-r--r--rotord/src/graph.h1
-rw-r--r--rotord/src/libavwrapper.h4
3 files changed, 59 insertions, 1 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp
index 29b46be..81f3275 100644
--- a/rotord/src/graph.cpp
+++ b/rotord/src/graph.cpp
@@ -173,6 +173,7 @@ bool Graph::video_render(const string &output_filename,const float framerate) {
a=new Audio_frame(audio,audioloader.get_number_channels(),samples_in_frame);
sample_start+=samples_in_frame;
}
+ else usingaudio=false;
}
@@ -666,7 +667,7 @@ bool Graph::parseXml(string media_path){
loaded=true;
return true;
}
-bool Graph::load_audio(const string &filename,vector<Audio_processor*> processors){
+bool Graph::_load_audio(const string &filename,vector<Audio_processor*> processors){
Logger& logger = Logger::get("Rotor");
logger.information("Analysing "+filename);
@@ -714,6 +715,58 @@ bool Graph::load_audio(const string &filename,vector<Audio_processor*> processor
logger.information("Finished audio analysis");
return true;
}
+bool Graph::load_audio(const string &filename,vector<Audio_processor*> processors){
+ Logger& logger = Logger::get("Rotor");
+ logger.information("Analysing "+filename);
+
+ libav::audio_decoder loader;
+ loader.open(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();
+
+ 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=((float)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");
+
+ return true;
+}
bool Graph::load_video(const string &nodeID,const string &filename){
//this is a good standard example of how to find
//a node of a specific type by ID and do something
diff --git a/rotord/src/graph.h b/rotord/src/graph.h
index 9207559..4df01bf 100644
--- a/rotord/src/graph.h
+++ b/rotord/src/graph.h
@@ -53,6 +53,7 @@ namespace Rotor {
bool check_audio(string audio,string path);
bool print_features(xmlIO &XML,string &node);
bool load_audio(const string &filename,vector<Audio_processor*> processors);
+ bool _load_audio(const string &filename,vector<Audio_processor*> processors);
bool load_video(const string &nodeID,const string &filename);//can be performance or clip
bool loaded;
float duration;
diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h
index 2f1f31e..4b24b02 100644
--- a/rotord/src/libavwrapper.h
+++ b/rotord/src/libavwrapper.h
@@ -252,6 +252,10 @@ namespace libav {
if (props) return props->Channels;
else return 0;
}
+ int get_number_samples(){
+ if (props) return props->NumSamples;
+ else return 0;
+ }
int64_t get_channel_layout(){
if (props) return props->ChannelLayout;
else return 0;