summaryrefslogtreecommitdiff
path: root/rotord/rotor.h
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/rotor.h')
-rwxr-xr-xrotord/rotor.h70
1 files changed, 6 insertions, 64 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h
index de8e686..b7ffc25 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -336,11 +336,7 @@ namespace Rotor {
class base_audio_processor {
public:
virtual int process_frame(uint8_t *data,int samples)=0;
- void init(int _channels,int _bits,int _samples) {
- channels=_channels;
- bits=_bits;
- samples=_samples;
- };
+ virtual void init(int _channels,int _bits,int _samples)=0;
int channels,bits,samples;
};
class audio_thumbnailer: public base_audio_processor {
@@ -349,71 +345,17 @@ namespace Rotor {
//draw pixels based on rms value
public:
audio_thumbnailer(){
- height=64;
- width=128; //fit
+ height=16;
+ width=64; //fit
data=new uint8_t[height*width];
memset(data,0,height*width);
}
~audio_thumbnailer(){
delete[] data;
}
- void init(int _channels,int _bits,int _samples) {
- base_audio_processor::init(_channels,_bits,_samples);
- samples_per_column=samples/width;
- column=0; //point thumbnail bitmap
- out_sample=0; //sample in whole track
- offset=(int)(pow(2.0,bits)/2.0);
- scale=1.0/offset;
- }
- 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 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;
- }
- //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++;
- }
- 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;
- }
+ void init(int _channels,int _bits,int _samples);
+ int process_frame(uint8_t *data,int samples_in_frame);
+ string print();
uint8_t *data;
int height,width,samples_per_column;
int column,out_sample;