diff options
Diffstat (limited to 'rotord/rotor.h')
| -rwxr-xr-x | rotord/rotor.h | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h index e16520b..de8e686 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -335,7 +335,7 @@ namespace Rotor { }; class base_audio_processor { public: - virtual bool process_frame(uint8_t *data,int samples)=0; + virtual int process_frame(uint8_t *data,int samples)=0; void init(int _channels,int _bits,int _samples) { channels=_channels; bits=_bits; @@ -350,7 +350,7 @@ namespace Rotor { public: audio_thumbnailer(){ height=64; - width=512; + width=128; //fit data=new uint8_t[height*width]; memset(data,0,height*width); } @@ -360,39 +360,66 @@ namespace Rotor { void init(int _channels,int _bits,int _samples) { base_audio_processor::init(_channels,_bits,_samples); samples_per_column=samples/width; - stored_data=new uint8_t[samples_per_column*channels*(bits>>3)]; - sample=0; + column=0; //point thumbnail bitmap + out_sample=0; //sample in whole track + offset=(int)(pow(2.0,bits)/2.0); + scale=1.0/offset; } - bool process_frame(uint8_t *data,int samples_in_frame){ + int process_frame(uint8_t *data,int samples_in_frame){ //begin by processing remaining samples //samples per column could be larger than a frame! (probably is) //but all we are doing is averaging int bytes=(bits>>3); int stride=channels*bytes; - int next_sample=0; - uint64_t accum; - while (next_sample<samples_in_frame) { - while (sample<samples_in_column&&next_sample<samples_in_frame) { - //do the accumulation + int in_sample=0; + while (in_sample<samples_in_frame&&column<width) { + int sample=0; + int samples=0; + double accum=0; + while (sample<samples_per_column&&in_sample<samples_in_frame) { + //accumulate squares for this column for (int i=0;i<channels;i++) { int this_val=0; for (int j=0;j<bytes;j++) { this_val+=data[(sample*stride)+(i*bytes)+j]<<j; } - accum+=this_val*this_val; - next_sample++; - sample++; - } + //convert from integer data format - i.e s16p - to audio signal in -1..1 range + //don't know how many bytes we are dealing with necessarily? + double val=(this_val-offset)*scale; + accum+=val*val; + samples++; } - } do; - - } do; - return true; + in_sample++; + sample++; + out_sample++; + } + //get root-mean + double mean=pow(accum/samples,0.5); + int colheight=height*mean*0.5; + int hh=height>>1; + for (int i=0;i<height;i++) { + data[i*width+column]=abs(i-hh)<colheight?0xff:0x00; + } + column++; + } + return out_sample; + } + string print(){ + string output; + for (int j=0;j<height;j++) { + for (int i=0;i<width;i++) { + output+=data[j*width+i]<0x7f?"0":"1"; + } + output +="\n"; + } + return output; } uint8_t *data; - uint8_t *stored_data; int height,width,samples_per_column; - int sample; + int column,out_sample; + //for drawing graph + int offset; + double scale; }; class Render_context: public Poco::Task { //Poco task object //manages a 'patchbay' @@ -400,7 +427,8 @@ namespace Rotor { //and low level interface onto the graph public: Render_context(const std::string& name): Task(name) { - state=IDLE; + audio_thumb=new audio_thumbnailer(); + state=IDLE; }; void runTask(); void add_queue(int item); @@ -417,11 +445,12 @@ namespace Rotor { private: int state; - float progress; //for a locking process: audio analysis or rendering + double progress; //for a locking process: audio analysis or rendering //thread only does one thing at once std::deque<int> work_queue; Poco::Mutex mutex; //lock for access from parent thread std::string audio_filename; + audio_thumbnailer *audio_thumb; vampHost::QMAnalyser audio_analyser; xmlIO xml; Graph graph; @@ -431,6 +460,6 @@ namespace Rotor { /* coding style -Types begin with a capital, use underscore as a seperator -instances begin with a small letter +Types begin with capitals 'CamelCase' +variables/ instances use lower case with underscore as a seperator */ |
