@@ -34,8 +34,7 @@ Control::Control(){ | |||||
process.bufsize=16384; | process.bufsize=16384; | ||||
process.stretch=4.0; | process.stretch=4.0; | ||||
/// process.transient.enable=false; | |||||
/// process.transient.amount=0.5; | |||||
process.onset_detection_sensitivity=0.0; | |||||
seek_pos=0.0; | seek_pos=0.0; | ||||
window_type=W_HANN; | window_type=W_HANN; | ||||
@@ -57,83 +56,6 @@ Control::~Control(){ | |||||
// delete player; face crash daca il las | // delete player; face crash daca il las | ||||
}; | }; | ||||
///void Control::pre_analyse_whole_audio(InputS *ai){ | |||||
/// int inbufsize=1024; | |||||
/// int readsize=inbufsize/2; | |||||
/// | |||||
/// short int *inbuf_i=new short int[readsize*2]; | |||||
/// | |||||
///// REALTYPE *inbuf_f=new REALTYPE[readsize]; | |||||
///// for (int i=0;i<readsize;i++) inbuf_f[i]=0.0; | |||||
/// | |||||
/// REALTYPE *processbuf=new REALTYPE[inbufsize]; | |||||
/// for (int i=0;i<inbufsize;i++) processbuf[i]=0.0; | |||||
/// | |||||
/// FFT *infft=new FFT(inbufsize); | |||||
/// | |||||
/// int k=0; | |||||
/// int fftsize=inbufsize/2; | |||||
/// REALTYPE *oldfreq=new REALTYPE[fftsize]; | |||||
/// for (int i=0;i<fftsize;i++) oldfreq[i]=0.0; | |||||
/// REALTYPE oldsumstart=0.0; | |||||
/// int transient_data_n=0; | |||||
/// int transient_data_max_n=10000; | |||||
/// REALTYPE *transient_data=new REALTYPE [transient_data_max_n]; | |||||
/// while(!ai->eof){ | |||||
/// float in_pos=(REALTYPE) ai->info.currentsample/(REALTYPE)ai->info.nsamples; | |||||
/// | |||||
/// int readed=ai->read(readsize,inbuf_i); | |||||
/// if (readed!=readsize) break;//do not process the last buffer from the audiofile | |||||
/// const float inv_32768=1.0/32768.0; | |||||
/// | |||||
/// for (int i=0;i<inbufsize-readed;i++){ | |||||
/// processbuf[i]=processbuf[i+readed]; | |||||
/// }; | |||||
/// for (int i=0;i<readed;i++) { | |||||
/// processbuf[i+inbufsize-readed]=(inbuf_i[i*2]*inv_32768+inbuf_i[i*2+1]*inv_32768); | |||||
/// }; | |||||
/// | |||||
/// | |||||
/// for (int i=0;i<inbufsize;i++) infft->smp[i]=processbuf[i]; | |||||
/// | |||||
/// | |||||
/// infft->applywindow(W_HAMMING); | |||||
/// infft->smp2freq(); | |||||
/// infft->freq[0]=0; | |||||
/// REALTYPE *freq=infft->freq; | |||||
/// | |||||
/// REALTYPE sumstart=0.0; | |||||
/// for (int i=0;i<fftsize;i++){ | |||||
/// REALTYPE x=freq[i]-oldfreq[i]; | |||||
/// if (x>0) sumstart+=x; | |||||
/// }; | |||||
/// sumstart/=fftsize; | |||||
/// const REALTYPE a=0.1; | |||||
/// oldsumstart=oldsumstart*(1.0-a)+sumstart*a; | |||||
/// sumstart-=1.5*oldsumstart; | |||||
/// if (sumstart<0.0) sumstart=0.0; | |||||
/// | |||||
/// transient_data[transient_data_n]=sumstart; | |||||
/// transient_data_n++; | |||||
/// if (transient_data_n>=transient_data_max_n){ | |||||
/// transient_data_max_n+=100000; | |||||
/// REALTYPE *new_transient_data=new REALTYPE[transient_data_max_n]; | |||||
/// for (int i=0;i<transient_data_n;i++) new_transient_data[i]=transient_data[i]; | |||||
/// delete [] transient_data; | |||||
/// transient_data=new_transient_data; | |||||
/// }; | |||||
/// | |||||
/// for (int i=0;i<fftsize;i++) oldfreq[i]=freq[i]; | |||||
/// }; | |||||
/// ppar.set_transient_data(transient_data_n,transient_data); | |||||
/// delete infft; | |||||
/// delete []transient_data; | |||||
/// | |||||
/// delete []oldfreq; | |||||
/// delete [] inbuf_i; | |||||
/// //delete [] inbuf_f; | |||||
/// delete [] processbuf; | |||||
///}; | |||||
bool Control::set_input_filename(string filename,FILE_TYPE intype){ | bool Control::set_input_filename(string filename,FILE_TYPE intype){ | ||||
InputS *ai=NULL; | InputS *ai=NULL; | ||||
@@ -336,7 +258,7 @@ REALTYPE Control::get_seek_pos(){ | |||||
}; | }; | ||||
void Control::set_stretch_controls(double stretch_s,int mode,double fftsize_s){ | |||||
void Control::set_stretch_controls(double stretch_s,int mode,double fftsize_s,double onset_detection_sensitivity){ | |||||
gui_sliders.stretch_s=stretch_s; | gui_sliders.stretch_s=stretch_s; | ||||
gui_sliders.mode_s=mode; | gui_sliders.mode_s=mode; | ||||
gui_sliders.fftsize_s=fftsize_s; | gui_sliders.fftsize_s=fftsize_s; | ||||
@@ -367,6 +289,7 @@ void Control::set_stretch_controls(double stretch_s,int mode,double fftsize_s){ | |||||
process.stretch=stretch; | process.stretch=stretch; | ||||
process.bufsize=bufsize; | process.bufsize=bufsize; | ||||
process.onset_detection_sensitivity=onset_detection_sensitivity; | |||||
}; | }; | ||||
@@ -394,6 +317,7 @@ double Control::get_stretch_control(double stretch,int mode){ | |||||
void Control::update_player_stretch(){ | void Control::update_player_stretch(){ | ||||
player->setrap(process.stretch); | player->setrap(process.stretch); | ||||
player->set_onset_detection_sensitivity(process.onset_detection_sensitivity); | |||||
}; | }; | ||||
@@ -473,6 +397,8 @@ string Control::Render(string inaudio,string outaudio,FILE_TYPE outtype,FILE_TYP | |||||
}inbuf; | }inbuf; | ||||
ProcessedStretch *stretchl=new ProcessedStretch(process.stretch,inbufsize,window_type,false,ai->info.samplerate,1); | ProcessedStretch *stretchl=new ProcessedStretch(process.stretch,inbufsize,window_type,false,ai->info.samplerate,1); | ||||
ProcessedStretch *stretchr=new ProcessedStretch(process.stretch,inbufsize,window_type,false,ai->info.samplerate,2); | ProcessedStretch *stretchr=new ProcessedStretch(process.stretch,inbufsize,window_type,false,ai->info.samplerate,2); | ||||
stretchl->set_onset_detection_sensitivity(process.onset_detection_sensitivity); | |||||
stretchr->set_onset_detection_sensitivity(process.onset_detection_sensitivity); | |||||
stretchl->set_parameters(&ppar); | stretchl->set_parameters(&ppar); | ||||
stretchr->set_parameters(&ppar); | stretchr->set_parameters(&ppar); | ||||
@@ -583,6 +509,7 @@ bool Control::save_parameters(const char *filename){ | |||||
xml->addpar("window_type",window_type); | xml->addpar("window_type",window_type); | ||||
xml->addparreal("volume",volume); | xml->addparreal("volume",volume); | ||||
xml->addparreal("onset_detection_sensitivity",process.onset_detection_sensitivity); | |||||
xml->endbranch(); | xml->endbranch(); | ||||
@@ -624,6 +551,7 @@ bool Control::load_parameters(const char *filename){ | |||||
gui_sliders.stretch_s=xml->getparreal("stretch_s",gui_sliders.stretch_s); | gui_sliders.stretch_s=xml->getparreal("stretch_s",gui_sliders.stretch_s); | ||||
gui_sliders.mode_s=xml->getpar("mode_s",gui_sliders.mode_s,0,2); | gui_sliders.mode_s=xml->getpar("mode_s",gui_sliders.mode_s,0,2); | ||||
window_type=(FFTWindow)xml->getpar("window_type",window_type,0,4); | window_type=(FFTWindow)xml->getpar("window_type",window_type,0,4); | ||||
process.onset_detection_sensitivity=xml->getparreal("onset_detection_sensitivity",0.0); | |||||
volume=xml->getparreal("volume",1.0); | volume=xml->getparreal("volume",1.0); | ||||
xml->exitbranch(); | xml->exitbranch(); | ||||
}; | }; | ||||
@@ -642,7 +570,7 @@ bool Control::load_parameters(const char *filename){ | |||||
}; | }; | ||||
delete xml; | delete xml; | ||||
set_stretch_controls(gui_sliders.stretch_s,gui_sliders.mode_s,gui_sliders.fftsize_s); | |||||
set_stretch_controls(gui_sliders.stretch_s,gui_sliders.mode_s,gui_sliders.fftsize_s,process.onset_detection_sensitivity); | |||||
set_window_type(window_type); | set_window_type(window_type); | ||||
set_volume(volume); | set_volume(volume); | ||||
@@ -66,13 +66,16 @@ class Control{ | |||||
double get_stretch(){ | double get_stretch(){ | ||||
return process.stretch; | return process.stretch; | ||||
}; | }; | ||||
double get_onset_detection_sensitivity(){ | |||||
return process.onset_detection_sensitivity; | |||||
}; | |||||
bool is_freeze(){ | bool is_freeze(){ | ||||
return player->is_freeze(); | return player->is_freeze(); | ||||
}; | }; | ||||
void set_stretch_controls(double stretch_s,int mode,double fftsize_s);//*_s sunt de la 0.0 la 1.0 | |||||
void set_stretch_controls(double stretch_s,int mode,double fftsize_s,double onset_detection_sensitivity);//*_s sunt de la 0.0 la 1.0 | |||||
double get_stretch_control(double stretch,int mode); | double get_stretch_control(double stretch,int mode); | ||||
void update_player_stretch(); | void update_player_stretch(); | ||||
@@ -106,10 +109,7 @@ class Control{ | |||||
struct { | struct { | ||||
int bufsize; | int bufsize; | ||||
double stretch; | double stretch; | ||||
/// struct{ | |||||
/// bool enable; | |||||
/// double amount; | |||||
/// } transient; | |||||
double onset_detection_sensitivity; | |||||
}process; | }process; | ||||
struct { | struct { | ||||
@@ -187,7 +187,7 @@ rendering=false;} {} | |||||
Function {make_window()} {open private | Function {make_window()} {open private | ||||
} { | } { | ||||
Fl_Window window { | Fl_Window window { | ||||
label {Paul's Extreme Sound Stretch} open | |||||
label {Paul's Extreme Sound Stretch} | |||||
xywh {192 131 995 550} type Double resizable | xywh {192 131 995 550} type Double resizable | ||||
code0 {if(strlen(VERSION)<2) {o->color(FL_BLUE); o->label("VERSION NOT SET!!!!!!!!!!!!");};} visible | code0 {if(strlen(VERSION)<2) {o->color(FL_BLUE); o->label("VERSION NOT SET!!!!!!!!!!!!");};} visible | ||||
} { | } { | ||||
@@ -383,6 +383,12 @@ stretch_slider->do_callback();} | |||||
class FreeEditControls | class FreeEditControls | ||||
} {} | } {} | ||||
} | } | ||||
Fl_Slider onset_slider { | |||||
label {Onset sensitivity:} | |||||
callback {refresh(); | |||||
control.update_player_stretch();} | |||||
xywh {135 213 140 17} type {Horz Knob} box FLAT_BOX align 4 | |||||
} | |||||
} | } | ||||
Fl_Group {} { | Fl_Group {} { | ||||
label Process open | label Process open | ||||
@@ -820,7 +826,8 @@ window->redraw();} {} | |||||
int mode=mode_choice->value(); | int mode=mode_choice->value(); | ||||
double resolution_s=fftsize_slider->value()/fftsize_slider->maximum(); | double resolution_s=fftsize_slider->value()/fftsize_slider->maximum(); | ||||
control.set_stretch_controls(stretch_s,mode,resolution_s); | |||||
double onset=onset_slider->value(); | |||||
control.set_stretch_controls(stretch_s,mode,resolution_s,onset); | |||||
stretch_slider->copy_label(control.get_stretch_info().c_str()); | stretch_slider->copy_label(control.get_stretch_info().c_str()); | ||||
fftsize_slider->copy_label(control.get_fftsize_info().c_str()); | fftsize_slider->copy_label(control.get_fftsize_info().c_str()); | ||||
@@ -847,7 +854,7 @@ if (!rendering){//do not change the status of render button while rendering | |||||
fftsize_slider->value(control.gui_sliders.fftsize_s); | fftsize_slider->value(control.gui_sliders.fftsize_s); | ||||
mode_choice->value(control.gui_sliders.mode_s); | mode_choice->value(control.gui_sliders.mode_s); | ||||
window_choice->value(control.window_type); | window_choice->value(control.window_type); | ||||
onset_slider->value(control.get_onset_detection_sensitivity()); | |||||
pitch_shift_enabled->value(control.ppar.pitch_shift.enabled); | pitch_shift_enabled->value(control.ppar.pitch_shift.enabled); | ||||
@@ -893,7 +900,8 @@ bbpar_stereo_mode->value(control.bbpar.stereo_mode); | |||||
stretch_multiplier_control->refresh(); | stretch_multiplier_control->refresh(); | ||||
arbitrary_filter_control->refresh(); | arbitrary_filter_control->refresh(); | ||||
binaural_beats_control->refresh();} {} | |||||
binaural_beats_control->refresh();} {selected | |||||
} | |||||
} | } | ||||
Function {tickrefresh()} {} { | Function {tickrefresh()} {} { | ||||
code {seek_slider->value(seek_slider->maximum()*control.get_seek_pos()); | code {seek_slider->value(seek_slider->maximum()*control.get_seek_pos()); | ||||
@@ -961,6 +969,5 @@ Fl::run(); | |||||
delete gui; | delete gui; | ||||
return 0;} {selected | |||||
} | |||||
return 0;} {} | |||||
} | } |
@@ -69,6 +69,7 @@ Player::Player():Thread(){ | |||||
info.samplerate=44100; | info.samplerate=44100; | ||||
info.eof=true; | info.eof=true; | ||||
volume=1.0; | volume=1.0; | ||||
onset_detection_sensitivity=0.0; | |||||
}; | }; | ||||
Player::~Player(){ | Player::~Player(){ | ||||
@@ -153,6 +154,9 @@ void Player::set_window_type(FFTWindow window){ | |||||
void Player::set_volume(REALTYPE vol){ | void Player::set_volume(REALTYPE vol){ | ||||
volume=vol; | volume=vol; | ||||
}; | }; | ||||
void Player::set_onset_detection_sensitivity(REALTYPE onset){ | |||||
onset_detection_sensitivity=onset; | |||||
}; | |||||
void Player::getaudiobuffer(int nsamples, float *out){ | void Player::getaudiobuffer(int nsamples, float *out){ | ||||
if (mode==MODE_PREPARING){ | if (mode==MODE_PREPARING){ | ||||
@@ -205,12 +209,10 @@ void Player::getaudiobuffer(int nsamples, float *out){ | |||||
}; | }; | ||||
}; | }; | ||||
// printf("-------------- %d\n",outbuf.nfresh); | |||||
outbuf.outk=k; | outbuf.outk=k; | ||||
outbuf.outpos=pos; | outbuf.outpos=pos; | ||||
bufmutex.unlock(); | bufmutex.unlock(); | ||||
// printf("max=%g\n",max); | |||||
}; | }; | ||||
@@ -405,6 +407,9 @@ void Player::computesamples(){ | |||||
first_in_buf=false; | first_in_buf=false; | ||||
stretchl->window_type=window_type; | stretchl->window_type=window_type; | ||||
stretchr->window_type=window_type; | stretchr->window_type=window_type; | ||||
REALTYPE s_onset=onset_detection_sensitivity; | |||||
stretchl->set_onset_detection_sensitivity(s_onset); | |||||
stretchr->set_onset_detection_sensitivity(s_onset); | |||||
REALTYPE onset_l=stretchl->process(inbuf.l,readsize); | REALTYPE onset_l=stretchl->process(inbuf.l,readsize); | ||||
REALTYPE onset_r=stretchr->process(inbuf.r,readsize); | REALTYPE onset_r=stretchr->process(inbuf.r,readsize); | ||||
REALTYPE onset=(onset_l>onset_r)?onset_l:onset_r; | REALTYPE onset=(onset_l>onset_r)?onset_l:onset_r; | ||||
@@ -67,6 +67,7 @@ class Player:public Thread{ | |||||
void set_window_type(FFTWindow window); | void set_window_type(FFTWindow window); | ||||
void set_volume(REALTYPE vol); | void set_volume(REALTYPE vol); | ||||
void set_onset_detection_sensitivity(REALTYPE onset); | |||||
void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar); | void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar); | ||||
@@ -86,7 +87,7 @@ class Player:public Thread{ | |||||
ModeType mode; | ModeType mode; | ||||
enum TaskMode{ | enum TaskMode{ | ||||
TASK_NONE, TASK_START, TASK_STOP,TASK_SEEK,TASK_RAP,TASK_PARAMETERS | |||||
TASK_NONE, TASK_START, TASK_STOP,TASK_SEEK,TASK_RAP,TASK_PARAMETERS, TASK_ONSET | |||||
}; | }; | ||||
struct { | struct { | ||||
TaskMode mode; | TaskMode mode; | ||||
@@ -120,7 +121,7 @@ class Player:public Thread{ | |||||
void newtaskcheck(); | void newtaskcheck(); | ||||
void computesamples(); | void computesamples(); | ||||
bool freeze_mode,bypass_mode,paused; | bool freeze_mode,bypass_mode,paused; | ||||
REALTYPE volume; | |||||
REALTYPE volume,onset_detection_sensitivity; | |||||
std::string current_filename; | std::string current_filename; | ||||
FFTWindow window_type; | FFTWindow window_type; | ||||
@@ -55,35 +55,15 @@ struct ProcessParameters{ | |||||
spread.enabled=false; | spread.enabled=false; | ||||
spread.bandwidth=0.3; | spread.bandwidth=0.3; | ||||
/// waveinfo.n_transients=1; | |||||
/// waveinfo.transients_data=new REALTYPE[1]; | |||||
/// waveinfo.transients_data[0]=0; | |||||
tonal_vs_noise.enabled=false; | tonal_vs_noise.enabled=false; | ||||
tonal_vs_noise.preserve=0.5; | tonal_vs_noise.preserve=0.5; | ||||
tonal_vs_noise.bandwidth=0.9; | tonal_vs_noise.bandwidth=0.9; | ||||
}; | }; | ||||
~ProcessParameters(){ | ~ProcessParameters(){ | ||||
/// delete []waveinfo.transients_data; | |||||
}; | }; | ||||
void add2XML(XMLwrapper *xml); | void add2XML(XMLwrapper *xml); | ||||
void getfromXML(XMLwrapper *xml); | void getfromXML(XMLwrapper *xml); | ||||
/// void set_transient_data(int n,REALTYPE *tr){ | |||||
/// delete []waveinfo.transients_data; | |||||
/// waveinfo.n_transients=n; | |||||
/// waveinfo.transients_data=new REALTYPE[n]; | |||||
/// for (int i=0;i<n;i++) waveinfo.transients_data[i]=tr[i]; | |||||
/// }; | |||||
/// | |||||
/// REALTYPE get_transient(REALTYPE pos_percents){ | |||||
/// REALTYPE pos=pos_percents*0.01; | |||||
/// if ((pos<0.0)||(pos>1.0)) return 0.0; | |||||
/// REALTYPE fpos=pos*waveinfo.n_transients; | |||||
/// int ipos=(int)fpos; | |||||
/// return waveinfo.transients_data[ipos]; | |||||
/// }; | |||||
struct{ | struct{ | ||||
bool enabled; | bool enabled; | ||||
int cents; | int cents; | ||||
@@ -133,11 +113,6 @@ struct ProcessParameters{ | |||||
FreeEdit free_filter; | FreeEdit free_filter; | ||||
FreeEdit stretch_multiplier; | FreeEdit stretch_multiplier; | ||||
//the folowing parameter represents the information regarding the audio (it is not saved) | |||||
/// struct{ | |||||
/// int n_transients; | |||||
/// REALTYPE *transients_data; | |||||
/// }waveinfo; | |||||
}; | }; | ||||
class ProcessedStretch:public Stretch{ | class ProcessedStretch:public Stretch{ | ||||
@@ -144,12 +144,6 @@ void FFT::applywindow(FFTWindow type){ | |||||
Stretch::Stretch(REALTYPE rap_,int bufsize_,FFTWindow w,bool bypass_,REALTYPE samplerate_,int stereo_mode_){ | Stretch::Stretch(REALTYPE rap_,int bufsize_,FFTWindow w,bool bypass_,REALTYPE samplerate_,int stereo_mode_){ | ||||
onset_detection_sensitivity=0.0; | onset_detection_sensitivity=0.0; | ||||
#warning test | |||||
onset_detection_sensitivity=0.5; | |||||
samplerate=samplerate_; | samplerate=samplerate_; | ||||
rap=rap_; | rap=rap_; | ||||
bufsize=bufsize_; | bufsize=bufsize_; | ||||