summaryrefslogtreecommitdiff
path: root/rotord/src/graph.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-09-16 15:03:56 +0100
committerTim Redfern <tim@eclectronics.org>2013-09-16 15:03:56 +0100
commit64046a1fb1f9254a485bac61752684b51afcb622 (patch)
tree5f043b2443f6b0dee0b4dcb3d19393f546430f66 /rotord/src/graph.cpp
parent440ba17594d17736a56cac0d89be97fb63577989 (diff)
ffmpegsource audio loading
Diffstat (limited to 'rotord/src/graph.cpp')
-rw-r--r--rotord/src/graph.cpp55
1 files changed, 54 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