source: src/spectral/tss.c @ 17b7d66

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

remove src/sample.h

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[96fb8ad]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 : alfa=4, beta=3, threshold=0.25 */
21
22#include "aubio_priv.h"
[6c7d49b]23#include "fvec.h"
24#include "cvec.h"
[96fb8ad]25#include "mathutils.h"
[32d6958]26#include "spectral/tss.h"
[96fb8ad]27
28struct _aubio_tss_t
29{
30  smpl_t thrs;
31  smpl_t alfa;
32  smpl_t beta;
33  smpl_t parm;
[102b732]34  smpl_t thrsfact;
[96fb8ad]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 alfa      = o->alfa;
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++){
[28d8c4a]60      dev[i][j] = aubio_unwrap2pi(input->phas[i][j]
[96fb8ad]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] += alfa*test;
86      test = (stead->norm[i][j]>0.);
87      oft2[i][j] += alfa*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
[102b732]96void aubio_tss_set_thres(aubio_tss_t *o, smpl_t thrs){
97        o->thrs = thrs;
98        o->parm = thrs*o->thrsfact;
99}
100
[96fb8ad]101aubio_tss_t * new_aubio_tss(smpl_t thrs, smpl_t alfa, smpl_t beta, 
102    uint_t size, uint_t overlap,uint_t channels)
103{
104  aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
105  uint_t rsize = size/2+1;
106  o->thrs = thrs;
[102b732]107  o->thrsfact = TWO_PI*overlap/rsize;
[96fb8ad]108  o->alfa = alfa;       
109  o->beta = beta;       
[102b732]110  o->parm = thrs*o->thrsfact;
[96fb8ad]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
Note: See TracBrowser for help on using the repository browser.