2 Copyright (C) 2003 Paul Brossier
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.
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.
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.
20 /* default values : alfa=4, beta=3, threshold=0.25 */
22 #include "aubio_priv.h"
24 #include "mathutils.h"
40 void aubio_tss_do(aubio_tss_t *o, cvec_t * input,
41 cvec_t * trans, cvec_t * stead)
45 uint_t nbins = input->length;
46 uint_t channels = input->channels;
47 smpl_t alfa = o->alfa;
48 smpl_t beta = o->beta;
49 smpl_t parm = o->parm;
50 smpl_t ** dev = (smpl_t **)o->dev->data;
51 smpl_t ** oft1 = (smpl_t **)o->oft1->data;
52 smpl_t ** oft2 = (smpl_t **)o->oft2->data;
53 smpl_t ** theta1 = (smpl_t **)o->theta1->data;
54 smpl_t ** theta2 = (smpl_t **)o->theta2->data;
55 /* second phase derivative */
56 for (i=0;i<channels; i++){
57 for (j=0;j<nbins; j++){
58 dev[i][j] = aubio_unwrap2pi(input->phas[i][j]
59 -2.0*theta1[i][j]+theta2[i][j]);
60 theta2[i][j] = theta1[i][j];
61 theta1[i][j] = input->phas[i][j];
64 for (j=0;j<nbins; j++){
65 /* transient analysis */
66 test = (ABS(dev[i][j]) > parm*oft1[i][j]);
67 trans->norm[i][j] = input->norm[i][j] * test;
68 trans->phas[i][j] = input->phas[i][j] * test;
71 for (j=0;j<nbins; j++){
72 /* steady state analysis */
73 test = (ABS(dev[i][j]) < parm*oft2[i][j]);
74 stead->norm[i][j] = input->norm[i][j] * test;
75 stead->phas[i][j] = input->phas[i][j] * test;
77 /*increase sstate probability for sines */
78 test = (trans->norm[i][j]==0.);
80 test = (stead->norm[i][j]==0.);
82 test = (trans->norm[i][j]>0.);
83 oft1[i][j] += alfa*test;
84 test = (stead->norm[i][j]>0.);
85 oft2[i][j] += alfa*test;
86 test = (oft1[i][j]>1. && trans->norm[i][j]>0.);
87 oft1[i][j] += beta*test;
88 test = (oft2[i][j]>1. && stead->norm[i][j]>0.);
89 oft2[i][j] += beta*test;
94 aubio_tss_t * new_aubio_tss(smpl_t thrs, smpl_t alfa, smpl_t beta,
95 uint_t size, uint_t overlap,uint_t channels)
97 aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
98 uint_t rsize = size/2+1;
102 o->parm = thrs*TWO_PI*overlap/rsize;
103 o->theta1 = new_fvec(rsize,channels);
104 o->theta2 = new_fvec(rsize,channels);
105 o->oft1 = new_fvec(rsize,channels);
106 o->oft2 = new_fvec(rsize,channels);
107 o->dev = new_fvec(rsize,channels);
111 void del_aubio_tss(aubio_tss_t *s)