Changeset b31f262 for src


Ignore:
Timestamp:
Jun 14, 2005, 1:07:08 AM (19 years ago)
Author:
Paul Brossier <piem@altern.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:
1397c6e
Parents:
0ce9acc3
Message:

add Kullback Liebler onset detection function and its modified version

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/onsetdetection.c

    r0ce9acc3 rb31f262  
    6868
    6969/* Complex Domain Method onset detection function */
    70 /* moved to /2 032402 */
    7170void aubio_onsetdetection_complex (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset) {
    7271        uint_t i, j;
     
    128127
    129128/* Spectral difference method onset detection function */
    130 /* moved to /2 032402 */
    131129void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o,
    132130                cvec_t * fftgrain, fvec_t * onset){
     
    157155}
    158156
     157/* Kullback Liebler onset detection function
     158 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
     159 * negative (1.+) and infinite values (+1.e-10) */
     160void aubio_onsetdetection_kl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){
     161        uint_t i,j;
     162        for (i=0;i<fftgrain->channels;i++) {
     163                onset->data[i][0] = 0.;
     164                for (j=0;j<fftgrain->length;j++) {
     165                        onset->data[i][0] += fftgrain->norm[i][j]
     166                                *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     167                        o->oldmag->data[i][j] = fftgrain->norm[i][j];
     168                }
     169                if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     170        }
     171}
     172
     173/* Modified Kullback Liebler onset detection function
     174 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
     175 * negative (1.+) and infinite values (+1.e-10) */
     176void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){
     177        uint_t i,j;
     178        for (i=0;i<fftgrain->channels;i++) {
     179                onset->data[i][0] = 0.;
     180                for (j=0;j<fftgrain->length;j++) {
     181                        onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     182                        o->oldmag->data[i][j] = fftgrain->norm[i][j];
     183                }
     184                if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     185        }
     186}
     187
    159188/* Generic function pointing to the choosen one */
    160189void
     
    205234                        o->threshold = 0.1;
    206235                        break;
     236                case kl:
     237                        o->oldmag = new_fvec(rsize,channels);
     238                        break;
     239                case mkl:
     240                        o->oldmag = new_fvec(rsize,channels);
     241                        break;
    207242                default:
    208243                        break;
     
    228263                case specdiff:
    229264                        o->funcpointer = aubio_onsetdetection_specdiff;
     265                        break;
     266                case kl:
     267                        o->funcpointer = aubio_onsetdetection_kl;
     268                        break;
     269                case mkl:
     270                        o->funcpointer = aubio_onsetdetection_mkl;
    230271                        break;
    231272                default:
  • src/onsetdetection.h

    r0ce9acc3 rb31f262  
    5454        hfc,            /**< high frequency content */
    5555        complexdomain,  /**< complex domain */       
    56         phase           /**< phase fast */           
     56        phase,          /**< phase fast */           
     57        kl,             /**< Kullback Liebler (Hainsworth et al.,  Onset detection in musical audio signals) */
     58        mkl             /**< modified Kullback Liebler (Hainsworth et al.,  Onset detection in musical audio signals) */
    5759} aubio_onsetdetection_type;
    5860
     
    99101 */
    100102void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
     103/** Kullback-Liebler onset detection function */
     104void aubio_onsetdetection_kl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
     105/** Modified Kullback-Liebler onset detection function */
     106void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
    101107/** Generic function pointing to the choosen one */
    102108void aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
Note: See TracChangeset for help on using the changeset viewer.