[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" |
---|
| 23 | #include "sample.h" |
---|
| 24 | #include "mathutils.h" |
---|
| 25 | #include "tss.h" |
---|
| 26 | |
---|
| 27 | struct _aubio_tss_t |
---|
| 28 | { |
---|
| 29 | smpl_t thrs; |
---|
| 30 | smpl_t alfa; |
---|
| 31 | smpl_t beta; |
---|
| 32 | smpl_t parm; |
---|
[102b732] | 33 | smpl_t thrsfact; |
---|
[96fb8ad] | 34 | fvec_t *theta1; |
---|
| 35 | fvec_t *theta2; |
---|
| 36 | fvec_t *oft1; |
---|
| 37 | fvec_t *oft2; |
---|
| 38 | fvec_t *dev; |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | void aubio_tss_do(aubio_tss_t *o, cvec_t * input, |
---|
| 42 | cvec_t * trans, cvec_t * stead) |
---|
| 43 | { |
---|
| 44 | uint_t i,j; |
---|
| 45 | uint_t test; |
---|
| 46 | uint_t nbins = input->length; |
---|
| 47 | uint_t channels = input->channels; |
---|
| 48 | smpl_t alfa = o->alfa; |
---|
| 49 | smpl_t beta = o->beta; |
---|
| 50 | smpl_t parm = o->parm; |
---|
| 51 | smpl_t ** dev = (smpl_t **)o->dev->data; |
---|
| 52 | smpl_t ** oft1 = (smpl_t **)o->oft1->data; |
---|
| 53 | smpl_t ** oft2 = (smpl_t **)o->oft2->data; |
---|
| 54 | smpl_t ** theta1 = (smpl_t **)o->theta1->data; |
---|
| 55 | smpl_t ** theta2 = (smpl_t **)o->theta2->data; |
---|
| 56 | /* second phase derivative */ |
---|
| 57 | for (i=0;i<channels; i++){ |
---|
| 58 | for (j=0;j<nbins; j++){ |
---|
[28d8c4a] | 59 | dev[i][j] = aubio_unwrap2pi(input->phas[i][j] |
---|
[96fb8ad] | 60 | -2.0*theta1[i][j]+theta2[i][j]); |
---|
| 61 | theta2[i][j] = theta1[i][j]; |
---|
| 62 | theta1[i][j] = input->phas[i][j]; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | for (j=0;j<nbins; j++){ |
---|
| 66 | /* transient analysis */ |
---|
| 67 | test = (ABS(dev[i][j]) > parm*oft1[i][j]); |
---|
| 68 | trans->norm[i][j] = input->norm[i][j] * test; |
---|
| 69 | trans->phas[i][j] = input->phas[i][j] * test; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | for (j=0;j<nbins; j++){ |
---|
| 73 | /* steady state analysis */ |
---|
| 74 | test = (ABS(dev[i][j]) < parm*oft2[i][j]); |
---|
| 75 | stead->norm[i][j] = input->norm[i][j] * test; |
---|
| 76 | stead->phas[i][j] = input->phas[i][j] * test; |
---|
| 77 | |
---|
| 78 | /*increase sstate probability for sines */ |
---|
| 79 | test = (trans->norm[i][j]==0.); |
---|
| 80 | oft1[i][j] = test; |
---|
| 81 | test = (stead->norm[i][j]==0.); |
---|
| 82 | oft2[i][j] = test; |
---|
| 83 | test = (trans->norm[i][j]>0.); |
---|
| 84 | oft1[i][j] += alfa*test; |
---|
| 85 | test = (stead->norm[i][j]>0.); |
---|
| 86 | oft2[i][j] += alfa*test; |
---|
| 87 | test = (oft1[i][j]>1. && trans->norm[i][j]>0.); |
---|
| 88 | oft1[i][j] += beta*test; |
---|
| 89 | test = (oft2[i][j]>1. && stead->norm[i][j]>0.); |
---|
| 90 | oft2[i][j] += beta*test; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
[102b732] | 95 | void aubio_tss_set_thres(aubio_tss_t *o, smpl_t thrs){ |
---|
| 96 | o->thrs = thrs; |
---|
| 97 | o->parm = thrs*o->thrsfact; |
---|
| 98 | } |
---|
| 99 | |
---|
[96fb8ad] | 100 | aubio_tss_t * new_aubio_tss(smpl_t thrs, smpl_t alfa, smpl_t beta, |
---|
| 101 | uint_t size, uint_t overlap,uint_t channels) |
---|
| 102 | { |
---|
| 103 | aubio_tss_t * o = AUBIO_NEW(aubio_tss_t); |
---|
| 104 | uint_t rsize = size/2+1; |
---|
| 105 | o->thrs = thrs; |
---|
[102b732] | 106 | o->thrsfact = TWO_PI*overlap/rsize; |
---|
[96fb8ad] | 107 | o->alfa = alfa; |
---|
| 108 | o->beta = beta; |
---|
[102b732] | 109 | o->parm = thrs*o->thrsfact; |
---|
[96fb8ad] | 110 | o->theta1 = new_fvec(rsize,channels); |
---|
| 111 | o->theta2 = new_fvec(rsize,channels); |
---|
| 112 | o->oft1 = new_fvec(rsize,channels); |
---|
| 113 | o->oft2 = new_fvec(rsize,channels); |
---|
| 114 | o->dev = new_fvec(rsize,channels); |
---|
| 115 | return o; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void del_aubio_tss(aubio_tss_t *s) |
---|
| 119 | { |
---|
| 120 | free(s->theta1); |
---|
| 121 | free(s->theta2); |
---|
| 122 | free(s->oft1); |
---|
| 123 | free(s->oft2); |
---|
| 124 | free(s->dev); |
---|
| 125 | free(s); |
---|
| 126 | } |
---|
| 127 | |
---|