ref: 18a82b345c00ce71e790ee2b119485dfbc309ae4
parent: 4b6937b60f42819270033ab16d7949ac507461a0
parent: b050e8e67ce54dad93add48e1a4549470cfc07bd
author: Paul Brossier <piem@piem.org>
date: Wed Nov 7 12:21:00 EST 2007
merge from rhubarb
--- a/src/pitchfcomb.c
+++ b/src/pitchfcomb.c
@@ -31,15 +31,15 @@
} aubio_fpeak_t;
struct _aubio_pitchfcomb_t {
- uint_t fftSize;
- uint_t stepSize;
- uint_t rate;
- fvec_t * winput;
- fvec_t * win;
- cvec_t * fftOut;
- fvec_t * fftLastPhase;
- aubio_fft_t * fft;
- //aubio_pvoc_t * pvoc;
+ uint_t fftSize;
+ uint_t stepSize;
+ uint_t rate;
+ fvec_t * winput;
+ fvec_t * win;
+ cvec_t * fftOut;
+ fvec_t * fftLastPhase;
+ aubio_fft_t * fft;
+ //aubio_pvoc_t * pvoc;
};
aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t samplerate)
@@ -47,7 +47,7 @@
aubio_pitchfcomb_t * p = AUBIO_NEW(aubio_pitchfcomb_t);
p->rate = samplerate;
p->fftSize = bufsize;
- p->stepSize = hopsize;
+ p->stepSize = hopsize;
p->winput = new_fvec(bufsize,1);
p->fftOut = new_cvec(bufsize,1);
p->fftLastPhase = new_fvec(bufsize,1);
@@ -71,7 +71,7 @@
}
for (k=0; k < input->length; k++){
- p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
+ p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
}
aubio_fft_do(p->fft,p->winput,p->fftOut);
@@ -103,17 +103,17 @@
peaks[0].db = magnitude;
}
}
-
+
k = 0;
for (l=1; l<MAX_PEAKS && peaks[l].freq > 0.0; l++) {
sint_t harmonic;
for (harmonic=5; harmonic>1; harmonic--) {
if (peaks[0].freq / peaks[l].freq < harmonic+.02 &&
- peaks[0].freq / peaks[l].freq > harmonic-.02) {
+ peaks[0].freq / peaks[l].freq > harmonic-.02) {
if (harmonic > (sint_t)maxharm &&
- peaks[0].db < peaks[l].db/2) {
+ peaks[0].db < peaks[l].db/2) {
maxharm = harmonic;
- k = l;
+ k = l;
}
}
}
--- a/src/pitchmcomb.c
+++ b/src/pitchmcomb.c
@@ -96,7 +96,7 @@
/* copy incoming grain to newmag */
for (j=0; j< newmag->length; j++)
newmag->data[i][j]=fftgrain->norm[i][j];
- /* detect only if local energy > 10. */
+ /* detect only if local energy > 10. */
//if (vec_local_energy(newmag)>10.) {
//hfc = vec_local_hfc(newmag); //not used
aubio_pitchmcomb_spectral_pp(p, newmag);
@@ -105,7 +105,7 @@
//return p->candidates[p->goodcandidate]->ebin;
j = (uint_t)FLOOR(p->candidates[p->goodcandidate]->ebin+.5);
instfreq = aubio_unwrap2pi(fftgrain->phas[0][j]
- - p->theta->data[0][j] - j*p->phasediff);
+ - p->theta->data[0][j] - j*p->phasediff);
instfreq *= p->phasefreq;
/* store phase for next run */
for (j=0; j< p->theta->length; j++) {
@@ -118,27 +118,27 @@
}*/
}
-uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain,
+uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain,
smpl_t * cands) {
uint_t i=0,j;
uint_t k;
fvec_t * newmag = (fvec_t *)p->newmag;
- aubio_spectralcandidate_t ** scands =
+ aubio_spectralcandidate_t ** scands =
(aubio_spectralcandidate_t **)(p->candidates);
//smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
/* copy incoming grain to newmag */
for (j=0; j< newmag->length; j++)
newmag->data[i][j]=fftgrain->norm[i][j];
- /* detect only if local energy > 10. */
- if (vec_local_energy(newmag)>10.) {
+ /* detect only if local energy > 10. */
+ if (vec_local_energy(newmag)>10.) {
/* hfc = vec_local_hfc(newmag); do not use */
aubio_pitchmcomb_spectral_pp(p, newmag);
aubio_pitchmcomb_combdet(p,newmag);
aubio_pitchmcomb_sort_cand_freq(scands,p->ncand);
- /* store ncand comb energies in cands[1:ncand] */
- for (k = 0; k<p->ncand; k++)
+ /* store ncand comb energies in cands[1:ncand] */
+ for (k = 0; k<p->ncand; k++)
cands[k] = p->candidates[k]->ene;
- /* store ncand[end] freq in cands[end] */
+ /* store ncand[end] freq in cands[end] */
cands[p->ncand] = p->candidates[p->ncand-1]->ebin;
return 1;
} else {
@@ -155,7 +155,7 @@
uint_t length = mag->length;
/* copy newmag to mag (scracth) */
for (j=0;j<length;j++) {
- mag->data[i][j] = newmag->data[i][j];
+ mag->data[i][j] = newmag->data[i][j];
}
vec_dc_removal(mag); /* dc removal */
vec_alpha_normalise(mag,p->alpha); /* alpha normalisation */
@@ -168,7 +168,7 @@
uint_t count;
/* return bin and ebin */
count = aubio_pitchmcomb_quadpick(peaks,mag);
- for (j=0;j<count;j++)
+ for (j=0;j<count;j++)
peaks[j].mag = newmag->data[i][peaks[j].bin];
/* reset non peaks */
for (j=count;j<length;j++)
@@ -180,7 +180,7 @@
void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag) {
aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;
- aubio_spectralcandidate_t ** candidate =
+ aubio_spectralcandidate_t ** candidate =
(aubio_spectralcandidate_t **)p->candidates;
/* parms */
@@ -223,9 +223,9 @@
/* for each in candidate[l]->ecomb[k] */
for (k=0;k<curlen;k++) {
xx = 100000.;
- /** get the candidate->ecomb the closer to peaks.ebin
+ /** get the candidate->ecomb the closer to peaks.ebin
* (to cope with the inharmonicity)*/
- for (d=0;d<count;d++) {
+ for (d=0;d<count;d++) {
delta2 = ABS(candidate[l]->ecomb[k]-peaks[d].ebin);
if (delta2 <= xx) {
position = d;
@@ -232,7 +232,7 @@
xx = delta2;
}
}
- /* for a Q factor of 17, maintaining "constant Q filtering",
+ /* for a Q factor of 17, maintaining "constant Q filtering",
* and sum energy and length over non null combs */
if ( 17. * xx < candidate[l]->ecomb[k] ) {
candidate[l]->ecomb[k]=peaks[position].ebin;
@@ -260,12 +260,12 @@
/** T=quadpick(X): return indices of elements of X which are peaks and positive
* exact peak positions are retrieved by quadratic interpolation
*
- * \bug peak-picking too picky, sometimes counts too many peaks ?
+ * \bug peak-picking too picky, sometimes counts too many peaks ?
*/
uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X){
uint_t i, j, ispeak, count = 0;
for (i=0;i<X->channels;i++)
- for (j=1;j<X->length-1;j++) {
+ for (j=1;j<X->length-1;j++) {
ispeak = vec_peakpick(X,j);
if (ispeak) {
count += ispeak;
@@ -289,7 +289,7 @@
}
void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins) {
- qsort(peaks, nbins, sizeof(aubio_spectralpeak_t),
+ qsort(peaks, nbins, sizeof(aubio_spectralpeak_t),
aubio_pitchmcomb_sort_peak_comp);
}
static sint_t aubio_pitchmcomb_sort_peak_comp(const void *x, const void *y) {
--- a/src/pitchyinfft.c
+++ b/src/pitchyinfft.c
@@ -35,54 +35,54 @@
};
static const smpl_t freqs[] = {0., 20., 25., 31.5, 40., 50., 63., 80., 100.,
- 125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
- 1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
- 12500., 15000., 20000., 25100};
+ 125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
+ 1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
+ 12500., 15000., 20000., 25100};
static const smpl_t weight[] = {-75.8, -70.1, -60.8, -52.1, -44.2, -37.5,
- -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
- -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
- -12.2, -7.4, -17.8, -17.8, -17.8};
+ -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
+ -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
+ -12.2, -7.4, -17.8, -17.8, -17.8};
aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize)
{
aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t);
- p->winput = new_fvec(bufsize,1);
- p->fft = new_aubio_fft(bufsize, 1);
- p->fftout = new_cvec(bufsize,1);
- p->sqrmag = new_fvec(bufsize,1);
- p->res = new_cvec(bufsize,1);
- p->yinfft = new_fvec(bufsize/2+1,1);
- p->win = new_fvec(bufsize,1);
+ p->winput = new_fvec(bufsize,1);
+ p->fft = new_aubio_fft(bufsize, 1);
+ p->fftout = new_cvec(bufsize,1);
+ p->sqrmag = new_fvec(bufsize,1);
+ p->res = new_cvec(bufsize,1);
+ p->yinfft = new_fvec(bufsize/2+1,1);
+ p->win = new_fvec(bufsize,1);
aubio_window(p->win->data[0], bufsize, aubio_win_hanningz);
p->weight = new_fvec(bufsize/2+1,1);
{
- uint_t i = 0, j = 1;
- smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
- for (i=0; i<p->weight->length; i++) {
- freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
- while (freq > freqs[j]) {
- j +=1;
- }
- a0 = weight[j-1];
- f0 = freqs[j-1];
- a1 = weight[j];
- f1 = freqs[j];
- if (f0 == f1) { // just in case
- p->weight->data[0][i] = a0;
- } else if (f0 == 0) { // y = ax+b
- p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
- } else {
- p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
- (a0 - (a1 - a0)/(f1/f0 - 1.));
- }
- while (freq > freqs[j]) {
- j +=1;
- }
- //AUBIO_DBG("%f\n",p->weight->data[0][i]);
- p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
- //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
- }
+ uint_t i = 0, j = 1;
+ smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
+ for (i=0; i<p->weight->length; i++) {
+ freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
+ while (freq > freqs[j]) {
+ j +=1;
+ }
+ a0 = weight[j-1];
+ f0 = freqs[j-1];
+ a1 = weight[j];
+ f1 = freqs[j];
+ if (f0 == f1) { // just in case
+ p->weight->data[0][i] = a0;
+ } else if (f0 == 0) { // y = ax+b
+ p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
+ } else {
+ p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
+ (a0 - (a1 - a0)/(f1/f0 - 1.));
+ }
+ while (freq > freqs[j]) {
+ j +=1;
+ }
+ //AUBIO_DBG("%f\n",p->weight->data[0][i]);
+ p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
+ //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
+ }
}
return p;
}
@@ -94,60 +94,60 @@
cvec_t * res = (cvec_t *)p->res;
fvec_t * yin = (fvec_t *)p->yinfft;
for (l=0; l < input->length; l++){
- p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
+ p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
}
aubio_fft_do(p->fft,p->winput,p->fftout);
for (l=0; l < p->fftout->length; l++){
- p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
- p->sqrmag->data[0][l] *= p->weight->data[0][l];
+ p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
+ p->sqrmag->data[0][l] *= p->weight->data[0][l];
}
for (l=1; l < p->fftout->length; l++){
- p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
- SQR(p->fftout->norm[0][l]);
- p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
- p->weight->data[0][l];
+ p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
+ SQR(p->fftout->norm[0][l]);
+ p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
+ p->weight->data[0][l];
}
for (l=0; l < p->sqrmag->length/2+1; l++) {
- sum += p->sqrmag->data[0][l];
+ sum += p->sqrmag->data[0][l];
}
sum *= 2.;
aubio_fft_do(p->fft,p->sqrmag,res);
- yin->data[0][0] = 1.;
+ yin->data[0][0] = 1.;
for (tau=1; tau < yin->length; tau++) {
- yin->data[0][tau] = sum -
- res->norm[0][tau]*COS(res->phas[0][tau]);
- tmp += yin->data[0][tau];
- yin->data[0][tau] *= tau/tmp;
+ yin->data[0][tau] = sum -
+ res->norm[0][tau]*COS(res->phas[0][tau]);
+ tmp += yin->data[0][tau];
+ yin->data[0][tau] *= tau/tmp;
}
- tau = vec_min_elem(yin);
+ tau = vec_min_elem(yin);
if (yin->data[0][tau] < tol) {
- /* no interpolation */
- //return tau;
- /* 3 point quadratic interpolation */
- //return vec_quadint_min(yin,tau,1);
- /* additional check for (unlikely) octave doubling in higher frequencies */
- if (tau>35) {
- return vec_quadint_min(yin,tau,1);
- } else {
- /* should compare the minimum value of each interpolated peaks */
- halfperiod = FLOOR(tau/2+.5);
- if (yin->data[0][halfperiod] < tol)
- return vec_quadint_min(yin,halfperiod,1);
- else
- return vec_quadint_min(yin,tau,1);
- }
+ /* no interpolation */
+ //return tau;
+ /* 3 point quadratic interpolation */
+ //return vec_quadint_min(yin,tau,1);
+ /* additional check for (unlikely) octave doubling in higher frequencies */
+ if (tau>35) {
+ return vec_quadint_min(yin,tau,1);
+ } else {
+ /* should compare the minimum value of each interpolated peaks */
+ halfperiod = FLOOR(tau/2+.5);
+ if (yin->data[0][halfperiod] < tol)
+ return vec_quadint_min(yin,halfperiod,1);
+ else
+ return vec_quadint_min(yin,tau,1);
+ }
} else
- return 0;
+ return 0;
}
void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){
- del_fvec(p->win);
- del_aubio_fft(p->fft);
- del_fvec(p->yinfft);
- del_fvec(p->sqrmag);
- del_cvec(p->res);
- del_cvec(p->fftout);
- del_fvec(p->winput);
- del_fvec(p->weight);
- AUBIO_FREE(p);
+ del_fvec(p->win);
+ del_aubio_fft(p->fft);
+ del_fvec(p->yinfft);
+ del_fvec(p->sqrmag);
+ del_cvec(p->res);
+ del_cvec(p->fftout);
+ del_fvec(p->winput);
+ del_fvec(p->weight);
+ AUBIO_FREE(p);
}