source: src/spectral/tss.c @ 59c046d

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

src/spectral/tss.c: simplify new_ method, add setters for threshold, alpha, and beta

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