Browse Source

Onset detection

master
Nasca Octavian PAUL 10 years ago
parent
commit
1bfdda7fb6
5 changed files with 35 additions and 25 deletions
  1. +5
    -2
      Control.cpp
  2. +5
    -2
      Player.cpp
  3. +0
    -6
      ProcessedStretch.cpp
  4. +17
    -9
      Stretch.cpp
  5. +8
    -6
      Stretch.h

+ 5
- 2
Control.cpp View File

@@ -503,8 +503,11 @@ string Control::Render(string inaudio,string outaudio,FILE_TYPE outtype,FILE_TYP
inbuf.l[i]=inbuf_i[i*2]/32768.0;
inbuf.r[i]=inbuf_i[i*2+1]/32768.0;
};
stretchl->process(inbuf.l,readed);
stretchr->process(inbuf.r,readed);
REALTYPE onset_l=stretchl->process(inbuf.l,readed);
REALTYPE onset_r=stretchr->process(inbuf.r,readed);
REALTYPE onset=(onset_l>onset_r)?onset_l:onset_r;
stretchl->here_is_onset(onset);
stretchr->here_is_onset(onset);
bb.process(stretchl->out_buf,stretchr->out_buf,outbufsize,in_pos*100.0);
for (int i=0;i<outbufsize;i++) {
stretchl->out_buf[i]*=volume;


+ 5
- 2
Player.cpp View File

@@ -405,8 +405,11 @@ void Player::computesamples(){
first_in_buf=false;
stretchl->window_type=window_type;
stretchr->window_type=window_type;
stretchl->process(inbuf.l,readsize);
stretchr->process(inbuf.r,readsize);
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;
stretchl->here_is_onset(onset);
stretchr->here_is_onset(onset);
binaural_beats->process(stretchl->out_buf,stretchr->out_buf,stretchl->get_bufsize(),in_pos_100);
// stretchl->process_output(stretchl->out_buf,stretchl->out_bufsize);
// stretchr->process_output(stretchr->out_buf,stretchr->out_bufsize);


+ 0
- 6
ProcessedStretch.cpp View File

@@ -182,10 +182,6 @@ REALTYPE ProcessedStretch::get_stretch_multiplier(REALTYPE pos_percents){
};

void ProcessedStretch::process_spectrum(REALTYPE *freq){
//REALTYPE fb=0.8;
//add(freq,fbfreq,fb);

if (pars.harmonics.enabled) {
copy(freq,infreq);
do_harmonics(infreq,freq);
@@ -231,8 +227,6 @@ void ProcessedStretch::process_spectrum(REALTYPE *freq){
do_compressor(infreq,freq);
};

// copy(freq,fbfreq);
// mul(freq,1.0-fb);
};

//void ProcessedStretch::process_output(REALTYPE *smps,int nsmps){


+ 17
- 9
Stretch.cpp View File

@@ -142,11 +142,11 @@ void FFT::applywindow(FFTWindow type){


Stretch::Stretch(REALTYPE rap_,int bufsize_,FFTWindow w,bool bypass_,REALTYPE samplerate_,int stereo_mode_){
onset_detection_strength=0.0;
onset_detection_sensitivity=0.0;

#warning test
onset_detection_strength=0.5;
onset_detection_sensitivity=0.5;



@@ -225,7 +225,7 @@ void Stretch::do_next_inbuf_smps(REALTYPE *smps){
REALTYPE Stretch::do_detect_onset(){
//kuku=!kuku;
REALTYPE result=0.0;
if (onset_detection_strength>1e-3){
if (onset_detection_sensitivity>1e-3){
REALTYPE os=0.0,osinc=0.0;
REALTYPE osincold=1e-5;
int maxk=1+(int)(bufsize*500.0/(samplerate*0.5));
@@ -244,7 +244,7 @@ REALTYPE Stretch::do_detect_onset(){
if (os<0.0) os=0.0;
//if (os>1.0) os=1.0;

REALTYPE os_strength=pow(20.0,sqrt(1.0-onset_detection_strength))-1.0;
REALTYPE os_strength=pow(20.0,sqrt(1.0-onset_detection_sensitivity))-1.0;
REALTYPE os_strength_h=os_strength*0.75;
if (os>os_strength_h){
result=(os-os_strength_h)/(os_strength-os_strength_h);
@@ -259,21 +259,22 @@ REALTYPE Stretch::do_detect_onset(){
return result;
};

void Stretch::process(REALTYPE *smps,int nsmps){
REALTYPE Stretch::process(REALTYPE *smps,int nsmps){
REALTYPE onset=0.0;
if (bypass){
for (int i=0;i<bufsize;i++) out_buf[i]=smps[i];
return;
return 0.0;
};

if (smps!=NULL){
if ((nsmps!=0)&&(nsmps!=bufsize)&&(nsmps!=bufsize*2)){
printf("Warning wrong nsmps on Stretch::process() %d,%d\n",nsmps,bufsize);
return;
return 0.0;
};
if (nsmps!=0){//new data arrived: update the frequency components
do_analyse_inbuf(smps);
if (nsmps==bufsize*2) do_analyse_inbuf(smps+bufsize);
REALTYPE onset=do_detect_onset();
if (onset_detection_sensitivity>1e-3) onset=do_detect_onset();
};


@@ -338,9 +339,16 @@ void Stretch::process(REALTYPE *smps,int nsmps){

// long double rf_test=remained_samples-old_remained_samples_test;//this value should be almost like "rf" (for most of the time with the exception of changing the "ri" value) for extremely long stretches (otherwise the shown stretch value is not accurate)
//for stretch up to 10^18x "long double" must have at least 64 bits in the fraction part (true for gcc compiler on x86 and macosx)
return onset;
};

void Stretch::here_is_onset(REALTYPE onset){
if (onset>0.5){
require_new_buffer=true;
remained_samples=0.0;
//aici sa pun creditul
};
};

int Stretch::get_nsamples(REALTYPE current_pos_percents){
if (bypass) return bufsize;


+ 8
- 6
Stretch.h View File

@@ -69,12 +69,11 @@ class Stretch{
return bufsize;
};

REALTYPE get_onset_detection_strength(){
return onset_detection_strength;
REALTYPE get_onset_detection_sensitivity(){
return onset_detection_sensitivity;
};

void process(REALTYPE *smps,int nsmps);
// virtual void process_output(REALTYPE *smps,int nsmps){};
REALTYPE process(REALTYPE *smps,int nsmps);//returns the onset value


REALTYPE *out_buf;//pot sa pun o variabila "max_out_bufsize" si asta sa fie marimea lui out_buf si pe out_bufsize sa il folosesc ca marime adaptiva
@@ -84,7 +83,10 @@ class Stretch{

void set_rap(REALTYPE newrap);//set the current stretch value

void set_onset_detection_strength(REALTYPE detection_strength);
void set_onset_detection_sensitivity(REALTYPE detection_sensitivity){
onset_detection_sensitivity=detection_sensitivity;
};
void here_is_onset(REALTYPE onset);

FFTWindow window_type;
protected:
@@ -101,7 +103,7 @@ class Stretch{
REALTYPE do_detect_onset();

// REALTYPE *in_pool;//de marimea in_bufsize
REALTYPE rap,onset_detection_strength;
REALTYPE rap,onset_detection_sensitivity;
REALTYPE *old_out_smps;
REALTYPE *old_freq;
REALTYPE *new_smps,*old_smps,*very_old_smps;


Loading…
Cancel
Save