Skip to content

Commit

Permalink
Added onset detection in GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nasca Octavian PAUL committed Mar 2, 2011
1 parent 1bfdda7 commit 39cc2d7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 127 deletions.
90 changes: 9 additions & 81 deletions Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Control::Control(){

process.bufsize=16384;
process.stretch=4.0;
/// process.transient.enable=false;
/// process.transient.amount=0.5;
process.onset_detection_sensitivity=0.0;

seek_pos=0.0;
window_type=W_HANN;
Expand All @@ -57,83 +56,6 @@ Control::~Control(){
// 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){
InputS *ai=NULL;
Expand Down Expand Up @@ -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.mode_s=mode;
gui_sliders.fftsize_s=fftsize_s;
Expand Down Expand Up @@ -367,6 +289,7 @@ void Control::set_stretch_controls(double stretch_s,int mode,double fftsize_s){

process.stretch=stretch;
process.bufsize=bufsize;
process.onset_detection_sensitivity=onset_detection_sensitivity;

};

Expand Down Expand Up @@ -394,6 +317,7 @@ double Control::get_stretch_control(double stretch,int mode){

void Control::update_player_stretch(){
player->setrap(process.stretch);
player->set_onset_detection_sensitivity(process.onset_detection_sensitivity);
};


Expand Down Expand Up @@ -473,6 +397,8 @@ string Control::Render(string inaudio,string outaudio,FILE_TYPE outtype,FILE_TYP
}inbuf;
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);
stretchl->set_onset_detection_sensitivity(process.onset_detection_sensitivity);
stretchr->set_onset_detection_sensitivity(process.onset_detection_sensitivity);
stretchl->set_parameters(&ppar);
stretchr->set_parameters(&ppar);

Expand Down Expand Up @@ -583,6 +509,7 @@ bool Control::save_parameters(const char *filename){

xml->addpar("window_type",window_type);
xml->addparreal("volume",volume);
xml->addparreal("onset_detection_sensitivity",process.onset_detection_sensitivity);

xml->endbranch();

Expand Down Expand Up @@ -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.mode_s=xml->getpar("mode_s",gui_sliders.mode_s,0,2);
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);
xml->exitbranch();
};
Expand All @@ -642,7 +570,7 @@ bool Control::load_parameters(const char *filename){
};
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_volume(volume);
Expand Down
10 changes: 5 additions & 5 deletions Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ class Control{
double get_stretch(){
return process.stretch;
};
double get_onset_detection_sensitivity(){
return process.onset_detection_sensitivity;
};


bool 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);
void update_player_stretch();

Expand Down Expand Up @@ -106,10 +109,7 @@ class Control{
struct {
int bufsize;
double stretch;
/// struct{
/// bool enable;
/// double amount;
/// } transient;
double onset_detection_sensitivity;
}process;

struct {
Expand Down
19 changes: 13 additions & 6 deletions GUI.fl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ rendering=false;} {}
Function {make_window()} {open private
} {
Fl_Window window {
label {Paul's Extreme Sound Stretch} open
label {Paul's Extreme Sound Stretch}
xywh {192 131 995 550} type Double resizable
code0 {if(strlen(VERSION)<2) {o->color(FL_BLUE); o->label("VERSION NOT SET!!!!!!!!!!!!");};} visible
} {
Expand Down Expand Up @@ -383,6 +383,12 @@ stretch_slider->do_callback();}
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 {} {
label Process open
Expand Down Expand Up @@ -820,7 +826,8 @@ window->redraw();} {}
int mode=mode_choice->value();
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());
fftsize_slider->copy_label(control.get_fftsize_info().c_str());
Expand All @@ -847,7 +854,7 @@ if (!rendering){//do not change the status of render button while rendering
fftsize_slider->value(control.gui_sliders.fftsize_s);
mode_choice->value(control.gui_sliders.mode_s);
window_choice->value(control.window_type);

onset_slider->value(control.get_onset_detection_sensitivity());


pitch_shift_enabled->value(control.ppar.pitch_shift.enabled);
Expand Down Expand Up @@ -893,7 +900,8 @@ bbpar_stereo_mode->value(control.bbpar.stereo_mode);

stretch_multiplier_control->refresh();
arbitrary_filter_control->refresh();
binaural_beats_control->refresh();} {}
binaural_beats_control->refresh();} {selected
}
}
Function {tickrefresh()} {} {
code {seek_slider->value(seek_slider->maximum()*control.get_seek_pos());
Expand Down Expand Up @@ -961,6 +969,5 @@ Fl::run();

delete gui;

return 0;} {selected
}
return 0;} {}
}
9 changes: 7 additions & 2 deletions Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Player::Player():Thread(){
info.samplerate=44100;
info.eof=true;
volume=1.0;
onset_detection_sensitivity=0.0;
};

Player::~Player(){
Expand Down Expand Up @@ -153,6 +154,9 @@ void Player::set_window_type(FFTWindow window){
void Player::set_volume(REALTYPE vol){
volume=vol;
};
void Player::set_onset_detection_sensitivity(REALTYPE onset){
onset_detection_sensitivity=onset;
};

void Player::getaudiobuffer(int nsamples, float *out){
if (mode==MODE_PREPARING){
Expand Down Expand Up @@ -205,12 +209,10 @@ void Player::getaudiobuffer(int nsamples, float *out){

};
};
// printf("-------------- %d\n",outbuf.nfresh);
outbuf.outk=k;
outbuf.outpos=pos;
bufmutex.unlock();

// printf("max=%g\n",max);

};

Expand Down Expand Up @@ -405,6 +407,9 @@ void Player::computesamples(){
first_in_buf=false;
stretchl->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_r=stretchr->process(inbuf.r,readsize);
REALTYPE onset=(onset_l>onset_r)?onset_l:onset_r;
Expand Down
5 changes: 3 additions & 2 deletions Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Player:public Thread{
void set_window_type(FFTWindow window);

void set_volume(REALTYPE vol);
void set_onset_detection_sensitivity(REALTYPE onset);

void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar);

Expand All @@ -86,7 +87,7 @@ class Player:public Thread{
ModeType mode;

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 {
TaskMode mode;
Expand Down Expand Up @@ -120,7 +121,7 @@ class Player:public Thread{
void newtaskcheck();
void computesamples();
bool freeze_mode,bypass_mode,paused;
REALTYPE volume;
REALTYPE volume,onset_detection_sensitivity;

std::string current_filename;
FFTWindow window_type;
Expand Down
25 changes: 0 additions & 25 deletions ProcessedStretch.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,15 @@ struct ProcessParameters{
spread.enabled=false;
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.preserve=0.5;
tonal_vs_noise.bandwidth=0.9;
};
~ProcessParameters(){
/// delete []waveinfo.transients_data;
};
void add2XML(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{
bool enabled;
int cents;
Expand Down Expand Up @@ -133,11 +113,6 @@ struct ProcessParameters{
FreeEdit free_filter;
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{
Expand Down
6 changes: 0 additions & 6 deletions Stretch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ void FFT::applywindow(FFTWindow type){
Stretch::Stretch(REALTYPE rap_,int bufsize_,FFTWindow w,bool bypass_,REALTYPE samplerate_,int stereo_mode_){
onset_detection_sensitivity=0.0;


#warning test
onset_detection_sensitivity=0.5;



samplerate=samplerate_;
rap=rap_;
bufsize=bufsize_;
Expand Down

0 comments on commit 39cc2d7

Please sign in to comment.