diff options
Diffstat (limited to 'rotord/src/graph.h')
| -rw-r--r-- | rotord/src/graph.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/rotord/src/graph.h b/rotord/src/graph.h index 2f8843d..70a7e3a 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -144,6 +144,40 @@ namespace Rotor { return true; } } + //fall back to audio + libav::audio_decoder loader; + if (loader.open(inputfilename)) { + Audio_thumbnailer at; + at.width=w; + at.height=h; + int rate = loader.get_sample_rate(); + int samples = loader.get_number_samples(); + int channels= loader.get_number_channels(); + int bits = loader.get_bit_depth(); + at.init(channels,bits,samples,rate); + bool finished=false; + uint16_t *audio=new uint16_t[1024*loader.get_number_channels()]; + uint64_t sample=0; + while (loader.get_samples(audio,sample,1024)) { + at.process_frame((uint8_t*)audio,1024); + sample+=1024; + } + cv::Mat co=cv::Mat(h,w,CV_8UC3); + uchar op; + for (int i=0;i<h;i++){ + uchar* r=co.ptr(i); //pointer to row + for (int j=0;j<w;j++){ + //audio rms in 0..1 range + if (at.audiodata[j]>abs(((float)i-h/2)/(h/2))) op=0xFF; + else op=0x00; + r[j*3]=op/4; + r[j*3+1]=op; + r[j*3+2]=op/4; + } + } + cv::imwrite(outputfilename.c_str(),co); + return true; + } return false; } private: |
