source: src/spectral/tss.c @ ed73bc6

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ed73bc6 was e6a78ea, checked in by Paul Brossier <piem@piem.org>, 15 years ago

src: update all headers to GPLv3

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[96fb8ad]1/*
[e6a78ea]2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
[96fb8ad]3
[e6a78ea]4  This file is part of aubio.
[96fb8ad]5
[e6a78ea]6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
[96fb8ad]10
[e6a78ea]11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
[96fb8ad]18
19*/
20
[f1b6aad]21/* default values : alpha=4, beta=3, threshold=0.25 */
[96fb8ad]22
23#include "aubio_priv.h"
[6c7d49b]24#include "fvec.h"
25#include "cvec.h"
[96fb8ad]26#include "mathutils.h"
[32d6958]27#include "spectral/tss.h"
[96fb8ad]28
[f1b6aad]29struct _aubio_tss_t
[96fb8ad]30{
[f1b6aad]31  smpl_t threshold;
32  smpl_t alpha;
[96fb8ad]33  smpl_t beta;
34  smpl_t parm;
[102b732]35  smpl_t thrsfact;
[96fb8ad]36  fvec_t *theta1;
37  fvec_t *theta2;
38  fvec_t *oft1;
39  fvec_t *oft2;
40  fvec_t *dev;
41};
42
43void aubio_tss_do(aubio_tss_t *o, cvec_t * input, 
44    cvec_t * trans, cvec_t * stead)
45{
46  uint_t i,j;
[f1b6aad]47  uint_t test;
[96fb8ad]48  uint_t nbins     = input->length;
49  uint_t channels  = input->channels;
[f1b6aad]50  smpl_t alpha     = o->alpha;
[96fb8ad]51  smpl_t beta      = o->beta;
52  smpl_t parm      = o->parm;
53  smpl_t ** dev    = (smpl_t **)o->dev->data;
54  smpl_t ** oft1   = (smpl_t **)o->oft1->data;
55  smpl_t ** oft2   = (smpl_t **)o->oft2->data;
56  smpl_t ** theta1 = (smpl_t **)o->theta1->data;
57  smpl_t ** theta2 = (smpl_t **)o->theta2->data;
58  /* second phase derivative */
59  for (i=0;i<channels; i++){
60    for (j=0;j<nbins; j++){
[28d8c4a]61      dev[i][j] = aubio_unwrap2pi(input->phas[i][j]
[96fb8ad]62          -2.0*theta1[i][j]+theta2[i][j]);
63      theta2[i][j] = theta1[i][j];
64      theta1[i][j] = input->phas[i][j];
65    }
66
67    for (j=0;j<nbins; j++){
68      /* transient analysis */
69      test = (ABS(dev[i][j]) > parm*oft1[i][j]);
70      trans->norm[i][j] = input->norm[i][j] * test;
71      trans->phas[i][j] = input->phas[i][j] * test;
72    }
73
74    for (j=0;j<nbins; j++){
75      /* steady state analysis */
76      test = (ABS(dev[i][j]) < parm*oft2[i][j]);
77      stead->norm[i][j] = input->norm[i][j] * test;
78      stead->phas[i][j] = input->phas[i][j] * test;
79
80      /*increase sstate probability for sines */
81      test = (trans->norm[i][j]==0.);
82      oft1[i][j]  = test;
83      test = (stead->norm[i][j]==0.);
84      oft2[i][j]  = test;
85      test = (trans->norm[i][j]>0.);
[f1b6aad]86      oft1[i][j] += alpha*test;
[96fb8ad]87      test = (stead->norm[i][j]>0.);
[f1b6aad]88      oft2[i][j] += alpha*test;
[96fb8ad]89      test = (oft1[i][j]>1. && trans->norm[i][j]>0.);
90      oft1[i][j] += beta*test;
91      test = (oft2[i][j]>1. && stead->norm[i][j]>0.);
92      oft2[i][j] += beta*test;
93    }
94  }
95}
96
[f1b6aad]97uint_t aubio_tss_set_threshold(aubio_tss_t *o, smpl_t threshold){
98  o->threshold = threshold;
99  o->parm = o->threshold * o->thrsfact;
100  return AUBIO_OK;
[102b732]101}
102
[f1b6aad]103aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size, uint_t channels)
[96fb8ad]104{
105  aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
[f1b6aad]106  uint_t rsize = buf_size/2+1;
107  o->threshold = 0.25;
108  o->thrsfact = TWO_PI*hop_size/rsize;
109  o->alpha = 3.;
110  o->beta = 4.;
111  o->parm = o->threshold*o->thrsfact;
[96fb8ad]112  o->theta1 = new_fvec(rsize,channels);
113  o->theta2 = new_fvec(rsize,channels);
114  o->oft1 = new_fvec(rsize,channels);
115  o->oft2 = new_fvec(rsize,channels);
116  o->dev = new_fvec(rsize,channels);
117  return o;
118}
119
120void del_aubio_tss(aubio_tss_t *s)
121{
122  free(s->theta1);
123  free(s->theta2);
124  free(s->oft1);
125  free(s->oft2);
126  free(s->dev);
127  free(s);
128}
129
[f1b6aad]130uint_t aubio_tss_set_alpha(aubio_tss_t *o, smpl_t alpha){
131  o->alpha = alpha;
132  return AUBIO_OK;
133}
134
135uint_t aubio_tss_set_beta(aubio_tss_t *o, smpl_t beta){
136  o->beta = beta;
137  return AUBIO_OK;
138}
139
Note: See TracBrowser for help on using the repository browser.