From 1d05d2380bb4f1fd265aef55744f432af38b08aa Mon Sep 17 00:00:00 2001 From: Comment Date: Sun, 8 Dec 2013 10:55:03 +0000 Subject: switched signals to double and random to uint16 --- rotord/src/rotor.h | 218 ++++++++++++++++++++++++++--------------------------- 1 file changed, 109 insertions(+), 109 deletions(-) (limited to 'rotord/src/rotor.h') diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index e00ebd6..0013313 100644 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -162,16 +162,16 @@ namespace Rotor { class Time_spec{ public: Time_spec(){}; - Time_spec(float _time,float _framerate,float _duration,Audio_frame *_audio=nullptr){ time=_time; framerate=_framerate; duration=_duration; audio=_audio;}; - float time; //num/denom ? - float framerate; - float duration; + Time_spec(double _time,double _framerate,double _duration,Audio_frame *_audio=nullptr){ time=_time; framerate=_framerate; duration=_duration; audio=_audio;}; + double time; //num/denom ? + double framerate; + double duration; Audio_frame *audio; Time_spec lastframe() const{ - return Time_spec(time-(1.0f/framerate),framerate,duration); + return Time_spec(time-(1.0/framerate),framerate,duration); } Time_spec nextframe() const{ - return Time_spec(time+(1.0f/framerate),framerate,duration); + return Time_spec(time+(1.0/framerate),framerate,duration); } int frame(){ return (int)((time*framerate)+0.5); //rounded to the nearest frame @@ -179,16 +179,16 @@ namespace Rotor { }; class Frame_spec: public Time_spec{ public: - Frame_spec(float _time,float _framerate,float _duration,int _w,int _h,Audio_frame *_audio=nullptr) + Frame_spec(double _time,double _framerate,double _duration,int _w,int _h,Audio_frame *_audio=nullptr) { time=_time; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; - Frame_spec(int _frame,float _framerate,float _duration,int _w,int _h,Audio_frame *_audio=nullptr) - { time=((float)_frame)/_framerate; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; + Frame_spec(int _frame,double _framerate,double _duration,int _w,int _h,Audio_frame *_audio=nullptr) + { time=((double)_frame)/_framerate; framerate=_framerate; duration=_duration; w=_w; h=_h;audio=_audio;}; int h,w; Frame_spec lastframe() const{ - return Frame_spec(time-(1.0f/framerate),framerate,duration,w,h); + return Frame_spec(time-(1.0/framerate),framerate,duration,w,h); } Frame_spec nextframe() const{ - return Frame_spec(time+(1.0f/framerate),framerate,duration,w,h); + return Frame_spec(time+(1.0/framerate),framerate,duration,w,h); } }; class Colour{ @@ -206,14 +206,14 @@ namespace Rotor { g=(uint8_t)hexToChar(s.substr(2,2)); b=(uint8_t)hexToChar(s.substr(4,2)); } - float Rfloat(){ - return ((float)r)/255.0f; + double Rdouble(){ + return ((double)r)/255.0; } - float Gfloat(){ - return ((float)g)/255.0f; + double Gdouble(){ + return ((double)g)/255.0; } - float Bfloat(){ - return ((float)b)/255.0f; + double Bdouble(){ + return ((double)b)/255.0; } uint8_t r,g,b; }; @@ -229,8 +229,8 @@ namespace Rotor { Node* connection; string description; string title; - virtual float get_time_used()=0; - virtual float get_time_taken()=0; + virtual double get_time_used()=0; + virtual double get_time_taken()=0; }; class Image_input: public Input{ public: @@ -240,8 +240,8 @@ namespace Rotor { connect(_connect); }; Image* get(const Frame_spec& time); - float get_time_used(); - float get_time_taken(); + double get_time_used(); + double get_time_taken(); }; class Signal_input: public Input{ public: @@ -250,19 +250,19 @@ namespace Rotor { Signal_input(const string &_desc,const string &_title,Node* _connect): Input(_desc,_title){ connect(_connect); }; - float get(const Time_spec& time); - float get_time_used(); - float get_time_taken(); + double get(const Time_spec& time); + double get_time_used(); + double get_time_taken(); }; class Parameter: public Signal_input{ public: virtual ~Parameter(){}; - void init(const float &_val){ + void init(const double &_val){ value=_val; } - Parameter(const string &_type,const string &_desc,const string &_title,float _value,float _min,float _max,float _step,Node* _connect): Signal_input(_desc,_title,_connect),value(_value),min(_min),max(_max),step(_step),type(_type){}; - float value,min,max,step; - float get(const Time_spec& time); + Parameter(const string &_type,const string &_desc,const string &_title,double _value,double _min,double _max,double _step,Node* _connect): Signal_input(_desc,_title,_connect),value(_value),min(_min),max(_max),step(_step),type(_type){}; + double value,min,max,step; + double get(const Time_spec& time); string type; }; /* @@ -316,12 +316,12 @@ namespace Rotor { type="lyrics"; blank_response=""; }; - void init(const std::map > _lyrics){ + void init(const std::map > _lyrics){ lyrics=_lyrics; for (auto l:lyrics){ cerr< > lyrics; //lyrics[startime]=pair + std::map > lyrics; //lyrics[startime]=pair std::string blank_response; }; class Node{ @@ -351,7 +351,7 @@ namespace Rotor { void create_signal_input(const string &_desc,const string &_title,Node* _connect=nullptr ) { inputs.push_back(new Signal_input(_desc,_title,_connect)); }; - void create_parameter(const string &_name,const string &_type,const string &_desc,const string &_title,float _value=1.0f,float _min=0.0f,float _max=0.0f,float _step=0.0f,Node* _connect=nullptr) { + void create_parameter(const string &_name,const string &_type,const string &_desc,const string &_title,double _value=1.0,double _min=0.0,double _max=0.0,double _step=0.0,Node* _connect=nullptr) { parameters[_name]=new Parameter(_type,_desc,_title,_value,_min,_max,_step,_connect); }; void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={},std::string _type="string") { @@ -382,7 +382,7 @@ namespace Rotor { string UItype; bool duplicate_inputs; string find_setting(map &settings,string key,string def=""){ if (settings.find(key)!=settings.end()) return settings[key]; else return def;}; - float find_setting(map &settings,string key,float def){ if (settings.find(key)!=settings.end()) return toFloat(settings[key]); else return def;}; + double find_setting(map &settings,string key,double def){ if (settings.find(key)!=settings.end()) return toFloat(settings[key]); else return def;}; int find_setting(map &settings,string key,int def){ if (settings.find(key)!=settings.end()) return toInt(settings[key]); else return def;}; void base_settings(map &settings) { description=find_setting(settings,"description"); @@ -397,8 +397,8 @@ namespace Rotor { } for (auto p: parameters){ if (find_setting(settings,p.first,"")!="") { - parameters[p.first]->init(find_setting(settings,p.first,0.0f)); - cerr<<"setting parameter '"<init(find_setting(settings,p.first,0.0)); + cerr<<"setting parameter '"<value=toFloat(value); }; void reset(){ - time_taken=0.0f; + time_taken=0.0; int(); } void time_frame(){ @@ -420,26 +420,26 @@ namespace Rotor { gettimeofday(&end_time, NULL); time_taken+=((end_time.tv_sec-frame_time.tv_sec) + (end_time.tv_usec-frame_time.tv_usec)/1000000.0); } - virtual float get_time_used()=0; - float time_taken; + virtual double get_time_used()=0; + double time_taken; protected: struct timeval frame_time; }; class Signal_node: public Node{ public: virtual ~Signal_node(){}; - const float get_output(const Time_spec &time) { + const double get_output(const Time_spec &time) { update(time); - float o=output(time); + double o=output(time); time_frame(); return o; }; - const float get_time_for_value(const float &value) { - return 0.0f; + const double get_time_for_value(const double &value) { + return 0.0; }; - virtual const float output(const Time_spec &time) { return 0.0f; }; - float get_time_used(){ - float t=time_taken; + virtual const double output(const Time_spec &time) { return 0.0; }; + double get_time_used(){ + double t=time_taken; for (auto i:inputs) t-=i->get_time_taken(); for (auto p:parameters) t-=p.second->get_time_taken(); return t; @@ -467,8 +467,8 @@ namespace Rotor { image.clear(); } Image image; - float get_time_used(){ - float t=time_taken; + double get_time_used(){ + double t=time_taken; for (auto i:inputs) t-=i->get_time_taken(); for (auto p:parameters) t-=p.second->get_time_taken(); for (auto i:image_inputs) t-=i->get_time_taken(); @@ -476,7 +476,7 @@ namespace Rotor { } private: - float image_time; //? could be used to detect image reuse? + double image_time; //? could be used to detect image reuse? }; class LUT { @@ -484,13 +484,13 @@ namespace Rotor { lut=nullptr; }; ~LUT(){if (lut) { delete[] lut;} }; - void generate(float black_in,float white_in,float black_out,float white_out,float gamma){ + void generate(double black_in,double white_in,double black_out,double white_out,double gamma){ //can check here if anything has changed if (lut) delete[] lut; lut=new unsigned char[256]; - float fltmax=(255.0f/256.0f); + double fltmax=(255.0/256.0); for (int i=0;i<256;i++){ - lut[i]=(unsigned char)(((pow(min(fltmax,max(0.0f,(((((float)i)/256.0f)-black_in)/(white_in-black_in)))),(1.0/gamma))*(white_out-black_out))+black_out)*255.0f); + lut[i]=(unsigned char)(((pow(min(fltmax,max((double)0.0,(((((double)i)/256.0)-black_in)/(white_in-black_in)))),(1.0/gamma))*(white_out-black_out))+black_out)*255.0); } } void apply(const cv::Mat& in,cv::Mat &out){ //facility to apply to other images for inherited classes @@ -551,7 +551,7 @@ namespace Rotor { create_attribute("mode","Cycling mode","Mode","cut",{"cut","mix","screen","multiply","alpha","wrap","xor","overlay","min","max"}); create_attribute("length_mode","Transition length mode","Length mode","fraction",{"seconds","fraction"}); create_attribute("time_mode","Time mode","time mode","absolute",{"absolute","relative"}); - create_parameter("transition_length","number","transition length","Transition length",1.0f,0.0f,0.0f); + create_parameter("transition_length","number","transition length","Transition length",1.0,0.0,0.0); title="Video cycler"; description="Cycles through video inputs according to selector signal"; duplicate_inputs=true; @@ -564,15 +564,15 @@ namespace Rotor { bool load(const string &filename); void init(){ segment=0; - segment_start=0.0f; - prevseg_start=0.0f; + segment_start=0.0; + prevseg_start=0.0; lastframe=0; } Image *output(const Frame_spec &frame){ //work out timing //can this be a general purpose function of node - float ph=inputs[0]->get((Time_spec)frame); + double ph=inputs[0]->get((Time_spec)frame); int seg=((int)ph); int thisframe=((Time_spec)frame).frame(); if(thisframe==lastframe||thisframe==lastframe+1){ @@ -594,7 +594,7 @@ namespace Rotor { } else { if (thisframe==0){ - segment_start=0.0f; + segment_start=0.0; segment=seg; } else { @@ -625,12 +625,12 @@ namespace Rotor { } } lastframe=thisframe; - //float start_time=(((Time_spec)frame).time-segment_start); - //float end_time=(((Time_spec)frame).time-segment_end); + //double start_time=(((Time_spec)frame).time-segment_start); + //double end_time=(((Time_spec)frame).time-segment_end); - float in_time=(((Time_spec)frame).time-segment_start); + double in_time=(((Time_spec)frame).time-segment_start); //time in seconds for the incoming sequence: starts at 0 - float out_time=(((Time_spec)frame).time-prevseg_start); + double out_time=(((Time_spec)frame).time-prevseg_start); //time in seconds for the outgoing sequence: //starts at how many seconds the outgoing has got to //so we need the previous segmente duration @@ -660,29 +660,29 @@ namespace Rotor { int im1=seg%image_inputs.size(); int im2=prevseg%image_inputs.size(); - float f; + double f; switch (attributes["length_mode"]->intVal){ case CYCLER_seconds: - f=min(1.0f,in_time/parameters["transition_length"]->value); + f=min(1.0,in_time/parameters["transition_length"]->value); break; case CYCLER_fraction: - f=min(1.0f,(in_time/(segment_end-segment_start))/parameters["transition_length"]->value); + f=min(1.0,(in_time/(segment_end-segment_start))/parameters["transition_length"]->value); break; } - //cerr<get(attributes["time_mode"]->intVal==CYCLER_abs?frame:inframe); if (in1){ - if (f<1.0f) { + if (f<1.0) { Image *in2=image_inputs[im2]->get(attributes["time_mode"]->intVal==CYCLER_abs?frame:outframe); if (in2){ image=(*in1); image*=f; Image i2=(*in2); - i2*=(1.0f-f); + i2*=(1.0-f); switch(attributes["mode"]->intVal){ case CYCLER_screen: image+=i2; @@ -730,8 +730,8 @@ namespace Rotor { } Video_cycler* clone(map &_settings) { return new Video_cycler(_settings);}; private: - float segment_start,segment_end; - float prevseg_start; + double segment_start,segment_end; + double prevseg_start; int segment,prevseg; int lastframe; }; @@ -743,11 +743,11 @@ namespace Rotor { public: Base_video(){ create_signal_input("playhead","Playhead"); - //floating point control of playback time + //doubleing point control of playback time //if signal is connected it overrides normal playback //time_mode dictates whether control is seconds, or duration - create_parameter("speed","number","video playback speed","Speed",1.0f,0.0f,0.0f); - create_parameter("framerate","number","framerate override","Frame rate",0.0f,0.0f,0.0f); + create_parameter("speed","number","video playback speed","Speed",1.0,0.0,0.0); + create_parameter("framerate","number","framerate override","Frame rate",0.0,0.0,0.0); create_attribute("frame_mode","frame mode","Frame mode","frame",{"frame","blend"}); create_attribute("time_mode","time mode","Time mode","play",{"play","stretch"}); create_attribute("media_id","media_id","media_id","media_id"); //for rotorW @@ -769,7 +769,7 @@ namespace Rotor { logger.error("libav::decoder failed to load "+filename); return false; } - bool get_frame(float wanted,const Frame_spec &frame){ + bool get_frame(double wanted,const Frame_spec &frame){ if (attributes["frame_mode"]->intVal==VIDEOFRAMES_blend){ if (((int)wanted)!=Base_video::lastframe){ //get a new pair of frames possibly by switching the next one @@ -788,13 +788,13 @@ namespace Rotor { in2=temp; lastframe=wanted; } - float amt=1.0f-(wanted-((int)wanted)); + double amt=1.0-(wanted-((int)wanted)); //cout<<"video loader time:"<value==0.0f?player.get_framerate():parameters["framerate"]->value); - float clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value; - float wanted=0.0f; + double clipframerate=(parameters["framerate"]->value==0.0?player.get_framerate():parameters["framerate"]->value); + double clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value; + double wanted=0.0; if (inputs[0]->connection) { //using playhead //should speed affect it? //if you want absolute control then you just want absolute control? switch (attributes["frame_mode"]->intVal){ case VIDEOTIME_play: - wanted=fmod(inputs[0]->get((Time_spec)frame)*frame.framerate*clipspeed,(float)player.get_number_frames()); + wanted=fmod(inputs[0]->get((Time_spec)frame)*frame.framerate*clipspeed,(double)player.get_number_frames()); break; case VIDEOTIME_stretch: - wanted=fmod(fmod(inputs[0]->get((Time_spec)frame),1.0f)*((float)player.get_number_frames())*clipspeed,(float)player.get_number_frames()); + wanted=fmod(fmod(inputs[0]->get((Time_spec)frame),1.0)*((double)player.get_number_frames())*clipspeed,(double)player.get_number_frames()); break; } } else { switch (attributes["frame_mode"]->intVal){ case VIDEOTIME_play: - wanted=fmod(frame.time*frame.framerate*clipspeed,(float)player.get_number_frames()); + wanted=fmod(frame.time*frame.framerate*clipspeed,(double)player.get_number_frames()); break; case VIDEOTIME_stretch: - wanted=fmod((frame.time/frame.duration)*((float)player.get_number_frames())*clipspeed,(float)player.get_number_frames()); + wanted=fmod((frame.time/frame.duration)*((double)player.get_number_frames())*clipspeed,(double)player.get_number_frames()); break; } } @@ -898,7 +898,7 @@ namespace Rotor { clip_loaded=-1; isLoaded=false; segment=0; - segment_start=0.0f; + segment_start=0.0; lastframe=0; }; Video_bank(map &settings): Video_bank() { @@ -924,7 +924,7 @@ namespace Rotor { logger.error("libav::decoder failed to load "+filename); return false; } - bool get_frame(float wanted,const Frame_spec &frame){ + bool get_frame(double wanted,const Frame_spec &frame){ if (attributes["frame_mode"]->intVal==VIDEOFRAMES_blend){ if (((int)wanted)!=Base_video::lastframe){ //get a new pair of frames possibly by switching the next one @@ -943,13 +943,13 @@ namespace Rotor { in2=temp; lastframe=wanted; } - float amt=1.0f-(wanted-((int)wanted)); + double amt=1.0-(wanted-((int)wanted)); //cout<<"video loader time:"<vals.size()){ - float ph=inputs[0]->get((Time_spec)frame); + double ph=inputs[0]->get((Time_spec)frame); int seg=((int)ph); int wv=seg%attributes["filenames"]->vals.size(); players.resize(attributes["filenames"]->vals.size()); @@ -998,10 +998,10 @@ namespace Rotor { //} } if (isLoaded){ - int wanted=0.0f; + int wanted=0.0; int thisframe=((Time_spec)frame).frame(); - float clipframerate=(parameters["framerate"]->value==0.0f?players[clip_loaded].get_framerate():parameters["framerate"]->value); - float clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value; + double clipframerate=(parameters["framerate"]->value==0.0?players[clip_loaded].get_framerate():parameters["framerate"]->value); + double clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value; switch (attributes["time_mode"]->intVal){ case VIDEOTIME_play: if(thisframe==lastframe||thisframe==lastframe+1){ @@ -1014,7 +1014,7 @@ namespace Rotor { } else { if (thisframe==0){ - segment_start=0.0f; + segment_start=0.0; segment=seg; } else { @@ -1045,7 +1045,7 @@ namespace Rotor { private: vector players; int clip_loaded; - float segment_start; + double segment_start; int segment; int lastframe; }; @@ -1058,7 +1058,7 @@ namespace Rotor { create_attribute("end_mode","mode to end movie","End mode","cut",{"cut","blank silence","fade peak"}); title="Video output"; description="Output to video"; - start_silence=start_peak=end_silence=end_peak=-1.0f; + start_silence=start_peak=end_silence=end_peak=-1.0; silence_threshold=0.01f; NODEID="693d2220-2d0a-11e3-9312-232908c3cc33"; }; @@ -1066,18 +1066,18 @@ namespace Rotor { base_settings(settings); }; ~Video_output(){ }; - void create_envelope(const vector &audio){ + void create_envelope(const vector &audio){ if (audio.size()){ uint32_t i=1; while (iaudio[i-1]) i++; - start_peak=((float)i-1)/audio.size(); + start_peak=((double)i-1)/audio.size(); i=audio.size(); while (i>0&&audio[i]audio[i+1]) i--; - end_peak=((float)i+1)/audio.size(); + end_peak=((double)i+1)/audio.size(); cerr<<"Video_output sound envelope: silence - "<value=="fade peak"||attributes["begin_mode"]->value=="blank silence"){ if (track_timevalue=="fade peak"&&start_peak>start_silence){ amount = (track_time-start_silence)/(start_peak-start_silence); @@ -1099,17 +1099,17 @@ namespace Rotor { } if (attributes["end_mode"]->value=="fade peak"||attributes["end_mode"]->value=="blank silence"){ if (track_time>end_silence){ - amount=0.0f; + amount=0.0; } else if (track_time>end_peak&&attributes["end_mode"]->value=="fade peak"&&end_silence>end_peak){ - amount = 1.0f-((track_time-end_peak)/(end_silence-end_peak)); + amount = 1.0-((track_time-end_peak)/(end_silence-end_peak)); } } - if (amount<(1.0f/256.0f)){ + if (amount<(1.0/256.0)){ image.clear(); } image=(*in); - if (amount<(255.0f/256.0f)){ + if (amount<(255.0/256.0)){ image*=amount; } //seems to be outputting correctly but not saving frames @@ -1120,11 +1120,11 @@ namespace Rotor { Video_output* clone(map &_settings) { return new Video_output(_settings);}; private: - float silence_threshold; - float start_silence; - float start_peak; - float end_silence; - float end_peak; + double silence_threshold; + double start_silence; + double start_peak; + double end_silence; + double end_peak; }; class Video_feedback: public Image_node { public: -- cgit v1.2.3