Ignore:
Timestamp:
Dec 4, 2009, 1:38:30 AM (14 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
741bdda
Parents:
0b9a02a
Message:

src/spectral: switch to mono

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/specdesc.c

    r0b9a02a rd95ff38  
    8989void aubio_specdesc_energy  (aubio_specdesc_t *o UNUSED,
    9090    cvec_t * fftgrain, fvec_t * onset) {
    91   uint_t i,j;
    92   for (i=0;i<fftgrain->channels;i++) {
    93     onset->data[i][0] = 0.;
    94     for (j=0;j<fftgrain->length;j++) {
    95       onset->data[i][0] += SQR(fftgrain->norm[i][j]);
    96     }
     91  uint_t j;
     92  onset->data[0] = 0.;
     93  for (j=0;j<fftgrain->length;j++) {
     94    onset->data[0] += SQR(fftgrain->norm[j]);
    9795  }
    9896}
     
    10199void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED,
    102100    cvec_t * fftgrain, fvec_t * onset){
    103   uint_t i,j;
    104   for (i=0;i<fftgrain->channels;i++) {
    105     onset->data[i][0] = 0.;
    106     for (j=0;j<fftgrain->length;j++) {
    107       onset->data[i][0] += (j+1)*fftgrain->norm[i][j];
    108     }
     101  uint_t j;
     102  onset->data[0] = 0.;
     103  for (j=0;j<fftgrain->length;j++) {
     104    onset->data[0] += (j+1)*fftgrain->norm[j];
    109105  }
    110106}
     
    113109/* Complex Domain Method onset detection function */
    114110void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) {
    115   uint_t i, j;
     111  uint_t j;
    116112  uint_t nbins = fftgrain->length;
    117   for (i=0;i<fftgrain->channels; i++)  {
    118     onset->data[i][0] = 0.;
    119     for (j=0;j<nbins; j++)  {
    120       // compute the predicted phase
    121       o->dev1->data[i][j] = 2. * o->theta1->data[i][j] - o->theta2->data[i][j];
    122       // compute the euclidean distance in the complex domain
    123       // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
    124       onset->data[i][0] +=
    125         SQRT (ABS (SQR (o->oldmag->data[i][j]) + SQR (fftgrain->norm[i][j])
    126               - 2. * o->oldmag->data[i][j] * fftgrain->norm[i][j]
    127               * COS (o->dev1->data[i][j] - fftgrain->phas[i][j])));
    128       /* swap old phase data (need to remember 2 frames behind)*/
    129       o->theta2->data[i][j] = o->theta1->data[i][j];
    130       o->theta1->data[i][j] = fftgrain->phas[i][j];
    131       /* swap old magnitude data (1 frame is enough) */
    132       o->oldmag->data[i][j] = fftgrain->norm[i][j];
    133     }
     113  onset->data[0] = 0.;
     114  for (j=0;j<nbins; j++)  {
     115    // compute the predicted phase
     116    o->dev1->data[j] = 2. * o->theta1->data[j] - o->theta2->data[j];
     117    // compute the euclidean distance in the complex domain
     118    // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
     119    onset->data[0] +=
     120      SQRT (ABS (SQR (o->oldmag->data[j]) + SQR (fftgrain->norm[j])
     121            - 2. * o->oldmag->data[j] * fftgrain->norm[j]
     122            * COS (o->dev1->data[j] - fftgrain->phas[j])));
     123    /* swap old phase data (need to remember 2 frames behind)*/
     124    o->theta2->data[j] = o->theta1->data[j];
     125    o->theta1->data[j] = fftgrain->phas[j];
     126    /* swap old magnitude data (1 frame is enough) */
     127    o->oldmag->data[j] = fftgrain->norm[j];
    134128  }
    135129}
     
    139133void aubio_specdesc_phase(aubio_specdesc_t *o,
    140134    cvec_t * fftgrain, fvec_t * onset){
    141   uint_t i, j;
     135  uint_t j;
    142136  uint_t nbins = fftgrain->length;
    143   for (i=0;i<fftgrain->channels; i++)  {
    144     onset->data[i][0] = 0.0;
    145     o->dev1->data[i][0]=0.;
    146     for ( j=0;j<nbins; j++ )  {
    147       o->dev1->data[i][j] =
    148         aubio_unwrap2pi(
    149             fftgrain->phas[i][j]
    150             -2.0*o->theta1->data[i][j]
    151             +o->theta2->data[i][j]);
    152       if ( o->threshold < fftgrain->norm[i][j] )
    153         o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
    154       else
    155         o->dev1->data[i][j] = 0.0;
    156       /* keep a track of the past frames */
    157       o->theta2->data[i][j] = o->theta1->data[i][j];
    158       o->theta1->data[i][j] = fftgrain->phas[i][j];
    159     }
    160     /* apply o->histogram */
    161     aubio_hist_dyn_notnull(o->histog,o->dev1);
    162     /* weight it */
    163     aubio_hist_weight(o->histog);
    164     /* its mean is the result */
    165     onset->data[i][0] = aubio_hist_mean(o->histog); 
    166     //onset->data[i][0] = fvec_mean(o->dev1);
    167   }
     137  onset->data[0] = 0.0;
     138  o->dev1->data[0]=0.;
     139  for ( j=0;j<nbins; j++ )  {
     140    o->dev1->data[j] =
     141      aubio_unwrap2pi(
     142          fftgrain->phas[j]
     143          -2.0*o->theta1->data[j]
     144          +o->theta2->data[j]);
     145    if ( o->threshold < fftgrain->norm[j] )
     146      o->dev1->data[j] = ABS(o->dev1->data[j]);
     147    else
     148      o->dev1->data[j] = 0.0;
     149    /* keep a track of the past frames */
     150    o->theta2->data[j] = o->theta1->data[j];
     151    o->theta1->data[j] = fftgrain->phas[j];
     152  }
     153  /* apply o->histogram */
     154  aubio_hist_dyn_notnull(o->histog,o->dev1);
     155  /* weight it */
     156  aubio_hist_weight(o->histog);
     157  /* its mean is the result */
     158  onset->data[0] = aubio_hist_mean(o->histog); 
     159  //onset->data[0] = fvec_mean(o->dev1);
    168160}
    169161
     
    171163void aubio_specdesc_specdiff(aubio_specdesc_t *o,
    172164    cvec_t * fftgrain, fvec_t * onset){
    173   uint_t i, j;
     165  uint_t j;
    174166  uint_t nbins = fftgrain->length;
    175   for (i=0;i<fftgrain->channels; i++)  {
    176     onset->data[i][0] = 0.0;
     167    onset->data[0] = 0.0;
    177168    for (j=0;j<nbins; j++)  {
    178       o->dev1->data[i][j] = SQRT(
    179           ABS(SQR( fftgrain->norm[i][j])
    180             - SQR(o->oldmag->data[i][j])));
    181       if (o->threshold < fftgrain->norm[i][j] )
    182         o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
     169      o->dev1->data[j] = SQRT(
     170          ABS(SQR( fftgrain->norm[j])
     171            - SQR(o->oldmag->data[j])));
     172      if (o->threshold < fftgrain->norm[j] )
     173        o->dev1->data[j] = ABS(o->dev1->data[j]);
    183174      else
    184         o->dev1->data[i][j] = 0.0;
    185       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     175        o->dev1->data[j] = 0.0;
     176      o->oldmag->data[j] = fftgrain->norm[j];
    186177    }
    187178
     
    192183    aubio_hist_weight(o->histog);
    193184    /* its mean is the result */
    194     onset->data[i][0] = aubio_hist_mean(o->histog); 
    195 
    196   }
     185    onset->data[0] = aubio_hist_mean(o->histog); 
    197186}
    198187
     
    201190 * negative (1.+) and infinite values (+1.e-10) */
    202191void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    203   uint_t i,j;
    204   for (i=0;i<fftgrain->channels;i++) {
    205     onset->data[i][0] = 0.;
     192  uint_t j;
     193    onset->data[0] = 0.;
    206194    for (j=0;j<fftgrain->length;j++) {
    207       onset->data[i][0] += fftgrain->norm[i][j]
    208         *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    209       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     195      onset->data[0] += fftgrain->norm[j]
     196        *LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
     197      o->oldmag->data[j] = fftgrain->norm[j];
    210198    }
    211     if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    212   }
     199    if (isnan(onset->data[0])) onset->data[0] = 0.;
    213200}
    214201
     
    217204 * negative (1.+) and infinite values (+1.e-10) */
    218205void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    219   uint_t i,j;
    220   for (i=0;i<fftgrain->channels;i++) {
    221     onset->data[i][0] = 0.;
     206  uint_t j;
     207    onset->data[0] = 0.;
    222208    for (j=0;j<fftgrain->length;j++) {
    223       onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    224       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     209      onset->data[0] += LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
     210      o->oldmag->data[j] = fftgrain->norm[j];
    225211    }
    226     if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    227   }
     212    if (isnan(onset->data[0])) onset->data[0] = 0.;
    228213}
    229214
    230215/* Spectral flux */
    231216void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    232   uint_t i, j;
    233   for (i=0;i<fftgrain->channels;i++) {
    234     onset->data[i][0] = 0.;
    235     for (j=0;j<fftgrain->length;j++) {
    236       if (fftgrain->norm[i][j] > o->oldmag->data[i][j])
    237         onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j];
    238       o->oldmag->data[i][j] = fftgrain->norm[i][j];
    239     }
     217  uint_t j;
     218  onset->data[0] = 0.;
     219  for (j=0;j<fftgrain->length;j++) {
     220    if (fftgrain->norm[j] > o->oldmag->data[j])
     221      onset->data[0] += fftgrain->norm[j] - o->oldmag->data[j];
     222    o->oldmag->data[j] = fftgrain->norm[j];
    240223  }
    241224}
     
    252235 */
    253236aubio_specdesc_t *
    254 new_aubio_specdesc (char_t * onset_mode,
    255     uint_t size, uint_t channels){
     237new_aubio_specdesc (char_t * onset_mode, uint_t size){
    256238  aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t);
    257239  uint_t rsize = size/2+1;
     
    303285      /* the other approaches will need some more memory spaces */
    304286    case aubio_onset_complex:
    305       o->oldmag = new_fvec(rsize,channels);
    306       o->dev1   = new_fvec(rsize,channels);
    307       o->theta1 = new_fvec(rsize,channels);
    308       o->theta2 = new_fvec(rsize,channels);
     287      o->oldmag = new_fvec(rsize);
     288      o->dev1   = new_fvec(rsize);
     289      o->theta1 = new_fvec(rsize);
     290      o->theta2 = new_fvec(rsize);
    309291      break;
    310292    case aubio_onset_phase:
    311       o->dev1   = new_fvec(rsize,channels);
    312       o->theta1 = new_fvec(rsize,channels);
    313       o->theta2 = new_fvec(rsize,channels);
    314       o->histog = new_aubio_hist(0.0, PI, 10, channels);
     293      o->dev1   = new_fvec(rsize);
     294      o->theta1 = new_fvec(rsize);
     295      o->theta2 = new_fvec(rsize);
     296      o->histog = new_aubio_hist(0.0, PI, 10);
    315297      o->threshold = 0.1;
    316298      break;
    317299    case aubio_onset_specdiff:
    318       o->oldmag = new_fvec(rsize,channels);
    319       o->dev1   = new_fvec(rsize,channels);
    320       o->histog = new_aubio_hist(0.0, PI, 10, channels);
     300      o->oldmag = new_fvec(rsize);
     301      o->dev1   = new_fvec(rsize);
     302      o->histog = new_aubio_hist(0.0, PI, 10);
    321303      o->threshold = 0.1;
    322304      break;
     
    324306    case aubio_onset_mkl:
    325307    case aubio_onset_specflux:
    326       o->oldmag = new_fvec(rsize,channels);
     308      o->oldmag = new_fvec(rsize);
    327309      break;
    328310    default:
Note: See TracChangeset for help on using the changeset viewer.