- Timestamp:
- Dec 5, 2018, 10:34:39 PM (6 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 283a619a
- Parents:
- 5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 14 added
- 59 edited
Legend:
- Unmodified
- Added
- Removed
-
src/aubio.h
r5b46bc3 r633400d 110 110 111 111 Several examples of C programs are available in the \p examples/ and \p tests/src 112 directories of the source tree. See more examples: 113 @ref spectral/test-fft.c 114 @ref spectral/test-phasevoc.c 115 @ref onset/test-onset.c 116 @ref pitch/test-pitch.c 117 @ref tempo/test-tempo.c 118 @ref test-fvec.c 119 @ref test-cvec.c 112 directories of the source tree. 113 114 Some examples: 115 - @ref spectral/test-fft.c 116 - @ref spectral/test-phasevoc.c 117 - @ref onset/test-onset.c 118 - @ref pitch/test-pitch.c 119 - @ref tempo/test-tempo.c 120 - @ref test-fvec.c 121 - @ref test-cvec.c 120 122 121 123 \subsection unstable_api Unstable API … … 138 140 139 141 Latest versions, further documentation, examples, wiki, and mailing lists can 140 be found at http ://aubio.org .142 be found at https://aubio.org . 141 143 142 144 */ … … 181 183 #include "temporal/c_weighting.h" 182 184 #include "spectral/fft.h" 185 #include "spectral/dct.h" 183 186 #include "spectral/phasevoc.h" 184 187 #include "spectral/filterbank.h" … … 186 189 #include "spectral/mfcc.h" 187 190 #include "spectral/specdesc.h" 191 #include "spectral/awhitening.h" 188 192 #include "spectral/tss.h" 189 193 #include "pitch/pitch.h" … … 212 216 #include "pitch/pitchyin.h" 213 217 #include "pitch/pitchyinfft.h" 218 #include "pitch/pitchyinfast.h" 214 219 #include "pitch/pitchschmitt.h" 215 220 #include "pitch/pitchfcomb.h" -
src/aubio_priv.h
r5b46bc3 r633400d 34 34 */ 35 35 36 #ifdef HAVE_CONFIG_H 36 37 #include "config.h" 38 #endif 37 39 38 40 #ifdef HAVE_STDLIB_H … … 69 71 #endif 70 72 71 #if def HAVE_ACCELERATE73 #if defined(HAVE_ACCELERATE) 72 74 #define HAVE_ATLAS 1 75 #define HAVE_BLAS 1 73 76 #include <Accelerate/Accelerate.h> 74 77 #elif defined(HAVE_ATLAS_CBLAS_H) 78 #elif defined(HAVE_BLAS) 79 #if defined(HAVE_ATLAS_CBLAS_H) 75 80 #define HAVE_ATLAS 1 76 81 #include <atlas/cblas.h> 77 #else 78 #undef HAVE_ATLAS 82 #elif defined(HAVE_OPENBLAS_CBLAS_H) 83 #include <openblas/cblas.h> 84 #elif defined(HAVE_CBLAS_H) 85 #include <cblas.h> 86 #endif 79 87 #endif 80 88 … … 84 92 #define aubio_vDSP_mmov vDSP_mmov 85 93 #define aubio_vDSP_vmul vDSP_vmul 94 #define aubio_vDSP_vsmul vDSP_vsmul 95 #define aubio_vDSP_vsadd vDSP_vsadd 86 96 #define aubio_vDSP_vfill vDSP_vfill 87 97 #define aubio_vDSP_meanv vDSP_meanv … … 92 102 #define aubio_vDSP_minvi vDSP_minvi 93 103 #define aubio_vDSP_dotpr vDSP_dotpr 104 #define aubio_vDSP_vclr vDSP_vclr 94 105 #else /* HAVE_AUBIO_DOUBLE */ 95 106 #define aubio_vDSP_mmov vDSP_mmovD 96 107 #define aubio_vDSP_vmul vDSP_vmulD 108 #define aubio_vDSP_vsmul vDSP_vsmulD 109 #define aubio_vDSP_vsadd vDSP_vsaddD 97 110 #define aubio_vDSP_vfill vDSP_vfillD 98 111 #define aubio_vDSP_meanv vDSP_meanvD … … 103 116 #define aubio_vDSP_minvi vDSP_minviD 104 117 #define aubio_vDSP_dotpr vDSP_dotprD 118 #define aubio_vDSP_vclr vDSP_vclrD 105 119 #endif /* HAVE_AUBIO_DOUBLE */ 106 120 #endif /* HAVE_ACCELERATE */ 107 121 122 #if defined(HAVE_BLAS) 123 #ifndef HAVE_AUBIO_DOUBLE 108 124 #ifdef HAVE_ATLAS 109 #ifndef HAVE_AUBIO_DOUBLE110 125 #define aubio_catlas_set catlas_sset 126 #endif /* HAVE_ATLAS */ 111 127 #define aubio_cblas_copy cblas_scopy 112 128 #define aubio_cblas_swap cblas_sswap 113 129 #define aubio_cblas_dot cblas_sdot 114 130 #else /* HAVE_AUBIO_DOUBLE */ 131 #ifdef HAVE_ATLAS 115 132 #define aubio_catlas_set catlas_dset 133 #endif /* HAVE_ATLAS */ 116 134 #define aubio_cblas_copy cblas_dcopy 117 135 #define aubio_cblas_swap cblas_dswap 118 136 #define aubio_cblas_dot cblas_ddot 119 137 #endif /* HAVE_AUBIO_DOUBLE */ 120 #endif /* HAVE_ATLAS */ 121 122 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS) 138 #endif /* HAVE_BLAS */ 139 140 #if defined HAVE_INTEL_IPP 141 #include <ippcore.h> 142 #include <ippvm.h> 143 #include <ipps.h> 144 #ifndef HAVE_AUBIO_DOUBLE 145 #define aubio_ippsSet ippsSet_32f 146 #define aubio_ippsZero ippsZero_32f 147 #define aubio_ippsCopy ippsCopy_32f 148 #define aubio_ippsMul ippsMul_32f 149 #define aubio_ippsMulC ippsMulC_32f 150 #define aubio_ippsAddC ippsAddC_32f 151 #define aubio_ippsLn ippsLn_32f_A21 152 #define aubio_ippsMean(a,b,c) ippsMean_32f(a, b, c, ippAlgHintFast) 153 #define aubio_ippsSum(a,b,c) ippsSum_32f(a, b, c, ippAlgHintFast) 154 #define aubio_ippsMax ippsMax_32f 155 #define aubio_ippsMin ippsMin_32f 156 #else /* HAVE_AUBIO_DOUBLE */ 157 #define aubio_ippsSet ippsSet_64f 158 #define aubio_ippsZero ippsZero_64f 159 #define aubio_ippsCopy ippsCopy_64f 160 #define aubio_ippsMul ippsMul_64f 161 #define aubio_ippsMulC ippsMulC_64f 162 #define aubio_ippsAddC ippsAddC_64f 163 #define aubio_ippsLn ippsLn_64f_A26 164 #define aubio_ippsMean ippsMean_64f 165 #define aubio_ippsSum ippsSum_64f 166 #define aubio_ippsMax ippsMax_64f 167 #define aubio_ippsMin ippsMin_64f 168 #endif /* HAVE_AUBIO_DOUBLE */ 169 #endif 170 171 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS) && !defined(HAVE_INTEL_IPP) 123 172 #define HAVE_NOOPT 1 124 #else125 #undef HAVE_NOOPT126 173 #endif 127 174 … … 182 229 #ifdef HAVE_C99_VARARGS_MACROS 183 230 #define AUBIO_ERR(...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__) 231 #define AUBIO_INF(...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " __VA_ARGS__) 184 232 #define AUBIO_MSG(...) aubio_log(AUBIO_LOG_MSG, __VA_ARGS__) 185 233 #define AUBIO_DBG(...) aubio_log(AUBIO_LOG_DBG, __VA_ARGS__) 186 234 #define AUBIO_WRN(...) aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__) 187 235 #else 188 #define AUBIO_ERR(format, args...) aubio_log(stderr, "AUBIO ERROR: " format , ##args) 189 #define AUBIO_MSG(format, args...) aubio_log(stdout, format , ##args) 190 #define AUBIO_DBG(format, args...) aubio_log(stderr, format , ##args) 191 #define AUBIO_WRN(format, args...) aubio_log(stderr, "AUBIO WARNING: " format, ##args) 236 #define AUBIO_ERR(format, args...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " format , ##args) 237 #define AUBIO_INF(format, args...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " format , ##args) 238 #define AUBIO_MSG(format, args...) aubio_log(AUBIO_LOG_MSG, format , ##args) 239 #define AUBIO_DBG(format, args...) aubio_log(AUBIO_LOG_DBG, format , ##args) 240 #define AUBIO_WRN(format, args...) aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " format, ##args) 192 241 #endif 193 242 … … 196 245 #define AUBIO_QUIT(_s) exit(_s) 197 246 #define AUBIO_SPRINTF sprintf 247 248 #define AUBIO_MAX_SAMPLERATE (192000*8) 249 #define AUBIO_MAX_CHANNELS 1024 198 250 199 251 /* pi and 2*pi */ … … 221 273 #define FLOOR floorf 222 274 #define CEIL ceilf 275 #define ATAN atanf 223 276 #define ATAN2 atan2f 224 277 #else … … 233 286 #define FLOOR floor 234 287 #define CEIL ceil 288 #define ATAN atan 235 289 #define ATAN2 atan2 236 290 #endif -
src/cvec.c
r5b46bc3 r633400d 86 86 return; 87 87 } 88 #ifdef HAVE_MEMCPY_HACKS 88 #if defined(HAVE_INTEL_IPP) 89 aubio_ippsCopy(s->phas, t->phas, (int)s->length); 90 aubio_ippsCopy(s->norm, t->norm, (int)s->length); 91 #elif defined(HAVE_MEMCPY_HACKS) 89 92 memcpy(t->norm, s->norm, t->length * sizeof(smpl_t)); 90 93 memcpy(t->phas, s->phas, t->length * sizeof(smpl_t)); 91 #else /* HAVE_MEMCPY_HACKS */94 #else 92 95 uint_t j; 93 96 for (j=0; j< t->length; j++) { … … 95 98 t->phas[j] = s->phas[j]; 96 99 } 97 #endif /* HAVE_MEMCPY_HACKS */100 #endif 98 101 } 99 102 100 void cvec_norm_set_all (cvec_t *s, smpl_t val) { 103 void cvec_norm_set_all(cvec_t *s, smpl_t val) { 104 #if defined(HAVE_INTEL_IPP) 105 aubio_ippsSet(val, s->norm, (int)s->length); 106 #else 101 107 uint_t j; 102 108 for (j=0; j< s->length; j++) { 103 109 s->norm[j] = val; 104 110 } 111 #endif 105 112 } 106 113 107 114 void cvec_norm_zeros(cvec_t *s) { 108 #ifdef HAVE_MEMCPY_HACKS 115 #if defined(HAVE_INTEL_IPP) 116 aubio_ippsZero(s->norm, (int)s->length); 117 #elif defined(HAVE_MEMCPY_HACKS) 109 118 memset(s->norm, 0, s->length * sizeof(smpl_t)); 110 #else /* HAVE_MEMCPY_HACKS */119 #else 111 120 cvec_norm_set_all (s, 0.); 112 #endif /* HAVE_MEMCPY_HACKS */121 #endif 113 122 } 114 123 … … 118 127 119 128 void cvec_phas_set_all (cvec_t *s, smpl_t val) { 129 #if defined(HAVE_INTEL_IPP) 130 aubio_ippsSet(val, s->phas, (int)s->length); 131 #else 120 132 uint_t j; 121 133 for (j=0; j< s->length; j++) { 122 134 s->phas[j] = val; 123 135 } 136 #endif 124 137 } 125 138 126 139 void cvec_phas_zeros(cvec_t *s) { 127 #ifdef HAVE_MEMCPY_HACKS 140 #if defined(HAVE_INTEL_IPP) 141 aubio_ippsZero(s->phas, (int)s->length); 142 #elif defined(HAVE_MEMCPY_HACKS) 128 143 memset(s->phas, 0, s->length * sizeof(smpl_t)); 129 144 #else … … 140 155 cvec_phas_zeros(s); 141 156 } 157 158 void cvec_logmag(cvec_t *s, smpl_t lambda) { 159 #if defined(HAVE_INTEL_IPP) 160 aubio_ippsMulC(s->norm, lambda, s->norm, (int)s->length); 161 aubio_ippsAddC(s->norm, 1.0, s->norm, (int)s->length); 162 aubio_ippsLn(s->norm, s->norm, (int)s->length); 163 #else 164 uint_t j; 165 for (j=0; j< s->length; j++) { 166 s->norm[j] = LOG(lambda * s->norm[j] + 1); 167 } 168 #endif 169 } -
src/cvec.h
r5b46bc3 r633400d 231 231 void cvec_zeros(cvec_t *s); 232 232 233 /** take logarithmic magnitude 234 235 \param s input cvec to compress 236 \param lambda value to use for normalisation 237 238 \f$ S_k = log( \lambda * S_k + 1 ) \f$ 239 240 */ 241 void cvec_logmag(cvec_t *s, smpl_t lambda); 242 233 243 #ifdef __cplusplus 234 244 } -
src/fmat.c
r5b46bc3 r633400d 111 111 uint_t i,j; 112 112 for (i=0; i< s->height; i++) { 113 for (j=0; j< FLOOR( s->length/2); j++) {113 for (j=0; j< FLOOR((smpl_t)s->length/2); j++) { 114 114 ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]); 115 115 } … … 161 161 assert(s->length == scale->length); 162 162 #endif 163 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_ ATLAS)163 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_BLAS) 164 164 uint_t j; 165 165 fvec_zeros(output); … … 170 170 } 171 171 } 172 #elif defined(HAVE_ ATLAS)172 #elif defined(HAVE_BLAS) 173 173 for (k = 0; k < s->height; k++) { 174 174 output->data[k] = aubio_cblas_dot( s->length, scale->data, 1, s->data[k], 1); -
src/fvec.c
r5b46bc3 r633400d 61 61 62 62 void fvec_set_all (fvec_t *s, smpl_t val) { 63 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS) 64 uint_t j; 65 for (j=0; j< s->length; j++) { 66 s->data[j] = val; 67 } 63 #if defined(HAVE_INTEL_IPP) 64 aubio_ippsSet(val, s->data, (int)s->length); 68 65 #elif defined(HAVE_ATLAS) 69 66 aubio_catlas_set(s->length, val, s->data, 1); 70 67 #elif defined(HAVE_ACCELERATE) 71 68 aubio_vDSP_vfill(&val, s->data, 1, s->length); 69 #else 70 uint_t j; 71 for ( j = 0; j< s->length; j++ ) 72 { 73 s->data[j] = val; 74 } 72 75 #endif 73 76 } 74 77 75 78 void fvec_zeros(fvec_t *s) { 76 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) 77 fvec_set_all (s, 0.); 78 #else 79 #if defined(HAVE_MEMCPY_HACKS) 79 #if defined(HAVE_INTEL_IPP) 80 aubio_ippsZero(s->data, (int)s->length); 81 #elif defined(HAVE_ACCELERATE) 82 aubio_vDSP_vclr(s->data, 1, s->length); 83 #elif defined(HAVE_MEMCPY_HACKS) 80 84 memset(s->data, 0, s->length * sizeof(smpl_t)); 81 85 #else 82 aubio_vDSP_vclr(s->data, 1, s->length); 83 #endif 86 fvec_set_all(s, 0.); 84 87 #endif 85 88 } … … 91 94 void fvec_rev(fvec_t *s) { 92 95 uint_t j; 93 for (j=0; j< FLOOR( s->length/2); j++) {96 for (j=0; j< FLOOR((smpl_t)s->length/2); j++) { 94 97 ELEM_SWAP(s->data[j], s->data[s->length-1-j]); 95 98 } … … 97 100 98 101 void fvec_weight(fvec_t *s, const fvec_t *weight) { 99 #ifndef HAVE_ACCELERATE 102 uint_t length = MIN(s->length, weight->length); 103 #if defined(HAVE_INTEL_IPP) 104 aubio_ippsMul(s->data, weight->data, s->data, (int)length); 105 #elif defined(HAVE_ACCELERATE) 106 aubio_vDSP_vmul( s->data, 1, weight->data, 1, s->data, 1, length ); 107 #else 100 108 uint_t j; 101 uint_t length = MIN(s->length, weight->length); 102 for (j=0; j< length; j++) { 109 for (j = 0; j < length; j++) { 103 110 s->data[j] *= weight->data[j]; 104 111 } 105 #else106 aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);107 112 #endif /* HAVE_ACCELERATE */ 108 113 } 109 114 110 115 void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) { 111 #ifndef HAVE_ACCELERATE 116 uint_t length = MIN(in->length, MIN(out->length, weight->length)); 117 #if defined(HAVE_INTEL_IPP) 118 aubio_ippsMul(in->data, weight->data, out->data, (int)length); 119 #elif defined(HAVE_ACCELERATE) 120 aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, length); 121 #else 112 122 uint_t j; 113 uint_t length = MIN(out->length, weight->length); 114 for (j=0; j< length; j++) { 123 for (j = 0; j < length; j++) { 115 124 out->data[j] = in->data[j] * weight->data[j]; 116 125 } 117 #else 118 aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length); 119 #endif /* HAVE_ACCELERATE */ 126 #endif 120 127 } 121 128 … … 126 133 return; 127 134 } 128 #ifdef HAVE_NOOPT 129 uint_t j; 130 for (j=0; j< t->length; j++) { 131 t->data[j] = s->data[j]; 132 } 133 #elif defined(HAVE_MEMCPY_HACKS) 134 memcpy(t->data, s->data, t->length * sizeof(smpl_t)); 135 #elif defined(HAVE_ATLAS) 135 #if defined(HAVE_INTEL_IPP) 136 aubio_ippsCopy(s->data, t->data, (int)s->length); 137 #elif defined(HAVE_BLAS) 136 138 aubio_cblas_copy(s->length, s->data, 1, t->data, 1); 137 139 #elif defined(HAVE_ACCELERATE) 138 140 aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1); 141 #elif defined(HAVE_MEMCPY_HACKS) 142 memcpy(t->data, s->data, t->length * sizeof(smpl_t)); 143 #else 144 uint_t j; 145 for (j = 0; j < t->length; j++) { 146 t->data[j] = s->data[j]; 147 } 139 148 #endif 140 149 } -
src/io/audio_unit.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include " config.h"21 #include "aubio_priv.h" 22 22 #ifdef HAVE_AUDIO_UNIT 23 #include "aubio_priv.h"24 23 25 24 #include "fvec.h" -
src/io/sink.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "fvec.h" … … 99 98 } 100 99 #endif /* HAVE_WAVWRITE */ 101 AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n", 102 uri, samplerate); 100 #if !defined(HAVE_WAVWRITE) && \ 101 !defined(HAVE_SNDFILE) && \ 102 !defined(HAVE_SINK_APPLE_AUDIO) 103 AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate); 104 #endif 103 105 AUBIO_FREE(s); 104 106 return NULL; -
src/io/sink_apple_audio.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include " config.h"21 #include "aubio_priv.h" 22 22 23 23 #ifdef HAVE_SINK_APPLE_AUDIO 24 25 #include "aubio_priv.h"26 24 #include "fvec.h" 27 25 #include "fmat.h" 28 26 #include "io/sink_apple_audio.h" 27 #include "io/ioutils.h" 29 28 30 29 // CFURLRef, CFURLCreateWithFileSystemPath, ... … … 63 62 s->async = false; 64 63 65 if ( uri == NULL) {64 if ( (uri == NULL) || (strlen(uri) < 1) ) { 66 65 AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n"); 67 66 goto beach; … … 74 73 s->channels = 0; 75 74 76 // negative samplerate given, abort77 if ((sint_t)samplerate < 0) goto beach;78 75 // zero samplerate given. do not open yet 79 if ((sint_t)samplerate == 0) return s; 76 if ((sint_t)samplerate == 0) { 77 return s; 78 } 79 // invalid samplerate given, abort 80 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) { 81 goto beach; 82 } 80 83 81 84 s->samplerate = samplerate; … … 95 98 uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate) 96 99 { 97 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 100 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) { 101 return AUBIO_FAIL; 102 } 98 103 s->samplerate = samplerate; 99 104 // automatically open when both samplerate and channels have been set … … 106 111 uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels) 107 112 { 108 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 113 if (aubio_io_validate_channels("sink_apple_audio", s->path, channels)) { 114 return AUBIO_FAIL; 115 } 109 116 s->channels = channels; 110 117 // automatically open when both samplerate and channels have been set -
src/io/sink_sndfile.c
r5b46bc3 r633400d 20 20 21 21 22 #include " config.h"22 #include "aubio_priv.h" 23 23 24 24 #ifdef HAVE_SNDFILE … … 26 26 #include <sndfile.h> 27 27 28 #include "aubio_priv.h"29 28 #include "fvec.h" 30 29 #include "fmat.h" 31 30 #include "io/sink_sndfile.h" 32 33 #define MAX_CHANNELS 6 31 #include "io/ioutils.h" 32 34 33 #define MAX_SIZE 4096 35 34 … … 70 69 s->channels = 0; 71 70 72 // negative samplerate given, abort73 if ((sint_t)samplerate < 0) goto beach;74 71 // zero samplerate given. do not open yet 75 if ((sint_t)samplerate == 0) return s; 72 if ((sint_t)samplerate == 0) { 73 return s; 74 } 75 // invalid samplerate given, abort 76 if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) { 77 goto beach; 78 } 76 79 77 80 s->samplerate = samplerate; … … 90 93 uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate) 91 94 { 92 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 95 if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) { 96 return AUBIO_FAIL; 97 } 93 98 s->samplerate = samplerate; 94 99 // automatically open when both samplerate and channels have been set … … 101 106 uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels) 102 107 { 103 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 108 if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) { 109 return AUBIO_FAIL; 110 } 104 111 s->channels = channels; 105 112 // automatically open when both samplerate and channels have been set … … 133 140 if (s->handle == NULL) { 134 141 /* show libsndfile err msg */ 135 AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL)); 142 AUBIO_ERR("sink_sndfile: Failed opening \"%s\" with %d channels, %dHz: %s\n", 143 s->path, s->channels, s->samplerate, sf_strerror (NULL)); 136 144 return AUBIO_FAIL; 137 145 } … … 139 147 s->scratch_size = s->max_size*s->channels; 140 148 /* allocate data for de/interleaving reallocated when needed. */ 141 if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) { 149 if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) { 150 abort(); 142 151 AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n", 143 s->max_size, s->channels, MAX_ CHANNELS *MAX_CHANNELS);152 s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS); 144 153 return AUBIO_FAIL; 145 154 } -
src/io/sink_wavwrite.c
r5b46bc3 r633400d 20 20 21 21 22 #include " config.h"22 #include "aubio_priv.h" 23 23 24 24 #ifdef HAVE_WAVWRITE 25 25 26 #include "aubio_priv.h"27 26 #include "fvec.h" 28 27 #include "fmat.h" 29 28 #include "io/sink_wavwrite.h" 29 #include "io/ioutils.h" 30 30 31 31 #include <errno.h> 32 32 33 #define MAX_CHANNELS 634 33 #define MAX_SIZE 4096 35 34 … … 105 104 s->channels = 0; 106 105 107 // negative samplerate given, abort108 if ((sint_t)samplerate < 0) goto beach;109 106 // zero samplerate given. do not open yet 110 if ((sint_t)samplerate == 0) return s; 111 // samplerate way too large, fail 112 if ((sint_t)samplerate > 192000 * 4) goto beach; 107 if ((sint_t)samplerate == 0) { 108 return s; 109 } 110 // invalid samplerate given, abort 111 if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) { 112 goto beach; 113 } 113 114 114 115 s->samplerate = samplerate; … … 130 131 uint_t aubio_sink_wavwrite_preset_samplerate(aubio_sink_wavwrite_t *s, uint_t samplerate) 131 132 { 132 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 133 if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) { 134 return AUBIO_FAIL; 135 } 133 136 s->samplerate = samplerate; 134 137 // automatically open when both samplerate and channels have been set … … 141 144 uint_t aubio_sink_wavwrite_preset_channels(aubio_sink_wavwrite_t *s, uint_t channels) 142 145 { 143 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 146 if (aubio_io_validate_channels("sink_wavwrite", s->path, channels)) { 147 return AUBIO_FAIL; 148 } 144 149 s->channels = channels; 145 150 // automatically open when both samplerate and channels have been set … … 214 219 s->scratch_size = s->max_size * s->channels; 215 220 /* allocate data for de/interleaving reallocated when needed. */ 216 if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {221 if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) { 217 222 AUBIO_ERR("sink_wavwrite: %d x %d exceeds SIZE maximum buffer size %d\n", 218 s->max_size, s->channels, MAX_SIZE * MAX_CHANNELS);223 s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS); 219 224 goto beach; 220 225 } -
src/io/source.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "fvec.h" … … 116 115 } 117 116 #endif /* HAVE_WAVREAD */ 118 AUBIO_ERROR("source: failed creating aubio source with %s" 119 " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size); 117 #if !defined(HAVE_WAVREAD) && \ 118 !defined(HAVE_LIBAV) && \ 119 !defined(HAVE_SOURCE_APPLE_AUDIO) && \ 120 !defined(HAVE_SNDFILE) 121 AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d" 122 " (no source built-in)\n", uri, samplerate, hop_size); 123 #endif 120 124 AUBIO_FREE(s); 121 125 return NULL; -
src/io/source_apple_audio.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include " config.h"21 #include "aubio_priv.h" 22 22 23 23 #ifdef HAVE_SOURCE_APPLE_AUDIO 24 24 25 #include "aubio_priv.h"26 25 #include "fvec.h" 27 26 #include "fmat.h" … … 281 280 { 282 281 OSStatus err = noErr; 283 if (!s->audioFile) { return AUBIO_ FAIL; }282 if (!s->audioFile) { return AUBIO_OK; } 284 283 err = ExtAudioFileDispose(s->audioFile); 285 284 s->audioFile = NULL; -
src/io/source_avcodec.c
r5b46bc3 r633400d 19 19 */ 20 20 21 22 #include "config.h" 21 #include "aubio_priv.h" 23 22 24 23 #ifdef HAVE_LIBAV 24 25 #include <libavcodec/avcodec.h> 26 #include <libavformat/avformat.h> 27 #if defined(HAVE_SWRESAMPLE) 28 #include <libswresample/swresample.h> 29 #elif defined(HAVE_AVRESAMPLE) 30 #include <libavresample/avresample.h> 31 #endif 32 #include <libavutil/opt.h> 33 #include <stdlib.h> 25 34 26 35 // determine whether we use libavformat from ffmpeg or from libav 27 36 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 ) 28 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through57.2.10037 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 -> 57.2.100 29 38 #define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \ 30 39 (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \ … … 33 42 ) 34 43 35 #include <libavcodec/avcodec.h> 36 #include <libavformat/avformat.h> 37 #include <libavresample/avresample.h> 38 #include <libavutil/opt.h> 39 #include <stdlib.h> 44 // backward compatibility with libavcodec55 45 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0) 46 #define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1 47 #endif 48 49 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) 50 #warning "libavcodec < 56 is deprecated" 51 #define av_frame_alloc avcodec_alloc_frame 52 #define av_frame_free avcodec_free_frame 53 #define av_packet_unref av_free_packet 54 #endif 40 55 41 56 #include "aubio_priv.h" … … 44 59 #include "source_avcodec.h" 45 60 61 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56, 56, 0) 46 62 #define AUBIO_AVCODEC_MAX_BUFFER_SIZE FF_MIN_BUFFER_SIZE 63 #else 64 #define AUBIO_AVCODEC_MAX_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE 65 #endif 47 66 48 67 struct _aubio_source_avcodec_t { … … 60 79 AVCodecContext *avCodecCtx; 61 80 AVFrame *avFrame; 81 AVPacket avPacket; 82 #ifdef HAVE_AVRESAMPLE 62 83 AVAudioResampleContext *avr; 63 float *output; 84 #elif defined(HAVE_SWRESAMPLE) 85 SwrContext *avr; 86 #endif 87 smpl_t *output; 64 88 uint_t read_samples; 65 89 uint_t read_index; 66 90 sint_t selected_stream; 67 91 uint_t eof; 68 uint_t multi;69 92 }; 70 93 71 // hack to create or re-create the context the first time _do or _do_multi is called 72 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi); 73 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples); 94 // create or re-create the context when _do or _do_multi is called 95 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s); 96 // actually read a frame 97 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, 98 uint_t * read_samples); 74 99 75 100 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s); … … 88 113 89 114 90 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { 115 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, 116 uint_t samplerate, uint_t hop_size) { 91 117 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 118 AVFormatContext *avFormatCtx = s->avFormatCtx; 119 AVCodecContext *avCodecCtx = s->avCodecCtx; 120 AVFrame *avFrame = s->avFrame; 121 sint_t selected_stream = -1; 122 #if FF_API_LAVF_AVCTX 123 AVCodecParameters *codecpar; 124 #endif 125 AVCodec *codec; 126 uint_t i; 92 127 int err; 93 128 if (path == NULL) { … … 96 131 } 97 132 if ((sint_t)samplerate < 0) { 98 AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n", path, samplerate); 133 AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n", 134 path, samplerate); 99 135 goto beach; 100 136 } 101 137 if ((sint_t)hop_size <= 0) { 102 AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n", path, hop_size); 138 AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n", 139 path, hop_size); 103 140 goto beach; 104 141 } … … 111 148 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 112 149 150 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,0,0) 113 151 // register all formats and codecs 114 152 av_register_all(); 153 #endif 115 154 116 155 if (aubio_source_avcodec_has_network_url(s)) { … … 119 158 120 159 // try opening the file and get some info about it 121 AVFormatContext *avFormatCtx = s->avFormatCtx;122 160 avFormatCtx = NULL; 123 161 if ( (err = avformat_open_input(&avFormatCtx, s->path, NULL, NULL) ) < 0 ) { … … 139 177 char errorstr[256]; 140 178 av_strerror (err, errorstr, sizeof(errorstr)); 141 AUBIO_ERR("source_avcodec: Could not find stream information " "for %s (%s)\n", s->path,142 errorstr);179 AUBIO_ERR("source_avcodec: Could not find stream information " 180 "for %s (%s)\n", s->path, errorstr); 143 181 goto beach; 144 182 } … … 148 186 149 187 // look for the first audio stream 150 uint_t i;151 sint_t selected_stream = -1;152 188 for (i = 0; i < avFormatCtx->nb_streams; i++) { 189 #if FF_API_LAVF_AVCTX 190 if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { 191 #else 153 192 if (avFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { 193 #endif 154 194 if (selected_stream == -1) { 155 195 selected_stream = i; … … 167 207 s->selected_stream = selected_stream; 168 208 169 AVCodecContext *avCodecCtx = s->avCodecCtx; 209 #if FF_API_LAVF_AVCTX 210 codecpar = avFormatCtx->streams[selected_stream]->codecpar; 211 if (codecpar == NULL) { 212 AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path); 213 goto beach; 214 } 215 codec = avcodec_find_decoder(codecpar->codec_id); 216 217 /* Allocate a codec context for the decoder */ 218 avCodecCtx = avcodec_alloc_context3(codec); 219 if (!avCodecCtx) { 220 AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context " 221 "for path %s\n", av_get_media_type_string(AVMEDIA_TYPE_AUDIO), 222 s->path); 223 goto beach; 224 } 225 #else 170 226 avCodecCtx = avFormatCtx->streams[selected_stream]->codec; 171 AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id); 227 codec = avcodec_find_decoder(avCodecCtx->codec_id); 228 #endif 172 229 if (codec == NULL) { 173 230 AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path); 174 231 goto beach; 175 232 } 233 234 #if FF_API_LAVF_AVCTX 235 /* Copy codec parameters from input stream to output codec context */ 236 if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) { 237 AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to " 238 "decoder context for %s\n", 239 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 240 goto beach; 241 } 242 #endif 176 243 177 244 if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) { 178 245 char errorstr[256]; 179 246 av_strerror (err, errorstr, sizeof(errorstr)); 180 AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path, errorstr); 247 AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path, 248 errorstr); 181 249 goto beach; 182 250 } … … 199 267 } 200 268 201 AVFrame *avFrame = s->avFrame;202 269 avFrame = av_frame_alloc(); 203 270 if (!avFrame) { … … 206 273 207 274 /* allocate output for avr */ 208 s->output = (float *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(float)); 275 s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE 276 * sizeof(smpl_t)); 209 277 210 278 s->read_samples = 0; … … 215 283 s->avFrame = avFrame; 216 284 217 // default to mono output 218 aubio_source_avcodec_reset_resampler(s, 0); 285 aubio_source_avcodec_reset_resampler(s); 286 287 if (s->avr == NULL) goto beach; 219 288 220 289 s->eof = 0; 221 s->multi = 0;222 290 223 291 //av_log_set_level(AV_LOG_QUIET); … … 232 300 } 233 301 234 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi) { 235 if ( (multi != s->multi) || (s->avr == NULL) ) { 302 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s) 303 { 304 // create or reset resampler to/from mono/multi-channel 305 if ( s->avr == NULL ) { 306 int err; 236 307 int64_t input_layout = av_get_default_channel_layout(s->input_channels); 237 uint_t output_channels = multi ? s->input_channels : 1; 238 int64_t output_layout = av_get_default_channel_layout(output_channels); 239 if (s->avr != NULL) { 240 avresample_close( s->avr ); 241 av_free ( s->avr ); 242 s->avr = NULL; 243 } 244 AVAudioResampleContext *avr = s->avr; 245 avr = avresample_alloc_context(); 246 247 av_opt_set_int(avr, "in_channel_layout", input_layout, 0); 248 av_opt_set_int(avr, "out_channel_layout", output_layout, 0); 249 av_opt_set_int(avr, "in_sample_rate", s->input_samplerate, 0); 250 av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0); 308 int64_t output_layout = av_get_default_channel_layout(s->input_channels); 309 #ifdef HAVE_AVRESAMPLE 310 AVAudioResampleContext *avr = avresample_alloc_context(); 311 #elif defined(HAVE_SWRESAMPLE) 312 SwrContext *avr = swr_alloc(); 313 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 314 315 av_opt_set_int(avr, "in_channel_layout", input_layout, 0); 316 av_opt_set_int(avr, "out_channel_layout", output_layout, 0); 317 av_opt_set_int(avr, "in_sample_rate", s->input_samplerate, 0); 318 av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0); 251 319 av_opt_set_int(avr, "in_sample_fmt", s->avCodecCtx->sample_fmt, 0); 252 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); 253 int err; 254 if ( ( err = avresample_open(avr) ) < 0) { 320 #if HAVE_AUBIO_DOUBLE 321 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0); 322 #else 323 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); 324 #endif 325 // TODO: use planar? 326 //av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 327 #ifdef HAVE_AVRESAMPLE 328 if ( ( err = avresample_open(avr) ) < 0) 329 #elif defined(HAVE_SWRESAMPLE) 330 if ( ( err = swr_init(avr) ) < 0) 331 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 332 { 255 333 char errorstr[256]; 256 334 av_strerror (err, errorstr, sizeof(errorstr)); 257 AUBIO_ERR("source_avcodec: Could not open AVAudioResampleContext for %s (%s)\n", 258 s->path, errorstr); 259 //goto beach; 335 AUBIO_ERR("source_avcodec: Could not open resampling context" 336 " for %s (%s)\n", s->path, errorstr); 260 337 return; 261 338 } 262 339 s->avr = avr; 263 s->multi = multi; 264 } 265 } 266 267 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples) { 340 } 341 } 342 343 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, 344 uint_t * read_samples) 345 { 268 346 AVFormatContext *avFormatCtx = s->avFormatCtx; 269 347 AVCodecContext *avCodecCtx = s->avCodecCtx; 270 348 AVFrame *avFrame = s->avFrame; 271 AVPacket avPacket; 349 AVPacket avPacket = s->avPacket; 350 #ifdef HAVE_AVRESAMPLE 351 AVAudioResampleContext *avr = s->avr; 352 #elif defined(HAVE_SWRESAMPLE) 353 SwrContext *avr = s->avr; 354 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 355 int got_frame = 0; 356 #ifdef HAVE_AVRESAMPLE 357 int in_linesize = 0; 358 int in_samples = avFrame->nb_samples; 359 int out_linesize = 0; 360 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE; 361 int out_samples = 0; 362 #elif defined(HAVE_SWRESAMPLE) 363 int in_samples = avFrame->nb_samples; 364 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; 365 int out_samples = 0; 366 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 367 smpl_t *output = s->output; 368 #ifndef FF_API_LAVF_AVCTX 369 int len = 0; 370 #else 371 int ret = 0; 372 #endif 272 373 av_init_packet (&avPacket); 273 AVAudioResampleContext *avr = s->avr;274 float *output = s->output;275 374 *read_samples = 0; 276 375 … … 285 384 char errorstr[256]; 286 385 av_strerror (err, errorstr, sizeof(errorstr)); 287 AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr); 386 AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", 387 s->path, errorstr); 388 s->eof = 1; 288 389 goto beach; 289 390 } 290 391 } while (avPacket.stream_index != s->selected_stream); 291 392 292 int got_frame = 0; 293 int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket); 393 #if FF_API_LAVF_AVCTX 394 ret = avcodec_send_packet(avCodecCtx, &avPacket); 395 if (ret < 0 && ret != AVERROR_EOF) { 396 AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); 397 goto beach; 398 } 399 ret = avcodec_receive_frame(avCodecCtx, avFrame); 400 if (ret >= 0) { 401 got_frame = 1; 402 } 403 if (ret < 0) { 404 if (ret == AVERROR(EAGAIN)) { 405 //AUBIO_WRN("source_avcodec: output is not available right now - " 406 // "user must try to send new input\n"); 407 goto beach; 408 } else if (ret == AVERROR_EOF) { 409 AUBIO_WRN("source_avcodec: the decoder has been fully flushed, " 410 "and there will be no more output frames\n"); 411 } else { 412 AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path); 413 goto beach; 414 } 415 } 416 #else 417 len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket); 294 418 295 419 if (len < 0) { 296 AUBIO_ERR("Error while decoding %s\n", s->path); 297 goto beach; 298 } 420 AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path); 421 goto beach; 422 } 423 #endif 299 424 if (got_frame == 0) { 300 //AUBIO_ERR("Could not get frame for (%s)\n", s->path); 301 goto beach; 302 } 303 304 int in_linesize = 0; 425 AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n", 426 s->path); 427 goto beach; 428 } 429 430 #if LIBAVUTIL_VERSION_MAJOR > 52 431 if (avFrame->channels != (sint_t)s->input_channels) { 432 AUBIO_WRN ("source_avcodec: trying to read from %d channel(s)," 433 "but configured for %d; is '%s' corrupt?\n", 434 avFrame->channels, s->input_channels, s->path); 435 goto beach; 436 } 437 #else 438 #warning "avutil < 53 is deprecated, crashes might occur on corrupt files" 439 #endif 440 441 #ifdef HAVE_AVRESAMPLE 442 in_linesize = 0; 305 443 av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels, 306 444 avFrame->nb_samples, avCodecCtx->sample_fmt, 1); 307 in t in_samples = avFrame->nb_samples;308 intout_linesize = 0;309 intmax_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;310 intout_samples = avresample_convert ( avr,445 in_samples = avFrame->nb_samples; 446 out_linesize = 0; 447 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE; 448 out_samples = avresample_convert ( avr, 311 449 (uint8_t **)&output, out_linesize, max_out_samples, 312 450 (uint8_t **)avFrame->data, in_linesize, in_samples); 451 #elif defined(HAVE_SWRESAMPLE) 452 in_samples = avFrame->nb_samples; 453 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; 454 out_samples = swr_convert( avr, 455 (uint8_t **)&output, max_out_samples, 456 (const uint8_t **)avFrame->data, in_samples); 457 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 313 458 if (out_samples <= 0) { 314 //AUBIO_ERR("No sample found while converting frame (%s)\n", s->path); 459 AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", 460 s->path); 315 461 goto beach; 316 462 } … … 322 468 s->avCodecCtx = avCodecCtx; 323 469 s->avFrame = avFrame; 470 #if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE) 324 471 s->avr = avr; 472 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 325 473 s->output = output; 326 474 … … 328 476 } 329 477 330 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){331 if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);332 uint_t i ;478 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, 479 uint_t * read) { 480 uint_t i, j; 333 481 uint_t end = 0; 334 482 uint_t total_wrote = 0; … … 336 484 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 337 485 for (i = 0; i < end; i++) { 338 read_data->data[i + total_wrote] = s->output[i + s->read_index]; 486 read_data->data[i + total_wrote] = 0.; 487 for (j = 0; j < s->input_channels; j++) { 488 read_data->data[i + total_wrote] += 489 s->output[(i + s->read_index) * s->input_channels + j]; 490 } 491 read_data->data[i + total_wrote] *= 1./s->input_channels; 339 492 } 340 493 total_wrote += end; … … 352 505 } 353 506 if (total_wrote < s->hop_size) { 354 for (i = end; i < s->hop_size; i++) {507 for (i = total_wrote; i < s->hop_size; i++) { 355 508 read_data->data[i] = 0.; 356 509 } … … 359 512 } 360 513 361 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, fmat_t * read_data, uint_t * read){362 if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);514 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, 515 fmat_t * read_data, uint_t * read) { 363 516 uint_t i,j; 364 517 uint_t end = 0; … … 387 540 if (total_wrote < s->hop_size) { 388 541 for (j = 0; j < read_data->height; j++) { 389 for (i = end; i < s->hop_size; i++) {542 for (i = total_wrote; i < s->hop_size; i++) { 390 543 read_data->data[j][i] = 0.; 391 544 } … … 404 557 405 558 uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t * s, uint_t pos) { 406 int64_t resampled_pos = (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate)); 559 int64_t resampled_pos = 560 (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate)); 407 561 int64_t min_ts = MAX(resampled_pos - 2000, 0); 408 562 int64_t max_ts = MIN(resampled_pos + 2000, INT64_MAX); 409 563 int seek_flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_ANY; 410 int ret = avformat_seek_file(s->avFormatCtx, s->selected_stream, 564 int ret = AUBIO_FAIL; 565 if (s->avFormatCtx != NULL && s->avr != NULL) { 566 ret = AUBIO_OK; 567 } else { 568 AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)", 569 s->path); 570 return ret; 571 } 572 if ((sint_t)pos < 0) { 573 AUBIO_ERR("source_avcodec: could not seek %s at %d (seeking position" 574 " should be >= 0)\n", s->path, pos); 575 return AUBIO_FAIL; 576 } 577 ret = avformat_seek_file(s->avFormatCtx, s->selected_stream, 411 578 min_ts, resampled_pos, max_ts, seek_flags); 412 579 if (ret < 0) { 413 AUBIO_ERR("Failed seeking to %d in file %s", pos, s->path); 580 AUBIO_ERR("source_avcodec: failed seeking to %d in file %s", 581 pos, s->path); 414 582 } 415 583 // reset read status … … 417 585 s->read_index = 0; 418 586 s->read_samples = 0; 587 #ifdef HAVE_AVRESAMPLE 419 588 // reset the AVAudioResampleContext 420 589 avresample_close(s->avr); 421 590 avresample_open(s->avr); 591 #elif defined(HAVE_SWRESAMPLE) 592 swr_close(s->avr); 593 swr_init(s->avr); 594 #endif 422 595 return ret; 423 596 } … … 433 606 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { 434 607 if (s->avr != NULL) { 608 #ifdef HAVE_AVRESAMPLE 435 609 avresample_close( s->avr ); 610 #elif defined(HAVE_SWRESAMPLE) 611 swr_close ( s->avr ); 612 #endif 436 613 av_free ( s->avr ); 437 614 } 438 615 s->avr = NULL; 439 616 if (s->avCodecCtx != NULL) { 617 #ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED 618 avcodec_free_context( &s->avCodecCtx ); 619 #else 440 620 avcodec_close ( s->avCodecCtx ); 621 #endif 441 622 } 442 623 s->avCodecCtx = NULL; 443 624 if (s->avFormatCtx != NULL) { 444 avformat_close_input ( &(s->avFormatCtx) ); 445 } 446 s->avFormatCtx = NULL; 625 avformat_close_input(&s->avFormatCtx); 626 s->avFormatCtx = NULL; 627 } 628 av_packet_unref(&s->avPacket); 447 629 return AUBIO_OK; 448 630 } … … 458 640 av_frame_free( &(s->avFrame) ); 459 641 } 460 if (s->path) AUBIO_FREE(s->path);461 642 s->avFrame = NULL; 643 if (s->path) { 644 AUBIO_FREE(s->path); 645 } 646 s->path = NULL; 462 647 AUBIO_FREE(s); 463 648 } -
src/io/source_sndfile.c
r5b46bc3 r633400d 19 19 */ 20 20 21 22 #include "config.h" 21 #include "aubio_priv.h" 23 22 24 23 #ifdef HAVE_SNDFILE … … 26 25 #include <sndfile.h> 27 26 28 #include "aubio_priv.h"29 27 #include "fvec.h" 30 28 #include "fmat.h" … … 33 31 #include "temporal/resampler.h" 34 32 35 #define MAX_CHANNELS 636 33 #define MAX_SIZE 4096 37 #define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE34 #define MAX_SAMPLES AUBIO_MAX_CHANNELS * MAX_SIZE 38 35 39 36 #if !HAVE_AUBIO_DOUBLE … … 141 138 if (s->ratio > 1) { 142 139 // we would need to add a ring buffer for these 143 if ( (uint_t) (s->input_hop_size * s->ratio + .5) != s->hop_size ) {140 if ( (uint_t)FLOOR(s->input_hop_size * s->ratio + .5) != s->hop_size ) { 144 141 AUBIO_ERR("source_sndfile: can not upsample %s from %d to %d\n", s->path, 145 142 s->input_samplerate, s->samplerate); … … 298 295 uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) { 299 296 uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio); 300 sf_count_t sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET); 297 sf_count_t sf_ret; 298 if (s->handle == NULL) { 299 AUBIO_ERR("source_sndfile: failed seeking in %s (file not opened?)\n", 300 s->path); 301 return AUBIO_FAIL; 302 } 303 if ((sint_t)pos < 0) { 304 AUBIO_ERR("source_sndfile: could not seek %s at %d (seeking position" 305 " should be >= 0)\n", s->path, pos); 306 return AUBIO_FAIL; 307 } 308 sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET); 301 309 if (sf_ret == -1) { 302 310 AUBIO_ERR("source_sndfile: Failed seeking %s at %d: %s\n", s->path, pos, sf_strerror (NULL)); … … 313 321 uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) { 314 322 if (!s->handle) { 315 return AUBIO_ FAIL;323 return AUBIO_OK; 316 324 } 317 325 if(sf_close(s->handle)) { … … 319 327 return AUBIO_FAIL; 320 328 } 329 s->handle = NULL; 321 330 return AUBIO_OK; 322 331 } -
src/io/source_wavread.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include " config.h"21 #include "aubio_priv.h" 22 22 23 23 #ifdef HAVE_WAVREAD 24 24 25 #include "aubio_priv.h"26 25 #include "fvec.h" 27 26 #include "fmat.h" … … 77 76 aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t); 78 77 size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44; 79 unsigned char buf[5] ;78 unsigned char buf[5] = "\0"; 80 79 unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size; 81 80 … … 110 109 buf[4] = '\0'; 111 110 if ( strcmp((const char *)buf, "RIFF") != 0 ) { 112 AUBIO_ERR("source_wavread: could not find RIFF header in %s\n", s->path);111 AUBIO_ERR("source_wavread: Failed opening %s (could not find RIFF header)\n", s->path); 113 112 goto beach; 114 113 } … … 121 120 buf[4] = '\0'; 122 121 if ( strcmp((const char *)buf, "WAVE") != 0 ) { 123 AUBIO_ERR("source_wavread: wrong format in RIFF header in %s\n", s->path);122 AUBIO_ERR("source_wavread: Failed opening %s (wrong format in RIFF header)\n", s->path); 124 123 goto beach; 125 124 } … … 135 134 bytes_junk += read_little_endian(buf, 4); 136 135 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 137 AUBIO_ERR("source_wavread: could not seek past JUNK Chunk in %s (%s)\n",136 AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n", 138 137 s->path, strerror(errno)); 139 138 goto beach; … … 148 147 // get the fmt chunk 149 148 if ( strcmp((const char *)buf, "fmt ") != 0 ) { 150 AUBIO_ERR("source_wavread: failed finding fmt RIFF header in %s\n", s->path);149 AUBIO_ERR("source_wavread: Failed opening %s (could not find 'fmt ' in RIFF header)\n", s->path); 151 150 goto beach; 152 151 } … … 157 156 if ( format != 16 ) { 158 157 // TODO accept format 18 159 AUBIO_ERR("source_wavread: file %s is not encoded with PCM\n", s->path);158 AUBIO_ERR("source_wavread: Failed opening %s (not encoded with PCM)\n", s->path); 160 159 goto beach; 161 160 } 162 161 if ( buf[1] || buf[2] | buf[3] ) { 163 AUBIO_ERR("source_wavread: Subchunk1Size should be 0, in %s\n", s->path);162 AUBIO_ERR("source_wavread: Failed opening %s (Subchunk1Size should be 0)\n", s->path); 164 163 goto beach; 165 164 } … … 168 167 bytes_read += fread(buf, 1, 2, s->fid); 169 168 if ( buf[0] != 1 || buf[1] != 0) { 170 AUBIO_ERR("source_wavread: AudioFormat should be PCM, in %s\n", s->path);169 AUBIO_ERR("source_wavread: Failed opening %s (AudioFormat should be PCM)\n", s->path); 171 170 goto beach; 172 171 } … … 191 190 bytes_read += fread(buf, 1, 2, s->fid); 192 191 bitspersample = read_little_endian(buf, 2); 192 193 if ( channels == 0 ) { 194 AUBIO_ERR("source_wavread: Failed opening %s (number of channels can not be 0)\n", s->path); 195 goto beach; 196 } 197 198 if ( (sint_t)sr <= 0 ) { 199 AUBIO_ERR("source_wavread: Failed opening %s (samplerate can not be <= 0)\n", s->path); 200 goto beach; 201 } 202 203 if ( byterate == 0 ) { 204 AUBIO_ERR("source_wavread: Failed opening %s (byterate can not be 0)\n", s->path); 205 goto beach; 206 } 207 208 if ( bitspersample == 0 ) { 209 AUBIO_ERR("source_wavread: Failed opening %s (bitspersample can not be 0)\n", s->path); 210 goto beach; 211 } 193 212 #if 0 194 213 if ( bitspersample != 16 ) { … … 200 219 201 220 if ( byterate * 8 != sr * channels * bitspersample ) { 202 AUBIO_ERR("source_wavread: wrong byterate in %s\n", s->path);221 AUBIO_ERR("source_wavread: Failed opening %s (wrong byterate)\n", s->path); 203 222 goto beach; 204 223 } 205 224 206 225 if ( blockalign * 8 != channels * bitspersample ) { 207 AUBIO_ERR("source_wavread: wrong blockalign in %s\n", s->path);226 AUBIO_ERR("source_wavread: Failed opening %s (wrong blockalign)\n", s->path); 208 227 goto beach; 209 228 } … … 330 349 uint_t end = 0; 331 350 uint_t total_wrote = 0; 351 if (s->fid == NULL) { 352 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 353 s->path); 354 return; 355 } 332 356 while (total_wrote < s->hop_size) { 333 357 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 364 388 uint_t end = 0; 365 389 uint_t total_wrote = 0; 390 if (s->fid == NULL) { 391 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 392 s->path); 393 return; 394 } 366 395 while (total_wrote < s->hop_size) { 367 396 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 404 433 uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) { 405 434 uint_t ret = 0; 435 if (s->fid == NULL) { 436 AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos); 437 return AUBIO_FAIL; 438 } 406 439 if ((sint_t)pos < 0) { 440 AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos); 407 441 return AUBIO_FAIL; 408 442 } … … 426 460 427 461 uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) { 428 if ( !s->fid) {429 return AUBIO_ FAIL;462 if (s->fid == NULL) { 463 return AUBIO_OK; 430 464 } 431 465 if (fclose(s->fid)) { -
src/io/utils_apple_audio.c
r5b46bc3 r633400d 1 #include " config.h"1 #include "aubio_priv.h" 2 2 3 3 #if defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO) … … 7 7 // ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ... 8 8 #include <AudioToolbox/AudioToolbox.h> 9 #include "aubio_priv.h"10 9 11 10 int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); -
src/mathutils.c
r5b46bc3 r633400d 25 25 #include "mathutils.h" 26 26 #include "musicutils.h" 27 #include "config.h"28 27 29 28 /** Window types */ 30 29 typedef enum 31 30 { 31 aubio_win_ones, 32 32 aubio_win_rectangle, 33 33 aubio_win_hamming, … … 65 65 AUBIO_ERR ("window type can not be null.\n"); 66 66 return 1; 67 } else if (strcmp (window_type, "rectangle") == 0) 67 } else if (strcmp (window_type, "ones") == 0) 68 wintype = aubio_win_ones; 69 else if (strcmp (window_type, "rectangle") == 0) 68 70 wintype = aubio_win_rectangle; 69 71 else if (strcmp (window_type, "hamming") == 0) … … 90 92 } 91 93 switch(wintype) { 94 case aubio_win_ones: 95 fvec_ones(win); 96 break; 92 97 case aubio_win_rectangle: 93 for (i=0;i<size;i++) 94 w[i] = 0.5; 98 fvec_set_all(win, .5); 95 99 break; 96 100 case aubio_win_hamming: … … 156 160 { 157 161 smpl_t tmp = 0.0; 158 #ifndef HAVE_ACCELERATE 162 #if defined(HAVE_INTEL_IPP) 163 aubio_ippsMean(s->data, (int)s->length, &tmp); 164 return tmp; 165 #elif defined(HAVE_ACCELERATE) 166 aubio_vDSP_meanv(s->data, 1, &tmp, s->length); 167 return tmp; 168 #else 159 169 uint_t j; 160 170 for (j = 0; j < s->length; j++) { 161 171 tmp += s->data[j]; 162 172 } 163 return tmp / (smpl_t) (s->length); 164 #else 165 aubio_vDSP_meanv(s->data, 1, &tmp, s->length); 166 return tmp; 167 #endif /* HAVE_ACCELERATE */ 173 return tmp / (smpl_t)(s->length); 174 #endif 168 175 } 169 176 … … 172 179 { 173 180 smpl_t tmp = 0.0; 174 #ifndef HAVE_ACCELERATE 181 #if defined(HAVE_INTEL_IPP) 182 aubio_ippsSum(s->data, (int)s->length, &tmp); 183 #elif defined(HAVE_ACCELERATE) 184 aubio_vDSP_sve(s->data, 1, &tmp, s->length); 185 #else 175 186 uint_t j; 176 187 for (j = 0; j < s->length; j++) { 177 188 tmp += s->data[j]; 178 189 } 179 #else 180 aubio_vDSP_sve(s->data, 1, &tmp, s->length); 181 #endif /* HAVE_ACCELERATE */ 190 #endif 182 191 return tmp; 183 192 } … … 186 195 fvec_max (fvec_t * s) 187 196 { 188 #ifndef HAVE_ACCELERATE 189 uint_t j; 190 smpl_t tmp = 0.0; 191 for (j = 0; j < s->length; j++) { 197 #if defined(HAVE_INTEL_IPP) 198 smpl_t tmp = 0.; 199 aubio_ippsMax( s->data, (int)s->length, &tmp); 200 #elif defined(HAVE_ACCELERATE) 201 smpl_t tmp = 0.; 202 aubio_vDSP_maxv( s->data, 1, &tmp, s->length ); 203 #else 204 uint_t j; 205 smpl_t tmp = s->data[0]; 206 for (j = 1; j < s->length; j++) { 192 207 tmp = (tmp > s->data[j]) ? tmp : s->data[j]; 193 208 } 194 #else 209 #endif 210 return tmp; 211 } 212 213 smpl_t 214 fvec_min (fvec_t * s) 215 { 216 #if defined(HAVE_INTEL_IPP) 195 217 smpl_t tmp = 0.; 196 aubio_vDSP_maxv(s->data, 1, &tmp, s->length); 197 #endif 198 return tmp; 199 } 200 201 smpl_t 202 fvec_min (fvec_t * s) 203 { 204 #ifndef HAVE_ACCELERATE 205 uint_t j; 206 smpl_t tmp = s->data[0]; 207 for (j = 0; j < s->length; j++) { 208 tmp = (tmp < s->data[j]) ? tmp : s->data[j]; 209 } 210 #else 218 aubio_ippsMin(s->data, (int)s->length, &tmp); 219 #elif defined(HAVE_ACCELERATE) 211 220 smpl_t tmp = 0.; 212 221 aubio_vDSP_minv(s->data, 1, &tmp, s->length); 222 #else 223 uint_t j; 224 smpl_t tmp = s->data[0]; 225 for (j = 1; j < s->length; j++) { 226 tmp = (tmp < s->data[j]) ? tmp : s->data[j]; 227 } 213 228 #endif 214 229 return tmp; … … 227 242 #else 228 243 smpl_t tmp = 0.; 229 uint_t pos = 0.;230 aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);231 #endif 232 return pos;244 vDSP_Length pos = 0; 245 aubio_vDSP_minvi(s->data, 1, &tmp, &pos, s->length); 246 #endif 247 return (uint_t)pos; 233 248 } 234 249 … … 245 260 #else 246 261 smpl_t tmp = 0.; 247 uint_t pos = 0.;248 aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);249 #endif 250 return pos;262 vDSP_Length pos = 0; 263 aubio_vDSP_maxvi(s->data, 1, &tmp, &pos, s->length); 264 #endif 265 return (uint_t)pos; 251 266 } 252 267 … … 257 272 // if length is odd, middle element is moved to the end 258 273 if (2 * half < s->length) start ++; 259 #ifndef HAVE_ ATLAS274 #ifndef HAVE_BLAS 260 275 for (j = 0; j < half; j++) { 261 276 ELEM_SWAP (s->data[j], s->data[j + start]); … … 277 292 // if length is odd, middle element is moved to the beginning 278 293 if (2 * half < s->length) start ++; 279 #ifndef HAVE_ ATLAS294 #ifndef HAVE_BLAS 280 295 for (j = 0; j < half; j++) { 281 296 ELEM_SWAP (s->data[j], s->data[j + start]); … … 291 306 } 292 307 308 void fvec_push(fvec_t *in, smpl_t new_elem) { 309 uint_t i; 310 for (i = 0; i < in->length - 1; i++) { 311 in->data[i] = in->data[i + 1]; 312 } 313 in->data[in->length - 1] = new_elem; 314 } 315 316 void fvec_clamp(fvec_t *in, smpl_t absmax) { 317 uint_t i; 318 for (i = 0; i < in->length; i++) { 319 if (in->data[i] > 0 && in->data[i] > ABS(absmax)) { 320 in->data[i] = absmax; 321 } else if (in->data[i] < 0 && in->data[i] < -ABS(absmax)) { 322 in->data[i] = -absmax; 323 } 324 } 325 } 326 293 327 smpl_t 294 328 aubio_level_lin (const fvec_t * f) 295 329 { 296 330 smpl_t energy = 0.; 297 #ifndef HAVE_ ATLAS331 #ifndef HAVE_BLAS 298 332 uint_t j; 299 333 for (j = 0; j < f->length; j++) { … … 351 385 for (j = 0; j < o->length; j++) { 352 386 o->data[j] += val; 387 } 388 } 389 390 void 391 fvec_mul (fvec_t *o, smpl_t val) 392 { 393 uint_t j; 394 for (j = 0; j < o->length; j++) { 395 o->data[j] *= val; 353 396 } 354 397 } … … 489 532 /* log(freq/A-2)/log(2) */ 490 533 midi = freq / 6.875; 491 midi = LOG (midi) / 0.6931471805599 5;534 midi = LOG (midi) / 0.6931471805599453; 492 535 midi *= 12; 493 536 midi -= 3; … … 501 544 if (midi > 140.) return 0.; // avoid infs 502 545 freq = (midi + 3.) / 12.; 503 freq = EXP (freq * 0.6931471805599 5);546 freq = EXP (freq * 0.6931471805599453); 504 547 freq *= 6.875; 505 548 return freq; … … 550 593 while (i < a) i <<= 1; 551 594 return i; 595 } 596 597 uint_t 598 aubio_power_of_two_order (uint_t a) 599 { 600 int order = 0; 601 int temp = aubio_next_power_of_two(a); 602 while (temp >>= 1) { 603 ++order; 604 } 605 return order; 552 606 } 553 607 -
src/mathutils.h
r5b46bc3 r633400d 118 118 void fvec_ishift (fvec_t * v); 119 119 120 /** push a new element to the end of a vector, erasing the first element and 121 * sliding all others 122 123 \param in vector to push to 124 \param new_elem new_element to add at the end of the vector 125 126 In numpy words, this is equivalent to: in = np.concatenate([in, [new_elem]])[1:] 127 128 */ 129 void fvec_push(fvec_t *in, smpl_t new_elem); 130 120 131 /** compute the sum of all elements of a vector 121 132 … … 182 193 */ 183 194 void fvec_add (fvec_t * v, smpl_t c); 195 196 /** multiply each elements of a vector by a scalar 197 198 \param v vector to add constant to 199 \param s constant to scale v with 200 201 */ 202 void fvec_mul (fvec_t * v, smpl_t s); 184 203 185 204 /** remove the minimum value of the vector to each elements … … 302 321 uint_t aubio_next_power_of_two(uint_t a); 303 322 323 /** return the log2 factor of the given power of 2 value a */ 324 uint_t aubio_power_of_two_order(uint_t a); 325 304 326 /** compute normalised autocorrelation function 305 327 -
src/musicutils.h
r5b46bc3 r633400d 87 87 smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize); 88 88 89 /** convert frequency (Hz) to mel 90 91 \param freq input frequency, in Hz 92 93 \return output mel 94 95 Converts a scalar from the frequency domain to the mel scale using Slaney 96 Auditory Toolbox's implementation: 97 98 If \f$ f < 1000 \f$, \f$ m = 3 f / 200 \f$. 99 100 If \f$ f >= 1000 \f$, \f$ m = 1000 + 27 \frac{{ln}(f) - ln(1000))} 101 {{ln}(6400) - ln(1000)} 102 \f$ 103 104 See also 105 -------- 106 107 aubio_meltohz(), aubio_hztomel_htk(). 108 109 */ 110 smpl_t aubio_hztomel (smpl_t freq); 111 112 /** convert mel to frequency (Hz) 113 114 \param mel input mel 115 116 \return output frequency, in Hz 117 118 Converts a scalar from the mel scale to the frequency domain using Slaney 119 Auditory Toolbox's implementation: 120 121 If \f$ f < 1000 \f$, \f$ f = 200 m/3 \f$. 122 123 If \f$ f \geq 1000 \f$, \f$ f = 1000 + \left(\frac{6400}{1000}\right) 124 ^{\frac{m - 1000}{27}} \f$ 125 126 See also 127 -------- 128 129 aubio_hztomel(), aubio_meltohz_htk(). 130 131 References 132 ---------- 133 134 Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010* 135 https://engineering.purdue.edu/~malcolm/interval/1998-010/ 136 137 */ 138 smpl_t aubio_meltohz (smpl_t mel); 139 140 /** convert frequency (Hz) to mel 141 142 \param freq input frequency, in Hz 143 144 \return output mel 145 146 Converts a scalar from the frequency domain to the mel scale, using the 147 equation defined by O'Shaughnessy, as implemented in the HTK speech 148 recognition toolkit: 149 150 \f$ m = 1127 + ln(1 + \frac{f}{700}) \f$ 151 152 See also 153 -------- 154 155 aubio_meltohz_htk(), aubio_hztomel(). 156 157 References 158 ---------- 159 160 Douglas O'Shaughnessy (1987). *Speech communication: human and machine*. 161 Addison-Wesley. p. 150. ISBN 978-0-201-16520-3. 162 163 HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/ 164 165 */ 166 smpl_t aubio_hztomel_htk (smpl_t freq); 167 168 /** convert mel to frequency (Hz) 169 170 \param mel input mel 171 172 \return output frequency, in Hz 173 174 Converts a scalar from the mel scale to the frequency domain, using the 175 equation defined by O'Shaughnessy, as implemented in the HTK speech 176 recognition toolkit: 177 178 \f$ f = 700 * {e}^\left(\frac{f}{1127} - 1\right) \f$ 179 180 See also 181 -------- 182 183 aubio_hztomel_htk(), aubio_meltohz(). 184 185 */ 186 smpl_t aubio_meltohz_htk (smpl_t mel); 187 89 188 /** convert frequency (Hz) to midi value (0-128) */ 90 189 smpl_t aubio_freqtomidi (smpl_t freq); … … 156 255 */ 157 256 smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold); 257 258 /** clamp the values of a vector within the range [-abs(max), abs(max)] 259 260 \param in vector to clamp 261 \param absmax maximum value over which input vector elements should be clamped 262 263 */ 264 void fvec_clamp(fvec_t *in, smpl_t absmax); 158 265 159 266 #ifdef __cplusplus -
src/notes/notes.c
r5b46bc3 r633400d 1 1 /* 2 Copyright (C) 2014 Paul Brossier <piem@aubio.org>2 Copyright (C) 2014-2018 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 25 25 #include "notes/notes.h" 26 26 27 #define AUBIO_DEFAULT_NOTES_SILENCE -70. 28 #define AUBIO_DEFAULT_NOTES_RELEASE_DROP 10. 29 // increase to 10. for .1 cent precision 30 // or to 100. for .01 cent precision 31 #define AUBIO_DEFAULT_CENT_PRECISION 1. 32 #define AUBIO_DEFAULT_NOTES_MINIOI_MS 30. 33 27 34 struct _aubio_notes_t { 28 35 … … 51 58 52 59 uint_t isready; 60 61 smpl_t last_onset_level; 62 smpl_t release_drop_level; 53 63 }; 54 64 … … 74 84 75 85 o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate); 86 if (o->onset == NULL) goto fail; 76 87 if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold); 77 88 o->onset_output = new_fvec (1); 78 89 79 90 o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate); 91 if (o->pitch == NULL) goto fail; 80 92 if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance); 93 aubio_pitch_set_unit (o->pitch, "midi"); 81 94 o->pitch_output = new_fvec (1); 82 95 … … 88 101 o->note_buffer2 = new_fvec(o->median); 89 102 103 if (!o->onset_output || !o->pitch_output || 104 !o->note_buffer || !o->note_buffer2) goto fail; 105 90 106 o->curnote = -1.; 91 107 o->newnote = 0.; 92 108 93 o->silence_threshold = -90.; 109 aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE); 110 aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS); 111 112 o->last_onset_level = AUBIO_DEFAULT_NOTES_SILENCE; 113 o->release_drop_level = AUBIO_DEFAULT_NOTES_RELEASE_DROP; 94 114 95 115 return o; … … 98 118 del_aubio_notes(o); 99 119 return NULL; 120 } 121 122 uint_t aubio_notes_set_silence(aubio_notes_t *o, smpl_t silence) 123 { 124 uint_t err = AUBIO_OK; 125 if (aubio_pitch_set_silence(o->pitch, silence) != AUBIO_OK) { 126 err = AUBIO_FAIL; 127 } 128 if (aubio_onset_set_silence(o->onset, silence) != AUBIO_OK) { 129 err = AUBIO_FAIL; 130 } 131 o->silence_threshold = silence; 132 return err; 133 } 134 135 smpl_t aubio_notes_get_silence(const aubio_notes_t *o) 136 { 137 return aubio_pitch_get_silence(o->pitch); 138 } 139 140 uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms) 141 { 142 uint_t err = AUBIO_OK; 143 if (!o->onset || (aubio_onset_set_minioi_ms(o->onset, minioi_ms) != 0)) { 144 err = AUBIO_FAIL; 145 } 146 return err; 147 } 148 149 smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o) 150 { 151 return aubio_onset_get_minioi_ms(o->onset); 152 } 153 154 uint_t aubio_notes_set_release_drop(aubio_notes_t *o, smpl_t release_drop_level) 155 { 156 uint_t err = AUBIO_OK; 157 if (release_drop_level <= 0.) { 158 AUBIO_ERR("notes: release_drop should be >= 0, got %f\n", release_drop_level); 159 err = AUBIO_FAIL; 160 } else { 161 o->release_drop_level = release_drop_level; 162 } 163 return err; 164 } 165 166 smpl_t aubio_notes_get_release_drop(const aubio_notes_t *o) 167 { 168 return o->release_drop_level; 100 169 } 101 170 … … 109 178 note_buffer->data[i] = note_buffer->data[i + 1]; 110 179 } 111 note_buffer->data[note_buffer->length - 1] = curnote; 180 //note_buffer->data[note_buffer->length - 1] = ROUND(10.*curnote)/10.; 181 note_buffer->data[note_buffer->length - 1] = ROUND(AUBIO_DEFAULT_CENT_PRECISION*curnote); 112 182 return; 113 183 } 114 184 115 static uint_t185 static smpl_t 116 186 aubio_notes_get_latest_note (aubio_notes_t *o) 117 187 { 118 uint_t i; 119 for (i = 0; i < o->note_buffer->length; i++) { 120 o->note_buffer2->data[i] = o->note_buffer->data[i]; 121 } 122 return fvec_median (o->note_buffer2); 188 fvec_copy(o->note_buffer, o->note_buffer2); 189 return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION; 123 190 } 124 191 … … 146 213 //notes->data[0] = o->curnote; 147 214 //notes->data[1] = 0.; 215 //AUBIO_WRN("notes: sending note-off at onset, not enough level\n"); 148 216 notes->data[2] = o->curnote; 149 217 } else { … … 153 221 /* kill old note */ 154 222 //send_noteon(o->curnote,0, o->samplerate); 223 //AUBIO_WRN("notes: sending note-off at onset, new onset detected\n"); 155 224 notes->data[2] = o->curnote; 156 225 /* get and send new one */ … … 160 229 o->curnote = new_pitch; 161 230 } 231 o->last_onset_level = curlevel; 162 232 } 163 233 } else { 164 if (o->median) { 234 if (curlevel < o->last_onset_level - o->release_drop_level) 235 { 236 // send note off 237 //AUBIO_WRN("notes: sending note-off, release detected\n"); 238 notes->data[0] = 0; 239 notes->data[1] = 0; 240 notes->data[2] = o->curnote; 241 // reset last_onset_level to silence_threshold 242 o->last_onset_level = o->silence_threshold; 243 o->curnote = 0; 244 } 245 else if (o->median) 246 { 165 247 if (o->isready > 0) 166 248 o->isready++; … … 169 251 /* kill old note */ 170 252 //send_noteon(curnote,0); 171 notes->data[2] = o->curnote; 253 if (o->curnote != 0) 254 { 255 //AUBIO_WRN("notes: sending note-off, new note detected\n"); 256 notes->data[2] = o->curnote; 257 } 172 258 o->newnote = aubio_notes_get_latest_note(o); 173 259 o->curnote = o->newnote; -
src/notes/notes.h
r5b46bc3 r633400d 16 16 You should have received a copy of the GNU General Public License 17 17 along with aubio. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 21 /** \file 22 23 Note detection object 18 24 19 25 */ … … 52 58 53 59 \param o note detection object as returned by new_aubio_notes() 54 \param in input signal of size [hop_size] 55 \param out output notes of size [3] ? FIXME 60 \param input input signal of size [hop_size] 61 \param output output notes, fvec of length 3 62 63 The notes output is a vector of length 3 containing: 64 - 0. the midi note value, or 0 if no note was found 65 - 1. the note velocity 66 - 2. the midi note to turn off 56 67 57 68 */ 58 69 void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * output); 70 71 /** set notes detection silence threshold 72 73 \param o notes detection object as returned by new_aubio_notes() 74 \param silence new silence detection threshold 75 76 \return 0 on success, non-zero otherwise 77 78 */ 79 uint_t aubio_notes_set_silence(aubio_notes_t * o, smpl_t silence); 80 81 /** get notes detection silence threshold 82 83 \param o notes detection object as returned by new_aubio_notes() 84 85 \return current silence threshold 86 87 */ 88 smpl_t aubio_notes_get_silence(const aubio_notes_t * o); 89 90 /** get notes detection minimum inter-onset interval, in millisecond 91 92 \param o notes detection object as returned by new_aubio_notes() 93 94 \return current minimum inter onset interval 95 96 */ 97 smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o); 98 99 /** set notes detection minimum inter-onset interval, in millisecond 100 101 \param o notes detection object as returned by new_aubio_notes() 102 \param minioi_ms new inter-onset interval 103 104 \return 0 on success, non-zero otherwise 105 106 */ 107 uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms); 108 109 /** get notes object release drop level, in dB 110 111 \param o notes detection object as returned by new_aubio_notes() 112 113 \return current release drop level, in dB 114 115 */ 116 smpl_t aubio_notes_get_release_drop (const aubio_notes_t *o); 117 118 /** set note release drop level, in dB 119 120 This function sets the release_drop_level parameter, in dB. When a new note 121 is found, the current level in dB is measured. If the measured level drops 122 under that initial level - release_drop_level, then a note-off will be 123 emitted. 124 125 Defaults to `10`, in dB. 126 127 \note This parameter was added in version `0.4.8`. Results obtained with 128 earlier versions can be reproduced by setting this value to `100`, so that 129 note-off will not be played until the next note. 130 131 \param o notes detection object as returned by new_aubio_notes() 132 \param release_drop new release drop level, in dB 133 134 \return 0 on success, non-zero otherwise 135 136 */ 137 uint_t aubio_notes_set_release_drop (aubio_notes_t *o, smpl_t release_drop); 59 138 60 139 #ifdef __cplusplus -
src/onset/onset.c
r5b46bc3 r633400d 24 24 #include "spectral/specdesc.h" 25 25 #include "spectral/phasevoc.h" 26 #include "spectral/awhitening.h" 26 27 #include "onset/peakpicker.h" 27 28 #include "mathutils.h" 28 29 #include "onset/onset.h" 30 31 void aubio_onset_default_parameters (aubio_onset_t *o, const char_t * method); 29 32 30 33 /** structure to store object state */ … … 43 46 uint_t total_frames; /**< total number of frames processed since the beginning */ 44 47 uint_t last_onset; /**< last detected onset location, in frames */ 48 49 uint_t apply_compression; 50 smpl_t lambda_compression; 51 uint_t apply_awhitening; /**< apply adaptive spectral whitening */ 52 aubio_spectral_whitening_t *spectral_whitening; 45 53 }; 46 54 … … 50 58 smpl_t isonset = 0; 51 59 aubio_pvoc_do (o->pv,input, o->fftgrain); 60 /* 61 if (apply_filtering) { 62 } 63 */ 64 if (o->apply_awhitening) { 65 aubio_spectral_whitening_do(o->spectral_whitening, o->fftgrain); 66 } 67 if (o->apply_compression) { 68 cvec_logmag(o->fftgrain, o->lambda_compression); 69 } 52 70 aubio_specdesc_do (o->od, o->fftgrain, o->desc); 53 71 aubio_peakpicker_do(o->pp, o->desc, onset); … … 58 76 isonset = 0; 59 77 } else { 78 // we have an onset 60 79 uint_t new_onset = o->total_frames + (uint_t)ROUND(isonset * o->hop_size); 80 // check if last onset time was more than minioi ago 61 81 if (o->last_onset + o->minioi < new_onset) { 62 //AUBIO_DBG ("accepted detection, marking as onset\n"); 63 o->last_onset = new_onset; 82 // start of file: make sure (new_onset - delay) >= 0 83 if (o->last_onset > 0 && o->delay > new_onset) { 84 isonset = 0; 85 } else { 86 //AUBIO_DBG ("accepted detection, marking as onset\n"); 87 o->last_onset = MAX(o->delay, new_onset); 88 } 64 89 } else { 65 90 //AUBIO_DBG ("doubled onset, not marking as onset\n"); … … 100 125 } 101 126 127 uint_t aubio_onset_set_awhitening (aubio_onset_t *o, uint_t enable) 128 { 129 o->apply_awhitening = enable == 1 ? 1 : 0; 130 return AUBIO_OK; 131 } 132 133 smpl_t aubio_onset_get_awhitening (aubio_onset_t *o) 134 { 135 return o->apply_awhitening; 136 } 137 138 uint_t aubio_onset_set_compression (aubio_onset_t *o, smpl_t lambda) 139 { 140 if (lambda < 0.) { 141 return AUBIO_FAIL; 142 } 143 o->lambda_compression = lambda; 144 o->apply_compression = (o->lambda_compression > 0.) ? 1 : 0; 145 return AUBIO_OK; 146 } 147 148 smpl_t aubio_onset_get_compression (aubio_onset_t *o) 149 { 150 return o->apply_compression ? o->lambda_compression : 0; 151 } 152 102 153 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) { 103 154 o->silence = silence; … … 206 257 o->pp = new_aubio_peakpicker(); 207 258 o->od = new_aubio_specdesc(onset_mode,buf_size); 208 if (o->od == NULL) goto beach_specdesc;209 259 o->fftgrain = new_cvec(buf_size); 210 260 o->desc = new_fvec(1); 211 261 o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate); 262 263 if (!o->pv || !o->pp || !o->od || !o->fftgrain 264 || !o->desc || !o->spectral_whitening) 265 goto beach; 266 267 /* initialize internal variables */ 268 aubio_onset_set_default_parameters (o, onset_mode); 269 270 aubio_onset_reset(o); 271 return o; 272 273 beach: 274 del_aubio_onset(o); 275 return NULL; 276 } 277 278 void aubio_onset_reset (aubio_onset_t *o) { 279 o->last_onset = 0; 280 o->total_frames = 0; 281 } 282 283 uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode) 284 { 285 uint_t ret = AUBIO_OK; 212 286 /* set some default parameter */ 213 287 aubio_onset_set_threshold (o, 0.3); 214 aubio_onset_set_delay(o, 4.3 * hop_size); 215 aubio_onset_set_minioi_ms(o, 20.); 216 aubio_onset_set_silence(o, -70.); 217 218 /* initialize internal variables */ 219 o->last_onset = 0; 220 o->total_frames = 0; 221 return o; 222 223 beach_specdesc: 224 del_aubio_peakpicker(o->pp); 225 del_aubio_pvoc(o->pv); 226 beach: 288 aubio_onset_set_delay (o, 4.3 * o->hop_size); 289 aubio_onset_set_minioi_ms (o, 50.); 290 aubio_onset_set_silence (o, -70.); 291 // disable spectral whitening 292 aubio_onset_set_awhitening (o, 0); 293 // disable logarithmic magnitude 294 aubio_onset_set_compression (o, 0.); 295 296 /* method specific optimisations */ 297 if (strcmp (onset_mode, "energy") == 0) { 298 } else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) { 299 aubio_onset_set_threshold (o, 0.058); 300 aubio_onset_set_compression (o, 1.); 301 } else if (strcmp (onset_mode, "complexdomain") == 0 302 || strcmp (onset_mode, "complex") == 0) { 303 aubio_onset_set_delay (o, 4.6 * o->hop_size); 304 aubio_onset_set_threshold (o, 0.15); 305 aubio_onset_set_awhitening(o, 1); 306 aubio_onset_set_compression (o, 1.); 307 } else if (strcmp (onset_mode, "phase") == 0) { 308 o->apply_compression = 0; 309 aubio_onset_set_awhitening (o, 0); 310 } else if (strcmp (onset_mode, "wphase") == 0) { 311 // use defaults for now 312 } else if (strcmp (onset_mode, "mkl") == 0) { 313 aubio_onset_set_threshold (o, 0.05); 314 aubio_onset_set_awhitening(o, 1); 315 aubio_onset_set_compression (o, 0.02); 316 } else if (strcmp (onset_mode, "kl") == 0) { 317 aubio_onset_set_threshold (o, 0.35); 318 aubio_onset_set_awhitening(o, 1); 319 aubio_onset_set_compression (o, 0.02); 320 } else if (strcmp (onset_mode, "specflux") == 0) { 321 aubio_onset_set_threshold (o, 0.18); 322 aubio_onset_set_awhitening(o, 1); 323 aubio_spectral_whitening_set_relax_time(o->spectral_whitening, 100); 324 aubio_spectral_whitening_set_floor(o->spectral_whitening, 1.); 325 aubio_onset_set_compression (o, 10.); 326 } else if (strcmp (onset_mode, "specdiff") == 0) { 327 } else if (strcmp (onset_mode, "old_default") == 0) { 328 // used to reproduce results obtained with the previous version 329 aubio_onset_set_threshold (o, 0.3); 330 aubio_onset_set_minioi_ms (o, 20.); 331 aubio_onset_set_compression (o, 0.); 332 } else { 333 AUBIO_WRN("onset: unknown spectral descriptor type %s, " 334 "using default parameters.\n", onset_mode); 335 ret = AUBIO_FAIL; 336 } 337 return ret; 338 } 339 340 void del_aubio_onset (aubio_onset_t *o) 341 { 342 if (o->spectral_whitening) 343 del_aubio_spectral_whitening(o->spectral_whitening); 344 if (o->od) 345 del_aubio_specdesc(o->od); 346 if (o->pp) 347 del_aubio_peakpicker(o->pp); 348 if (o->pv) 349 del_aubio_pvoc(o->pv); 350 if (o->desc) 351 del_fvec(o->desc); 352 if (o->fftgrain) 353 del_cvec(o->fftgrain); 227 354 AUBIO_FREE(o); 228 return NULL; 229 } 230 231 void del_aubio_onset (aubio_onset_t *o) 232 { 233 del_aubio_specdesc(o->od); 234 del_aubio_peakpicker(o->pp); 235 del_aubio_pvoc(o->pv); 236 del_fvec(o->desc); 237 del_cvec(o->fftgrain); 238 AUBIO_FREE(o); 239 } 355 } -
src/onset/onset.h
r5b46bc3 r633400d 118 118 smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o); 119 119 120 /** set onset detection adaptive whitening 121 122 \param o onset detection object as returned by new_aubio_onset() 123 \param enable 1 to enable, 0 to disable 124 125 \return 0 if successful, 1 otherwise 126 127 */ 128 uint_t aubio_onset_set_awhitening(aubio_onset_t * o, uint_t enable); 129 130 /** get onset detection adaptive whitening 131 132 \param o onset detection object as returned by new_aubio_onset() 133 134 \return 1 if enabled, 0 otherwise 135 136 */ 137 smpl_t aubio_onset_get_awhitening(aubio_onset_t * o); 138 139 /** set or disable log compression 140 141 \param o onset detection object as returned by new_aubio_onset() 142 \param lambda logarithmic compression factor, 0 to disable 143 144 \return 0 if successful, 1 otherwise 145 146 */ 147 uint_t aubio_onset_set_compression(aubio_onset_t *o, smpl_t lambda); 148 149 /** get onset detection log compression 150 151 \param o onset detection object as returned by new_aubio_onset() 152 153 \returns 0 if disabled, compression factor otherwise 154 155 */ 156 smpl_t aubio_onset_get_compression(aubio_onset_t *o); 157 120 158 /** set onset detection silence threshold 121 159 … … 274 312 */ 275 313 smpl_t aubio_onset_get_threshold(const aubio_onset_t * o); 314 315 /** set default parameters 316 317 \param o onset detection object as returned by new_aubio_onset() 318 \param onset_mode detection mode to adjust 319 320 This function is called at the end of new_aubio_onset(). 321 322 */ 323 uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode); 324 325 /** reset onset detection 326 327 \param o onset detection object as returned by new_aubio_onset() 328 329 Reset current time and last onset to 0. 330 331 This function is called at the end of new_aubio_onset(). 332 333 */ 334 void aubio_onset_reset(aubio_onset_t * o); 276 335 277 336 /** delete onset detection object -
src/onset/peakpicker.c
r5b46bc3 r633400d 93 93 fvec_t *scratch = p->scratch; 94 94 smpl_t mean = 0., median = 0.; 95 uint_t length = p->win_post + p->win_pre + 1;96 95 uint_t j = 0; 97 96 98 /* store onset in onset_keep */ 99 /* shift all elements but last, then write last */ 100 for (j = 0; j < length - 1; j++) { 101 onset_keep->data[j] = onset_keep->data[j + 1]; 102 onset_proc->data[j] = onset_keep->data[j]; 103 } 104 onset_keep->data[length - 1] = onset->data[0]; 105 onset_proc->data[length - 1] = onset->data[0]; 97 /* push new novelty to the end */ 98 fvec_push(onset_keep, onset->data[0]); 99 /* store a copy */ 100 fvec_copy(onset_keep, onset_proc); 106 101 107 /* filter onset_proc */ 108 /** \bug filtfilt calculated post+pre times, should be only once !? */ 102 /* filter this copy */ 109 103 aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); 110 104 111 105 /* calculate mean and median for onset_proc */ 112 106 mean = fvec_mean (onset_proc); 113 /* copy to scratch */ 114 for (j = 0; j < length; j++)115 scratch->data[j] = onset_proc->data[j];107 108 /* copy to scratch and compute its median */ 109 fvec_copy(onset_proc, scratch); 116 110 median = p->thresholdfn (scratch); 117 111 … … 186 180 */ 187 181 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 188 -0.59488894, 0.23484048); 182 // FIXME: broken since c9e20ca, revert for now 183 //-0.59488894, 0.23484048); 184 0.23484048, 0); 189 185 190 186 return t; -
src/pitch/pitch.c
r5b46bc3 r633400d 33 33 #include "pitch/pitchschmitt.h" 34 34 #include "pitch/pitchyinfft.h" 35 #include "pitch/pitchyinfast.h" 35 36 #include "pitch/pitchspecacf.h" 36 37 #include "pitch/pitch.h" … … 46 47 aubio_pitcht_fcomb, /**< `fcomb`, Fast comb filter */ 47 48 aubio_pitcht_yinfft, /**< `yinfft`, Spectral YIN */ 49 aubio_pitcht_yinfast, /**< `yinfast`, YIN fast */ 48 50 aubio_pitcht_specacf, /**< `specacf`, Spectral autocorrelation */ 49 51 aubio_pitcht_default … … 95 97 static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 96 98 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 99 static void aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 97 100 static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 98 101 … … 112 115 aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t); 113 116 aubio_pitch_type pitch_type; 117 if (pitch_mode == NULL) { 118 AUBIO_ERR ("pitch: can not use ‘NULL‘ for pitch detection method\n"); 119 goto beach; 120 } 114 121 if (strcmp (pitch_mode, "mcomb") == 0) 115 122 pitch_type = aubio_pitcht_mcomb; 123 else if (strcmp (pitch_mode, "yinfast") == 0) 124 pitch_type = aubio_pitcht_yinfast; 116 125 else if (strcmp (pitch_mode, "yinfft") == 0) 117 126 pitch_type = aubio_pitcht_yinfft; … … 139 148 goto beach; 140 149 } else if (bufsize < hopsize) { 141 AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);150 AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", hopsize, bufsize); 142 151 goto beach; 143 152 } else if ((sint_t)samplerate < 1) { … … 156 165 p->buf = new_fvec (bufsize); 157 166 p->p_object = new_aubio_pitchyin (bufsize); 167 if (!p->p_object) goto beach; 158 168 p->detect_cb = aubio_pitch_do_yin; 159 169 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence; … … 163 173 p->filtered = new_fvec (hopsize); 164 174 p->pv = new_aubio_pvoc (bufsize, hopsize); 175 if (!p->pv) goto beach; 165 176 p->fftgrain = new_cvec (bufsize); 166 177 p->p_object = new_aubio_pitchmcomb (bufsize, hopsize); … … 171 182 p->buf = new_fvec (bufsize); 172 183 p->p_object = new_aubio_pitchfcomb (bufsize, hopsize); 184 if (!p->p_object) goto beach; 173 185 p->detect_cb = aubio_pitch_do_fcomb; 174 186 break; … … 181 193 p->buf = new_fvec (bufsize); 182 194 p->p_object = new_aubio_pitchyinfft (samplerate, bufsize); 195 if (!p->p_object) goto beach; 183 196 p->detect_cb = aubio_pitch_do_yinfft; 184 197 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence; 185 198 aubio_pitchyinfft_set_tolerance (p->p_object, 0.85); 186 199 break; 200 case aubio_pitcht_yinfast: 201 p->buf = new_fvec (bufsize); 202 p->p_object = new_aubio_pitchyinfast (bufsize); 203 if (!p->p_object) goto beach; 204 p->detect_cb = aubio_pitch_do_yinfast; 205 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfast_get_confidence; 206 aubio_pitchyinfast_set_tolerance (p->p_object, 0.15); 207 break; 187 208 case aubio_pitcht_specacf: 188 209 p->buf = new_fvec (bufsize); 189 210 p->p_object = new_aubio_pitchspecacf (bufsize); 211 if (!p->p_object) goto beach; 190 212 p->detect_cb = aubio_pitch_do_specacf; 191 213 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance; … … 198 220 199 221 beach: 222 if (p->filtered) del_fvec(p->filtered); 223 if (p->buf) del_fvec(p->buf); 200 224 AUBIO_FREE(p); 201 225 return NULL; … … 228 252 del_fvec (p->buf); 229 253 del_aubio_pitchyinfft (p->p_object); 254 break; 255 case aubio_pitcht_yinfast: 256 del_fvec (p->buf); 257 del_aubio_pitchyinfast (p->p_object); 230 258 break; 231 259 case aubio_pitcht_specacf: … … 319 347 aubio_pitchyinfft_set_tolerance (p->p_object, tol); 320 348 break; 349 case aubio_pitcht_yinfast: 350 aubio_pitchyinfast_set_tolerance (p->p_object, tol); 351 break; 321 352 default: 322 353 break; … … 335 366 case aubio_pitcht_yinfft: 336 367 tolerance = aubio_pitchyinfft_get_tolerance (p->p_object); 368 break; 369 case aubio_pitcht_yinfast: 370 tolerance = aubio_pitchyinfast_get_tolerance (p->p_object); 337 371 break; 338 372 default: … … 404 438 aubio_pitch_slideblock (p, ibuf); 405 439 aubio_pitchyinfft_do (p->p_object, p->buf, obuf); 440 pitch = obuf->data[0]; 441 if (pitch > 0) { 442 pitch = p->samplerate / (pitch + 0.); 443 } else { 444 pitch = 0.; 445 } 446 obuf->data[0] = pitch; 447 } 448 449 void 450 aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) 451 { 452 smpl_t pitch = 0.; 453 aubio_pitch_slideblock (p, ibuf); 454 aubio_pitchyinfast_do (p->p_object, p->buf, obuf); 406 455 pitch = obuf->data[0]; 407 456 if (pitch > 0) { -
src/pitch/pitch.h
r5b46bc3 r633400d 82 82 see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html 83 83 84 \b \p yinfast : Yinfast algorithm 85 86 This algorithm is equivalent to the YIN algorithm, but computed in the 87 spectral domain for efficiency. See also `python/demos/demo_yin_compare.py`. 88 84 89 \b \p yinfft : Yinfft algorithm 85 90 … … 151 156 \param mode set pitch units for output 152 157 158 mode can be one of "Hz", "midi", "cent", or "bin". Defaults to "Hz". 159 153 160 \return 0 if successfull, non-zero otherwise 154 161 -
src/pitch/pitchfcomb.c
r5b46bc3 r633400d 54 54 p->fftSize = bufsize; 55 55 p->stepSize = hopsize; 56 p->fft = new_aubio_fft (bufsize); 57 if (!p->fft) goto beach; 56 58 p->winput = new_fvec (bufsize); 57 59 p->fftOut = new_cvec (bufsize); 58 60 p->fftLastPhase = new_fvec (bufsize); 59 p->fft = new_aubio_fft (bufsize);60 61 p->win = new_aubio_window ("hanning", bufsize); 61 62 return p; 63 64 beach: 65 AUBIO_FREE(p); 66 return NULL; 62 67 } 63 68 -
src/pitch/pitchmcomb.c
r5b46bc3 r633400d 38 38 * sort_pitchpeak(peaks, length); 39 39 */ 40 #if 0 40 41 /** spectral_peak comparison function (must return signed int) */ 41 42 static sint_t aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y); … … 45 46 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, 46 47 smpl_t * cands); 48 #endif 47 49 48 50 /** sort spectral_candidate against their comb ene */ 49 51 void aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates, 50 52 uint_t nbins); 53 #if 0 51 54 /** sort spectral_candidate against their frequency */ 52 55 void aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates, 53 56 uint_t nbins); 57 #endif 54 58 55 59 struct _aubio_pitchmcomb_t … … 134 138 } 135 139 140 #if 0 136 141 uint_t 137 142 aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, smpl_t * cands) … … 164 169 } 165 170 } 171 #endif 166 172 167 173 void … … 314 320 } 315 321 322 #if 0 316 323 void 317 324 aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins) … … 343 350 } 344 351 345 346 352 void 347 353 aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates, … … 357 363 } 358 364 } 365 #endif 359 366 360 367 aubio_pitchmcomb_t * -
src/pitch/pitchspecacf.c
r5b46bc3 r633400d 43 43 { 44 44 aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t); 45 p->fft = new_aubio_fft (bufsize); 46 if (!p->fft) goto beach; 45 47 p->win = new_aubio_window ("hanningz", bufsize); 46 48 p->winput = new_fvec (bufsize); 47 p->fft = new_aubio_fft (bufsize);48 49 p->fftout = new_fvec (bufsize); 49 50 p->sqrmag = new_fvec (bufsize); … … 52 53 p->confidence = 0.; 53 54 return p; 55 56 beach: 57 AUBIO_FREE(p); 58 return NULL; 54 59 } 55 60 -
src/pitch/pitchyin.c
r5b46bc3 r633400d 37 37 fvec_t *yin; 38 38 smpl_t tol; 39 smpl_t confidence;39 uint_t peak_pos; 40 40 }; 41 41 42 #if 0 42 43 /** compute difference function 43 44 … … 61 62 */ 62 63 uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf); 64 #endif 63 65 64 66 aubio_pitchyin_t * … … 68 70 o->yin = new_fvec (bufsize / 2); 69 71 o->tol = 0.15; 72 o->peak_pos = 0; 70 73 return o; 71 74 } … … 78 81 } 79 82 83 #if 0 80 84 /* outputs the difference function */ 81 85 void … … 127 131 return 0; 128 132 } 129 133 #endif 130 134 131 135 /* all the above in one */ … … 133 137 aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out) 134 138 { 135 smpl_t tol = o->tol; 136 fvec_t *yin = o->yin; 137 uint_t j, tau = 0; 139 const smpl_t tol = o->tol; 140 fvec_t* yin = o->yin; 141 const smpl_t *input_data = input->data; 142 const uint_t length = yin->length; 143 smpl_t *yin_data = yin->data; 144 uint_t j, tau; 138 145 sint_t period; 139 smpl_t tmp = 0., tmp2 = 0.; 140 yin->data[0] = 1.; 141 for (tau = 1; tau < yin->length; tau++) { 142 yin->data[tau] = 0.; 143 for (j = 0; j < yin->length; j++) { 144 tmp = input->data[j] - input->data[j + tau]; 145 yin->data[tau] += SQR (tmp); 146 smpl_t tmp, tmp2 = 0.; 147 148 yin_data[0] = 1.; 149 for (tau = 1; tau < length; tau++) { 150 yin_data[tau] = 0.; 151 for (j = 0; j < length; j++) { 152 tmp = input_data[j] - input_data[j + tau]; 153 yin_data[tau] += SQR (tmp); 146 154 } 147 tmp2 += yin ->data[tau];155 tmp2 += yin_data[tau]; 148 156 if (tmp2 != 0) { 149 157 yin->data[tau] *= tau / tmp2; … … 152 160 } 153 161 period = tau - 3; 154 if (tau > 4 && (yin->data[period] < tol) && 155 (yin->data[period] < yin->data[period + 1])) { 156 out->data[0] = fvec_quadratic_peak_pos (yin, period); 157 goto beach; 162 if (tau > 4 && (yin_data[period] < tol) && 163 (yin_data[period] < yin_data[period + 1])) { 164 o->peak_pos = (uint_t)period; 165 out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos); 166 return; 158 167 } 159 168 } 160 out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin)); 161 beach: 162 return; 169 o->peak_pos = (uint_t)fvec_min_elem (yin); 170 out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos); 163 171 } 164 172 165 173 smpl_t 166 174 aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) { 167 o->confidence = 1. - fvec_min (o->yin); 168 return o->confidence; 175 return 1. - o->yin->data[o->peak_pos]; 169 176 } 170 177 -
src/pitch/pitchyinfft.c
r5b46bc3 r633400d 37 37 fvec_t *yinfft; /**< Yin function */ 38 38 smpl_t tol; /**< Yin tolerance */ 39 smpl_t confidence; /**< confidence*/39 uint_t peak_pos; /**< currently selected peak pos*/ 40 40 uint_t short_period; /** shortest period under which to check for octave error */ 41 41 }; … … 45 45 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250., 46 46 1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000., 47 12500., 15000., 20000., 25100 47 12500., 15000., 20000., 25100., -1. 48 48 }; 49 49 … … 63 63 p->winput = new_fvec (bufsize); 64 64 p->fft = new_aubio_fft (bufsize); 65 if (!p->fft) goto beach; 65 66 p->fftout = new_fvec (bufsize); 66 67 p->sqrmag = new_fvec (bufsize); 67 68 p->yinfft = new_fvec (bufsize / 2 + 1); 68 69 p->tol = 0.85; 70 p->peak_pos = 0; 69 71 p->win = new_aubio_window ("hanningz", bufsize); 70 72 p->weight = new_fvec (bufsize / 2 + 1); 71 73 for (i = 0; i < p->weight->length; i++) { 72 74 freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate; 73 while (freq > freqs[j]) { 75 while (freq > freqs[j] && freqs[j] > 0) { 76 //AUBIO_DBG("freq %3.5f > %3.5f \tsamplerate %d (Hz) \t" 77 // "(weight length %d, bufsize %d) %d %d\n", freq, freqs[j], 78 // samplerate, p->weight->length, bufsize, i, j); 74 79 j += 1; 75 80 } … … 96 101 p->short_period = (uint_t)ROUND(samplerate / 1300.); 97 102 return p; 103 104 beach: 105 if (p->winput) del_fvec(p->winput); 106 AUBIO_FREE(p); 107 return NULL; 98 108 } 99 109 … … 156 166 halfperiod = FLOOR (tau / 2 + .5); 157 167 if (yin->data[halfperiod] < p->tol) 158 output->data[0] = fvec_quadratic_peak_pos (yin, halfperiod);168 p->peak_pos = halfperiod; 159 169 else 160 output->data[0] = fvec_quadratic_peak_pos (yin, tau); 170 p->peak_pos = tau; 171 output->data[0] = fvec_quadratic_peak_pos (yin, p->peak_pos); 161 172 } 162 173 } else { 174 p->peak_pos = 0; 163 175 output->data[0] = 0.; 164 176 } … … 180 192 smpl_t 181 193 aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o) { 182 o->confidence = 1. - fvec_min (o->yinfft); 183 return o->confidence; 194 return 1. - o->yinfft->data[o->peak_pos]; 184 195 } 185 196 -
src/spectral/fft.c
r5b46bc3 r633400d 78 78 pthread_mutex_t aubio_fftw_mutex = PTHREAD_MUTEX_INITIALIZER; 79 79 80 #else 81 #ifdef HAVE_ACCELERATE // using ACCELERATE 80 #elif defined HAVE_ACCELERATE // using ACCELERATE 82 81 // https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html 83 82 #include <Accelerate/Accelerate.h> … … 91 90 #define aubio_vDSP_vsadd vDSP_vsadd 92 91 #define aubio_vDSP_vsmul vDSP_vsmul 93 #define aubio_vDSP_create_fftsetup vDSP_create_fftsetup94 #define aubio_vDSP_destroy_fftsetup vDSP_destroy_fftsetup95 92 #define aubio_DSPComplex DSPComplex 96 93 #define aubio_DSPSplitComplex DSPSplitComplex 97 #define aubio_FFTSetup FFTSetup 94 #define aubio_vDSP_DFT_Setup vDSP_DFT_Setup 95 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetup 96 #define aubio_vDSP_DFT_Execute vDSP_DFT_Execute 97 #define aubio_vDSP_DFT_DestroySetup vDSP_DFT_DestroySetup 98 98 #define aubio_vvsqrt vvsqrtf 99 99 #else … … 105 105 #define aubio_vDSP_vsadd vDSP_vsaddD 106 106 #define aubio_vDSP_vsmul vDSP_vsmulD 107 #define aubio_vDSP_create_fftsetup vDSP_create_fftsetupD108 #define aubio_vDSP_destroy_fftsetup vDSP_destroy_fftsetupD109 107 #define aubio_DSPComplex DSPDoubleComplex 110 108 #define aubio_DSPSplitComplex DSPDoubleSplitComplex 111 #define aubio_FFTSetup FFTSetupD 109 #define aubio_vDSP_DFT_Setup vDSP_DFT_SetupD 110 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetupD 111 #define aubio_vDSP_DFT_Execute vDSP_DFT_ExecuteD 112 #define aubio_vDSP_DFT_DestroySetup vDSP_DFT_DestroySetupD 112 113 #define aubio_vvsqrt vvsqrt 113 114 #endif /* HAVE_AUBIO_DOUBLE */ 114 115 115 #else // using OOURA 116 #elif defined HAVE_INTEL_IPP // using INTEL IPP 117 118 #if !HAVE_AUBIO_DOUBLE 119 #define aubio_IppFloat Ipp32f 120 #define aubio_IppComplex Ipp32fc 121 #define aubio_FFTSpec FFTSpec_R_32f 122 #define aubio_ippsMalloc_complex ippsMalloc_32fc 123 #define aubio_ippsFFTInit_R ippsFFTInit_R_32f 124 #define aubio_ippsFFTGetSize_R ippsFFTGetSize_R_32f 125 #define aubio_ippsFFTInv_CCSToR ippsFFTInv_CCSToR_32f 126 #define aubio_ippsFFTFwd_RToCCS ippsFFTFwd_RToCCS_32f 127 #define aubio_ippsAtan2 ippsAtan2_32f_A21 128 #else /* HAVE_AUBIO_DOUBLE */ 129 #define aubio_IppFloat Ipp64f 130 #define aubio_IppComplex Ipp64fc 131 #define aubio_FFTSpec FFTSpec_R_64f 132 #define aubio_ippsMalloc_complex ippsMalloc_64fc 133 #define aubio_ippsFFTInit_R ippsFFTInit_R_64f 134 #define aubio_ippsFFTGetSize_R ippsFFTGetSize_R_64f 135 #define aubio_ippsFFTInv_CCSToR ippsFFTInv_CCSToR_64f 136 #define aubio_ippsFFTFwd_RToCCS ippsFFTFwd_RToCCS_64f 137 #define aubio_ippsAtan2 ippsAtan2_64f_A50 138 #endif 139 140 141 #else // using OOURA 116 142 // let's use ooura instead 117 143 extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *); 118 144 119 #endif /* HAVE_ACCELERATE */ 120 #endif /* HAVE_FFTW3 */ 145 #endif 121 146 122 147 struct _aubio_fft_t { 123 148 uint_t winsize; 124 149 uint_t fft_size; 150 125 151 #ifdef HAVE_FFTW3 // using FFTW3 126 152 real_t *in, *out; 127 153 fftw_plan pfw, pbw; 128 fft_data_t * specdata; 129 #else 130 # ifdef HAVE_ACCELERATE// using ACCELERATE131 int log2fftsize;132 aubio_ FFTSetup fftSetup;154 fft_data_t * specdata; /* complex spectral data */ 155 156 #elif defined HAVE_ACCELERATE // using ACCELERATE 157 aubio_vDSP_DFT_Setup fftSetupFwd; 158 aubio_vDSP_DFT_Setup fftSetupBwd; 133 159 aubio_DSPSplitComplex spec; 134 160 smpl_t *in, *out; 161 162 #elif defined HAVE_INTEL_IPP // using Intel IPP 163 smpl_t *in, *out; 164 Ipp8u* memSpec; 165 Ipp8u* memInit; 166 Ipp8u* memBuffer; 167 struct aubio_FFTSpec* fftSpec; 168 aubio_IppComplex* complexOut; 135 169 #else // using OOURA 136 170 smpl_t *in, *out; 137 171 smpl_t *w; 138 172 int *ip; 139 #endif /* HAVE_ACCELERATE*/140 #endif /* HAVE_FFTW3 */ 173 #endif /* using OOURA */ 174 141 175 fvec_t * compspec; 142 176 }; … … 148 182 goto beach; 149 183 } 184 150 185 #ifdef HAVE_FFTW3 151 186 uint_t i; … … 176 211 s->specdata[i] = 0.; 177 212 } 178 #else 179 #ifdef HAVE_ACCELERATE // using ACCELERATE 213 214 #elif defined HAVE_ACCELERATE // using ACCELERATE 215 { 216 uint_t radix = winsize; 217 uint_t order = 0; 218 while ((radix / 2) * 2 == radix) { 219 radix /= 2; 220 order++; 221 } 222 if (order < 4 || (radix != 1 && radix != 3 && radix != 5 && radix != 15)) { 223 AUBIO_ERR("fft: vDSP/Accelerate supports FFT with sizes = " 224 "f * 2 ** n, where n > 4 and f in [1, 3, 5, 15], but requested %d. " 225 "Use the closest power of two, or try recompiling aubio with " 226 "--enable-fftw3.\n", winsize); 227 goto beach; 228 } 229 } 180 230 s->winsize = winsize; 181 231 s->fft_size = winsize; 182 232 s->compspec = new_fvec(winsize); 183 s->log2fftsize = (uint_t)log2f(s->fft_size);184 233 s->in = AUBIO_ARRAY(smpl_t, s->fft_size); 185 234 s->out = AUBIO_ARRAY(smpl_t, s->fft_size); 186 235 s->spec.realp = AUBIO_ARRAY(smpl_t, s->fft_size/2); 187 236 s->spec.imagp = AUBIO_ARRAY(smpl_t, s->fft_size/2); 188 s->fftSetup = aubio_vDSP_create_fftsetup(s->log2fftsize, FFT_RADIX2); 237 s->fftSetupFwd = aubio_vDSP_DFT_zrop_CreateSetup(NULL, 238 s->fft_size, vDSP_DFT_FORWARD); 239 s->fftSetupBwd = aubio_vDSP_DFT_zrop_CreateSetup(s->fftSetupFwd, 240 s->fft_size, vDSP_DFT_INVERSE); 241 242 #elif defined HAVE_INTEL_IPP // using Intel IPP 243 const IppHintAlgorithm qualityHint = ippAlgHintAccurate; // OR ippAlgHintFast; 244 const int flags = IPP_FFT_NODIV_BY_ANY; // we're scaling manually afterwards 245 int order = aubio_power_of_two_order(winsize); 246 int sizeSpec, sizeInit, sizeBuffer; 247 IppStatus status; 248 249 if (winsize <= 4 || aubio_is_power_of_two(winsize) != 1) 250 { 251 AUBIO_ERR("intel IPP fft: can only create with sizes > 4 and power of two, requested %d," 252 " try recompiling aubio with --enable-fftw3\n", winsize); 253 goto beach; 254 } 255 256 status = aubio_ippsFFTGetSize_R(order, flags, qualityHint, 257 &sizeSpec, &sizeInit, &sizeBuffer); 258 if (status != ippStsNoErr) { 259 AUBIO_ERR("fft: failed to initialize fft. IPP error: %d\n", status); 260 goto beach; 261 } 262 s->fft_size = s->winsize = winsize; 263 s->compspec = new_fvec(winsize); 264 s->in = AUBIO_ARRAY(smpl_t, s->winsize); 265 s->out = AUBIO_ARRAY(smpl_t, s->winsize); 266 s->memSpec = ippsMalloc_8u(sizeSpec); 267 s->memBuffer = ippsMalloc_8u(sizeBuffer); 268 if (sizeInit > 0 ) { 269 s->memInit = ippsMalloc_8u(sizeInit); 270 } 271 s->complexOut = aubio_ippsMalloc_complex(s->fft_size / 2 + 1); 272 status = aubio_ippsFFTInit_R( 273 &s->fftSpec, order, flags, qualityHint, s->memSpec, s->memInit); 274 if (status != ippStsNoErr) { 275 AUBIO_ERR("fft: failed to initialize. IPP error: %d\n", status); 276 goto beach; 277 } 278 189 279 #else // using OOURA 190 280 if (aubio_is_power_of_two(winsize) != 1) { … … 201 291 s->w = AUBIO_ARRAY(smpl_t, s->fft_size); 202 292 s->ip[0] = 0; 203 #endif /* HAVE_ACCELERATE*/204 #endif /* HAVE_FFTW3 */ 293 #endif /* using OOURA */ 294 205 295 return s; 296 206 297 beach: 207 298 AUBIO_FREE(s); … … 211 302 void del_aubio_fft(aubio_fft_t * s) { 212 303 /* destroy data */ 213 del_fvec(s->compspec);214 304 #ifdef HAVE_FFTW3 // using FFTW3 215 305 pthread_mutex_lock(&aubio_fftw_mutex); … … 218 308 fftw_free(s->specdata); 219 309 pthread_mutex_unlock(&aubio_fftw_mutex); 220 #else /* HAVE_FFTW3 */ 221 # ifdef HAVE_ACCELERATE// using ACCELERATE310 311 #elif defined HAVE_ACCELERATE // using ACCELERATE 222 312 AUBIO_FREE(s->spec.realp); 223 313 AUBIO_FREE(s->spec.imagp); 224 aubio_vDSP_destroy_fftsetup(s->fftSetup); 314 aubio_vDSP_DFT_DestroySetup(s->fftSetupBwd); 315 aubio_vDSP_DFT_DestroySetup(s->fftSetupFwd); 316 317 #elif defined HAVE_INTEL_IPP // using Intel IPP 318 ippFree(s->memSpec); 319 ippFree(s->memInit); 320 ippFree(s->memBuffer); 321 ippFree(s->complexOut); 322 225 323 #else // using OOURA 226 324 AUBIO_FREE(s->w); 227 325 AUBIO_FREE(s->ip); 228 #endif /* HAVE_ACCELERATE */ 229 #endif /* HAVE_FFTW3 */ 326 #endif 327 328 del_fvec(s->compspec); 329 AUBIO_FREE(s->in); 230 330 AUBIO_FREE(s->out); 231 AUBIO_FREE(s->in);232 331 AUBIO_FREE(s); 233 332 } … … 252 351 memcpy(s->in, input->data, s->winsize * sizeof(smpl_t)); 253 352 #endif /* HAVE_MEMCPY_HACKS */ 353 254 354 #ifdef HAVE_FFTW3 // using FFTW3 255 355 fftw_execute(s->pfw); … … 266 366 } 267 367 #endif /* HAVE_COMPLEX_H */ 268 #else /* HAVE_FFTW3 */ 269 # ifdef HAVE_ACCELERATE// using ACCELERATE368 369 #elif defined HAVE_ACCELERATE // using ACCELERATE 270 370 // convert real data to even/odd format used in vDSP 271 371 aubio_vDSP_ctoz((aubio_DSPComplex*)s->in, 2, &s->spec, 1, s->fft_size/2); 272 372 // compute the FFT 273 aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD); 373 aubio_vDSP_DFT_Execute(s->fftSetupFwd, s->spec.realp, s->spec.imagp, 374 s->spec.realp, s->spec.imagp); 274 375 // convert from vDSP complex split to [ r0, r1, ..., rN, iN-1, .., i2, i1] 275 376 compspec->data[0] = s->spec.realp[0]; … … 282 383 smpl_t scale = 1./2.; 283 384 aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size); 385 386 #elif defined HAVE_INTEL_IPP // using Intel IPP 387 388 // apply fft 389 aubio_ippsFFTFwd_RToCCS(s->in, (aubio_IppFloat*)s->complexOut, s->fftSpec, s->memBuffer); 390 // convert complex buffer to [ r0, r1, ..., rN, iN-1, .., i2, i1] 391 compspec->data[0] = s->complexOut[0].re; 392 compspec->data[s->fft_size / 2] = s->complexOut[s->fft_size / 2].re; 393 for (i = 1; i < s->fft_size / 2; i++) { 394 compspec->data[i] = s->complexOut[i].re; 395 compspec->data[s->fft_size - i] = s->complexOut[i].im; 396 } 397 284 398 #else // using OOURA 285 399 aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w); … … 290 404 compspec->data[s->winsize - i] = - s->in[2 * i + 1]; 291 405 } 292 #endif /* HAVE_ACCELERATE */ 293 #endif /* HAVE_FFTW3 */ 406 #endif /* using OOURA */ 294 407 } 295 408 … … 314 427 output->data[i] = s->out[i]*renorm; 315 428 } 316 #else /* HAVE_FFTW3 */ 317 # ifdef HAVE_ACCELERATE// using ACCELERATE429 430 #elif defined HAVE_ACCELERATE // using ACCELERATE 318 431 // convert from real imag [ r0, r1, ..., rN, iN-1, .., i2, i1] 319 432 // to vDSP packed format [ r0, rN, r1, i1, ..., rN-1, iN-1 ] … … 327 440 aubio_vDSP_ctoz((aubio_DSPComplex*)s->out, 2, &s->spec, 1, s->fft_size/2); 328 441 // compute the FFT 329 aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE); 442 aubio_vDSP_DFT_Execute(s->fftSetupBwd, s->spec.realp, s->spec.imagp, 443 s->spec.realp, s->spec.imagp); 330 444 // convert result to real output 331 445 aubio_vDSP_ztoc(&s->spec, 1, (aubio_DSPComplex*)output->data, 2, s->fft_size/2); … … 333 447 smpl_t scale = 1.0 / s->winsize; 334 448 aubio_vDSP_vsmul(output->data, 1, &scale, output->data, 1, s->fft_size); 449 450 #elif defined HAVE_INTEL_IPP // using Intel IPP 451 452 // convert from real imag [ r0, 0, ..., rN, iN-1, .., i2, i1, iN-1] to complex format 453 s->complexOut[0].re = compspec->data[0]; 454 s->complexOut[0].im = 0; 455 s->complexOut[s->fft_size / 2].re = compspec->data[s->fft_size / 2]; 456 s->complexOut[s->fft_size / 2].im = 0.0; 457 for (i = 1; i < s->fft_size / 2; i++) { 458 s->complexOut[i].re = compspec->data[i]; 459 s->complexOut[i].im = compspec->data[s->fft_size - i]; 460 } 461 // apply fft 462 aubio_ippsFFTInv_CCSToR((const aubio_IppFloat *)s->complexOut, output->data, s->fftSpec, s->memBuffer); 463 // apply scaling 464 aubio_ippsMulC(output->data, 1.0 / s->winsize, output->data, s->fft_size); 465 335 466 #else // using OOURA 336 467 smpl_t scale = 2.0 / s->winsize; … … 345 476 output->data[i] = s->out[i] * scale; 346 477 } 347 #endif /* HAVE_ACCELERATE */ 348 #endif /* HAVE_FFTW3 */ 478 #endif 349 479 } 350 480 … … 366 496 spectrum->phas[0] = 0.; 367 497 } 498 #if defined(HAVE_INTEL_IPP) 499 // convert from real imag [ r0, r1, ..., rN, iN-1, ..., i2, i1, i0] 500 // to [ r0, r1, ..., rN, i0, i1, i2, ..., iN-1] 501 for (i = 1; i < spectrum->length / 2; i++) { 502 ELEM_SWAP(compspec->data[compspec->length - i], 503 compspec->data[spectrum->length + i - 1]); 504 } 505 aubio_ippsAtan2(compspec->data + spectrum->length, 506 compspec->data + 1, spectrum->phas + 1, spectrum->length - 1); 507 // revert the imaginary part back again 508 for (i = 1; i < spectrum->length / 2; i++) { 509 ELEM_SWAP(compspec->data[spectrum->length + i - 1], 510 compspec->data[compspec->length - i]); 511 } 512 #else 368 513 for (i=1; i < spectrum->length - 1; i++) { 369 514 spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i], 370 515 compspec->data[i]); 371 516 } 372 if (compspec->data[compspec->length/2] < 0) { 373 spectrum->phas[spectrum->length - 1] = PI; 517 #endif 518 #ifdef HAVE_FFTW3 519 // for even length only, make sure last element is 0 or PI 520 if (2 * (compspec->length / 2) == compspec->length) { 521 #endif 522 if (compspec->data[compspec->length/2] < 0) { 523 spectrum->phas[spectrum->length - 1] = PI; 524 } else { 525 spectrum->phas[spectrum->length - 1] = 0.; 526 } 527 #ifdef HAVE_FFTW3 374 528 } else { 375 spectrum->phas[spectrum->length - 1] = 0.; 376 } 529 i = spectrum->length - 1; 530 spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i], 531 compspec->data[i]); 532 } 533 #endif 377 534 } 378 535 … … 384 541 + SQR(compspec->data[compspec->length - i]) ); 385 542 } 386 spectrum->norm[spectrum->length-1] = 387 ABS(compspec->data[compspec->length/2]); 543 #ifdef HAVE_FFTW3 544 // for even length, make sure last element is > 0 545 if (2 * (compspec->length / 2) == compspec->length) { 546 #endif 547 spectrum->norm[spectrum->length-1] = 548 ABS(compspec->data[compspec->length/2]); 549 #ifdef HAVE_FFTW3 550 } else { 551 i = spectrum->length - 1; 552 spectrum->norm[i] = SQRT(SQR(compspec->data[i]) 553 + SQR(compspec->data[compspec->length - i]) ); 554 } 555 #endif 388 556 } 389 557 -
src/spectral/filterbank.c
r5b46bc3 r633400d 24 24 #include "fmat.h" 25 25 #include "cvec.h" 26 #include "vecutils.h" 26 27 #include "spectral/filterbank.h" 27 28 #include "mathutils.h" … … 33 34 uint_t n_filters; 34 35 fmat_t *filters; 36 smpl_t norm; 37 smpl_t power; 35 38 }; 36 39 … … 40 43 /* allocate space for filterbank object */ 41 44 aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t); 45 46 if ((sint_t)n_filters <= 0) { 47 AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters); 48 goto fail; 49 } 50 if ((sint_t)win_s <= 0) { 51 AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s); 52 goto fail; 53 } 42 54 fb->win_s = win_s; 43 55 fb->n_filters = n_filters; … … 46 58 fb->filters = new_fmat (n_filters, win_s / 2 + 1); 47 59 60 fb->norm = 1; 61 62 fb->power = 1; 63 48 64 return fb; 65 fail: 66 AUBIO_FREE (fb); 67 return NULL; 49 68 } 50 69 … … 68 87 tmp.data = in->norm; 69 88 89 if (f->power != 1.) fvec_pow(&tmp, f->power); 90 70 91 fmat_vecmul(f->filters, &tmp, out); 71 92 … … 85 106 return 0; 86 107 } 108 109 uint_t 110 aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm) 111 { 112 if (norm != 0 && norm != 1) return AUBIO_FAIL; 113 f->norm = norm; 114 return AUBIO_OK; 115 } 116 117 smpl_t 118 aubio_filterbank_get_norm (aubio_filterbank_t *f) 119 { 120 return f->norm; 121 } 122 123 uint_t 124 aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power) 125 { 126 f->power = power; 127 return AUBIO_OK; 128 } 129 130 smpl_t 131 aubio_filterbank_get_power (aubio_filterbank_t *f) 132 { 133 return f->power; 134 } -
src/spectral/filterbank.h
r5b46bc3 r633400d 84 84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters); 85 85 86 /** set norm parameter 87 88 \param f filterbank object, as returned by new_aubio_filterbank() 89 \param norm `1` to norm the filters, `0` otherwise. 90 91 If set to `0`, the filters will not be normalized. If set to `1`, 92 each filter will be normalized to one. Defaults to `1`. 93 94 This function should be called *before* setting the filters with one of 95 aubio_filterbank_set_triangle_bands(), aubio_filterbank_set_mel_coeffs(), 96 aubio_filterbank_set_mel_coeffs_htk(), or 97 aubio_filterbank_set_mel_coeffs_slaney(). 98 99 */ 100 uint_t aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm); 101 102 /** get norm parameter 103 104 \param f filterbank object, as returned by new_aubio_filterbank() 105 \returns `1` if norm is set, `0` otherwise. Defaults to `1`. 106 107 */ 108 smpl_t aubio_filterbank_get_norm (aubio_filterbank_t *f); 109 110 /** set power parameter 111 112 \param f filterbank object, as returned by new_aubio_filterbank() 113 \param power Raise norm of the input spectrum norm to this power before 114 computing filterbank. Defaults to `1`. 115 116 */ 117 uint_t aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power); 118 119 /** get power parameter 120 121 \param f filterbank object, as returned by new_aubio_filterbank() 122 \return current power parameter. Defaults to `1`. 123 124 */ 125 smpl_t aubio_filterbank_get_power (aubio_filterbank_t *f); 126 86 127 #ifdef __cplusplus 87 128 } -
src/spectral/filterbank_mel.c
r5b46bc3 r633400d 55 55 } 56 56 57 if (freqs->data[freqs->length - 1] > samplerate / 2) { 58 AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \ 59 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]); 57 for (fn = 0; fn < freqs->length; fn++) { 58 if (freqs->data[fn] < 0) { 59 AUBIO_ERR("filterbank_mel: freqs must contain only positive values.\n"); 60 return AUBIO_FAIL; 61 } else if (freqs->data[fn] > samplerate / 2) { 62 AUBIO_WRN("filterbank_mel: freqs should contain only " 63 "values < samplerate / 2.\n"); 64 } else if (fn > 0 && freqs->data[fn] < freqs->data[fn-1]) { 65 AUBIO_ERR("filterbank_mel: freqs should be a list of frequencies " 66 "sorted from low to high, but freq[%d] < freq[%d-1]\n", fn, fn); 67 return AUBIO_FAIL; 68 } else if (fn > 0 && freqs->data[fn] == freqs->data[fn-1]) { 69 AUBIO_WRN("filterbank_mel: set_triangle_bands received a list " 70 "with twice the frequency %f\n", freqs->data[fn]); 71 } 60 72 } 61 73 … … 79 91 80 92 /* compute triangle heights so that each triangle has unit area */ 81 for (fn = 0; fn < n_filters; fn++) { 82 triangle_heights->data[fn] = 83 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 93 if (aubio_filterbank_get_norm(fb)) { 94 for (fn = 0; fn < n_filters; fn++) { 95 triangle_heights->data[fn] = 96 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 97 } 98 } else { 99 fvec_ones (triangle_heights); 84 100 } 85 101 … … 92 108 /* zeroing of all filters */ 93 109 fmat_zeros (filters); 94 95 if (fft_freqs->data[1] >= lower_freqs->data[0]) {96 /* - 1 to make sure we don't miss the smallest power of two */97 uint_t min_win_s =98 (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;99 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \100 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",101 fft_freqs->data[1], lower_freqs->data[0],102 upper_freqs->data[0], (win_s - 1) * 2,103 aubio_next_power_of_two (min_win_s));104 }105 110 106 111 /* building each filter table */ … … 117 122 118 123 /* compute positive slope step size */ 119 riseInc = 120 triangle_heights->data[fn] / 121 (center_freqs->data[fn] - lower_freqs->data[fn]); 124 riseInc = triangle_heights->data[fn] 125 / (center_freqs->data[fn] - lower_freqs->data[fn]); 122 126 123 127 /* compute coefficients in positive slope */ … … 133 137 134 138 /* compute negative slope step size */ 135 downInc = 136 triangle_heights->data[fn] / 137 (upper_freqs->data[fn] - center_freqs->data[fn]); 139 downInc = triangle_heights->data[fn] 140 / (upper_freqs->data[fn] - center_freqs->data[fn]); 138 141 139 142 /* compute coefficents in negative slope */ … … 161 164 del_fvec (fft_freqs); 162 165 163 return 0;166 return AUBIO_OK; 164 167 } 165 168 … … 168 171 smpl_t samplerate) 169 172 { 170 uint_t retval;171 172 173 /* Malcolm Slaney parameters */ 173 smpl_t lowestFrequency = 133.3333; 174 smpl_t linearSpacing = 66.66666666; 175 smpl_t logSpacing = 1.0711703; 176 177 uint_t linearFilters = 13; 178 uint_t logFilters = 27; 179 uint_t n_filters = linearFilters + logFilters; 180 181 uint_t fn; /* filter counter */ 182 174 const smpl_t lowestFrequency = 133.3333; 175 const smpl_t linearSpacing = 66.66666666; 176 const smpl_t logSpacing = 1.0711703; 177 178 const uint_t linearFilters = 13; 179 const uint_t logFilters = 27; 180 const uint_t n_filters = linearFilters + logFilters; 181 182 uint_t fn, retval; 183 183 smpl_t lastlinearCF; 184 184 185 185 /* buffers to compute filter frequencies */ 186 fvec_t *freqs = new_fvec (n_filters + 2); 186 fvec_t *freqs; 187 188 if (samplerate <= 0) { 189 AUBIO_ERR("filterbank: set_mel_coeffs_slaney samplerate should be > 0\n"); 190 return AUBIO_FAIL; 191 } 192 193 freqs = new_fvec (n_filters + 2); 187 194 188 195 /* first step: fill all the linear filter frequencies */ … … 206 213 return retval; 207 214 } 215 216 static uint_t aubio_filterbank_check_freqs (aubio_filterbank_t *fb UNUSED, 217 smpl_t samplerate, smpl_t *freq_min, smpl_t *freq_max) 218 { 219 if (samplerate <= 0) { 220 AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n"); 221 return AUBIO_FAIL; 222 } 223 if (*freq_max < 0) { 224 AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n"); 225 return AUBIO_FAIL; 226 } else if (*freq_max == 0) { 227 *freq_max = samplerate / 2.; 228 } 229 if (*freq_min < 0) { 230 AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n"); 231 return AUBIO_FAIL; 232 } 233 return AUBIO_OK; 234 } 235 236 uint_t 237 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate, 238 smpl_t freq_min, smpl_t freq_max) 239 { 240 uint_t m, retval; 241 smpl_t start = freq_min, end = freq_max, step; 242 fvec_t *freqs; 243 fmat_t *coeffs = aubio_filterbank_get_coeffs(fb); 244 uint_t n_bands = coeffs->height; 245 246 if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) { 247 return AUBIO_FAIL; 248 } 249 250 start = aubio_hztomel(start); 251 end = aubio_hztomel(end); 252 253 freqs = new_fvec(n_bands + 2); 254 step = (end - start) / (n_bands + 1); 255 256 for (m = 0; m < n_bands + 2; m++) 257 { 258 freqs->data[m] = MIN(aubio_meltohz(start + step * m), samplerate/2.); 259 } 260 261 retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate); 262 263 /* destroy vector used to store frequency limits */ 264 del_fvec (freqs); 265 return retval; 266 } 267 268 uint_t 269 aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate, 270 smpl_t freq_min, smpl_t freq_max) 271 { 272 uint_t m, retval; 273 smpl_t start = freq_min, end = freq_max, step; 274 fvec_t *freqs; 275 fmat_t *coeffs = aubio_filterbank_get_coeffs(fb); 276 uint_t n_bands = coeffs->height; 277 278 if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) { 279 return AUBIO_FAIL; 280 } 281 282 start = aubio_hztomel_htk(start); 283 end = aubio_hztomel_htk(end); 284 285 freqs = new_fvec (n_bands + 2); 286 step = (end - start) / (n_bands + 1); 287 288 for (m = 0; m < n_bands + 2; m++) 289 { 290 freqs->data[m] = MIN(aubio_meltohz_htk(start + step * m), samplerate/2.); 291 } 292 293 retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate); 294 295 /* destroy vector used to store frequency limits */ 296 del_fvec (freqs); 297 return retval; 298 } -
src/spectral/filterbank_mel.h
r5b46bc3 r633400d 56 56 57 57 \param fb filterbank object 58 \param samplerate audio sampling rate 58 \param samplerate audio sampling rate, in Hz 59 59 60 The filter coefficients are built according to Malcolm Slaney's Auditory 61 Toolbox, available at http://engineering.purdue.edu/~malcolm/interval/1998-010/ 62 (see file mfcc.m). 60 The filter coefficients are built to match exactly Malcolm Slaney's Auditory 61 Toolbox implementation (see file mfcc.m). The number of filters should be 40. 62 63 References 64 ---------- 65 66 Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010* 67 https://engineering.purdue.edu/~malcolm/interval/1998-010/ 63 68 64 69 */ 65 70 uint_t aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb, 66 71 smpl_t samplerate); 72 73 /** Mel filterbank initialization 74 75 \param fb filterbank object 76 \param samplerate audio sampling rate 77 \param fmin start frequency, in Hz 78 \param fmax end frequency, in Hz 79 80 The filterbank will be initialized with bands linearly spaced in the mel 81 scale, from `fmin` to `fmax`. 82 83 References 84 ---------- 85 86 Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010* 87 https://engineering.purdue.edu/~malcolm/interval/1998-010/ 88 89 */ 90 uint_t aubio_filterbank_set_mel_coeffs(aubio_filterbank_t * fb, 91 smpl_t samplerate, smpl_t fmin, smpl_t fmax); 92 93 /** Mel filterbank initialization 94 95 \param fb filterbank object 96 \param samplerate audio sampling rate 97 \param fmin start frequency, in Hz 98 \param fmax end frequency, in Hz 99 100 The bank of filters will be initalized to to cover linearly spaced bands in 101 the Htk mel scale, from `fmin` to `fmax`. 102 103 References 104 ---------- 105 106 Douglas O'Shaughnessy (1987). *Speech communication: human and machine*. 107 Addison-Wesley. p. 150. ISBN 978-0-201-16520-3. 108 109 HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/ 110 111 */ 112 uint_t aubio_filterbank_set_mel_coeffs_htk(aubio_filterbank_t * fb, 113 smpl_t samplerate, smpl_t fmin, smpl_t fmax); 67 114 68 115 #ifdef __cplusplus -
src/spectral/mfcc.c
r5b46bc3 r633400d 29 29 #include "spectral/filterbank.h" 30 30 #include "spectral/filterbank_mel.h" 31 #include "spectral/dct.h" 31 32 #include "spectral/mfcc.h" 32 33 … … 37 38 uint_t win_s; /** grain length */ 38 39 uint_t samplerate; /** sample rate (needed?) */ 39 uint_t n_filters; /** number of *filters */40 uint_t n_filters; /** number of filters */ 40 41 uint_t n_coefs; /** number of coefficients (<= n_filters/2 +1) */ 41 42 aubio_filterbank_t *fb; /** filter bank */ 42 43 fvec_t *in_dct; /** input buffer for dct * [fb->n_filters] */ 43 fmat_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */ 44 aubio_dct_t *dct; /** dct object */ 45 fvec_t *output; /** dct output */ 46 smpl_t scale; 44 47 }; 45 48 … … 52 55 /* allocate space for mfcc object */ 53 56 aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t); 54 smpl_t scaling;55 57 56 uint_t i, j; 58 if ((sint_t)n_coefs <= 0) { 59 AUBIO_ERR("mfcc: n_coefs should be > 0, got %d\n", n_coefs); 60 goto failure; 61 } 62 if ((sint_t)samplerate <= 0) { 63 AUBIO_ERR("mfcc: samplerate should be > 0, got %d\n", samplerate); 64 goto failure; 65 } 57 66 58 67 mfcc->win_s = win_s; … … 63 72 /* filterbank allocation */ 64 73 mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s); 65 aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate); 74 75 if (!mfcc->fb) 76 goto failure; 77 78 if (n_filters == 40) 79 aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate); 80 else 81 aubio_filterbank_set_mel_coeffs(mfcc->fb, samplerate, 82 0, samplerate/2.); 66 83 67 84 /* allocating buffers */ 68 85 mfcc->in_dct = new_fvec (n_filters); 69 86 70 mfcc->dct_coeffs = new_fmat (n_coefs, n_filters); 87 mfcc->dct = new_aubio_dct (n_filters); 88 mfcc->output = new_fvec (n_filters); 71 89 72 /* compute DCT transform dct_coeffs[j][i] as 73 cos ( j * (i+.5) * PI / n_filters ) */ 74 scaling = 1. / SQRT (n_filters / 2.); 75 for (i = 0; i < n_filters; i++) { 76 for (j = 0; j < n_coefs; j++) { 77 mfcc->dct_coeffs->data[j][i] = 78 scaling * COS (j * (i + 0.5) * PI / n_filters); 79 } 80 mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.; 81 } 90 if (!mfcc->in_dct || !mfcc->dct || !mfcc->output) 91 goto failure; 92 93 mfcc->scale = 1.; 82 94 83 95 return mfcc; 96 97 failure: 98 del_aubio_mfcc(mfcc); 99 return NULL; 84 100 } 85 101 … … 87 103 del_aubio_mfcc (aubio_mfcc_t * mf) 88 104 { 89 90 /* delete filterbank */ 91 del_aubio_filterbank (mf->fb); 92 93 /* delete buffers */ 94 del_fvec (mf->in_dct); 95 del_fmat (mf->dct_coeffs); 96 97 /* delete mfcc object */ 105 if (mf->fb) 106 del_aubio_filterbank (mf->fb); 107 if (mf->in_dct) 108 del_fvec (mf->in_dct); 109 if (mf->dct) 110 del_aubio_dct (mf->dct); 111 if (mf->output) 112 del_fvec (mf->output); 98 113 AUBIO_FREE (mf); 99 114 } … … 103 118 aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out) 104 119 { 120 fvec_t tmp; 121 105 122 /* compute filterbank */ 106 123 aubio_filterbank_do (mf->fb, in, mf->in_dct); … … 109 126 fvec_log10 (mf->in_dct); 110 127 111 /* raise power */ 112 //fvec_pow (mf->in_dct, 3.); 128 if (mf->scale != 1) fvec_mul (mf->in_dct, mf->scale); 113 129 114 130 /* compute mfccs */ 115 fmat_vecmul(mf->dct_coeffs, mf->in_dct, out); 131 aubio_dct_do(mf->dct, mf->in_dct, mf->output); 132 // copy only first n_coeffs elements 133 // TODO assert mf->output->length == n_coeffs 134 tmp.data = mf->output->data; 135 tmp.length = out->length; 136 fvec_copy(&tmp, out); 116 137 117 138 return; 118 139 } 140 141 uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power) 142 { 143 return aubio_filterbank_set_power(mf->fb, power); 144 } 145 146 smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf) 147 { 148 return aubio_filterbank_get_power(mf->fb); 149 } 150 151 uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale) 152 { 153 mf->scale = scale; 154 return AUBIO_OK; 155 } 156 157 smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf) 158 { 159 return mf->scale; 160 } 161 162 uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf, smpl_t freq_min, 163 smpl_t freq_max) 164 { 165 return aubio_filterbank_set_mel_coeffs(mf->fb, mf->samplerate, 166 freq_min, freq_max); 167 } 168 169 uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf, smpl_t freq_min, 170 smpl_t freq_max) 171 { 172 return aubio_filterbank_set_mel_coeffs_htk(mf->fb, mf->samplerate, 173 freq_min, freq_max); 174 } 175 176 uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf) 177 { 178 return aubio_filterbank_set_mel_coeffs_slaney (mf->fb, mf->samplerate); 179 } -
src/spectral/mfcc.h
r5b46bc3 r633400d 27 27 28 28 The implementation follows the specifications established by Malcolm Slaney 29 in its Auditory Toolbox, available online (see file mfcc.m). 29 in its Auditory Toolbox, available online at the following address (see 30 file mfcc.m): 30 31 31 http ://engineering.ecn.purdue.edu/~malcolm/interval/1998-010/32 https://engineering.purdue.edu/~malcolm/interval/1998-010/ 32 33 33 34 \example spectral/test-mfcc.c … … 73 74 void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out); 74 75 76 /** set power parameter 77 78 \param mf mfcc object, as returned by new_aubio_mfcc() 79 \param power Raise norm of the input spectrum norm to this power before 80 computing filterbank. Defaults to `1`. 81 82 See aubio_filterbank_set_power(). 83 84 */ 85 uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power); 86 87 /** get power parameter 88 89 \param mf mfcc object, as returned by new_aubio_mfcc() 90 \return current power parameter. Defaults to `1`. 91 92 See aubio_filterbank_get_power(). 93 94 */ 95 smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf); 96 97 /** set scaling parameter 98 99 \param mf mfcc object, as returned by new_aubio_mfcc() 100 \param scale Scaling value to apply. 101 102 Scales the output of the filterbank after taking its logarithm and before 103 computing the DCT. Defaults to `1`. 104 105 */ 106 uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale); 107 108 /** get scaling parameter 109 110 \param mf mfcc object, as returned by new_aubio_mfcc() 111 \return current scaling parameter. Defaults to `1`. 112 113 */ 114 smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf); 115 116 /** Mel filterbank initialization 117 118 \param mf mfcc object 119 \param fmin start frequency, in Hz 120 \param fmax end frequency, in Hz 121 122 The filterbank will be initialized with bands linearly spaced in the mel 123 scale, from `fmin` to `fmax`. 124 125 See also 126 -------- 127 128 aubio_filterbank_set_mel_coeffs() 129 130 */ 131 uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf, 132 smpl_t fmin, smpl_t fmax); 133 134 /** Mel filterbank initialization 135 136 \param mf mfcc object 137 \param fmin start frequency, in Hz 138 \param fmax end frequency, in Hz 139 140 The bank of filters will be initalized to to cover linearly spaced bands in 141 the Htk mel scale, from `fmin` to `fmax`. 142 143 See also 144 -------- 145 146 aubio_filterbank_set_mel_coeffs_htk() 147 148 */ 149 uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf, 150 smpl_t fmin, smpl_t fmax); 151 152 /** Mel filterbank initialization (Auditory Toolbox's parameters) 153 154 \param mf mfcc object 155 156 The filter coefficients are built to match exactly Malcolm Slaney's Auditory 157 Toolbox implementation. The number of filters should be 40. 158 159 This is the default filterbank when `mf` was created with `n_filters = 40`. 160 161 See also 162 -------- 163 164 aubio_filterbank_set_mel_coeffs_slaney() 165 166 */ 167 uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf); 168 75 169 #ifdef __cplusplus 76 170 } -
src/spectral/ooura_fft8g.c
r5b46bc3 r633400d 3 3 // - include "aubio_priv.h" (for config.h and types.h) 4 4 // - add missing prototypes 5 // - use COS and SIN macros 5 // - use COS, SIN, and ATAN macros 6 // - add cast to (smpl_t) to avoid float conversion warnings 6 7 // - declare initialization as static 7 8 // - prefix public function with aubio_ooura_ … … 364 365 a[1] = xi; 365 366 } else { 366 a[1] = 0.5 * (a[0] - a[1]);367 a[1] = (smpl_t)0.5 * (a[0] - a[1]); 367 368 a[0] -= a[1]; 368 369 if (n > 4) { … … 693 694 if (nw > 2) { 694 695 nwh = nw >> 1; 695 delta = atan(1.0) / nwh;696 delta = ATAN(1.0) / nwh; 696 697 w[0] = 1; 697 698 w[1] = 0; … … 727 728 if (nc > 1) { 728 729 nch = nc >> 1; 729 delta = atan(1.0) / nch;730 c[0] = cos(delta * nch);731 c[nch] = 0.5 * c[0];730 delta = ATAN(1.0) / nch; 731 c[0] = COS(delta * nch); 732 c[nch] = (smpl_t)0.5 * c[0]; 732 733 for (j = 1; j < nch; j++) { 733 c[j] = 0.5 * cos(delta * j);734 c[nc - j] = 0.5 * sin(delta * j);734 c[j] = (smpl_t)0.5 * COS(delta * j); 735 c[nc - j] = (smpl_t)0.5 * SIN(delta * j); 735 736 } 736 737 } … … 1588 1589 k = n - j; 1589 1590 kk += ks; 1590 wkr = 0.5 - c[nc - kk];1591 wkr = (smpl_t)0.5 - c[nc - kk]; 1591 1592 wki = c[kk]; 1592 1593 xr = a[j] - a[k]; … … 1614 1615 k = n - j; 1615 1616 kk += ks; 1616 wkr = 0.5 - c[nc - kk];1617 wkr = (smpl_t)0.5 - c[nc - kk]; 1617 1618 wki = c[kk]; 1618 1619 xr = a[j] - a[k]; -
src/spectral/phasevoc.c
r5b46bc3 r633400d 89 89 goto beach; 90 90 } else if (win_s < hop_s) { 91 AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", win_s, hop_s);91 AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", hop_s, win_s); 92 92 goto beach; 93 93 } … … 142 142 AUBIO_FREE (pv); 143 143 return NULL; 144 } 145 146 uint_t aubio_pvoc_set_window(aubio_pvoc_t *pv, const char_t *window) { 147 return fvec_set_window(pv->w, (char_t*)window); 144 148 } 145 149 … … 209 213 synthold[i] += synth[i + pv->hop_s] * pv->scale; 210 214 } 215 216 uint_t aubio_pvoc_get_win(aubio_pvoc_t* pv) 217 { 218 return pv->win_s; 219 } 220 221 uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv) 222 { 223 return pv->hop_s; 224 } -
src/spectral/phasevoc.h
r5b46bc3 r633400d 89 89 */ 90 90 uint_t aubio_pvoc_get_win(aubio_pvoc_t* pv); 91 91 92 /** get hop size 92 93 … … 96 97 uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv); 97 98 99 /** set window type 100 101 \param pv phase vocoder to set the window type 102 \param window_type a string representing a window 103 104 \return 0 if successful, non-zero otherwise 105 106 */ 107 uint_t aubio_pvoc_set_window(aubio_pvoc_t *pv, const char_t *window_type); 108 98 109 #ifdef __cplusplus 99 110 } -
src/spectral/specdesc.c
r5b46bc3 r633400d 31 31 void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 32 32 void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 33 void aubio_specdesc_wphase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 33 34 void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 34 35 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); … … 58 59 aubio_onset_complex, /**< complex domain */ 59 60 aubio_onset_phase, /**< phase fast */ 61 aubio_onset_wphase, /**< weighted phase */ 60 62 aubio_onset_kl, /**< Kullback Liebler */ 61 63 aubio_onset_mkl, /**< modified Kullback Liebler */ … … 158 160 onset->data[0] = aubio_hist_mean(o->histog); 159 161 //onset->data[0] = fvec_mean(o->dev1); 162 } 163 164 /* weighted phase */ 165 void 166 aubio_specdesc_wphase(aubio_specdesc_t *o, 167 const cvec_t *fftgrain, fvec_t *onset) { 168 uint_t i; 169 aubio_specdesc_phase(o, fftgrain, onset); 170 for (i = 0; i < fftgrain->length; i++) { 171 o->dev1->data[i] *= fftgrain->norm[i]; 172 } 173 /* apply o->histogram */ 174 aubio_hist_dyn_notnull(o->histog,o->dev1); 175 /* weight it */ 176 aubio_hist_weight(o->histog); 177 /* its mean is the result */ 178 onset->data[0] = aubio_hist_mean(o->histog); 160 179 } 161 180 … … 251 270 else if (strcmp (onset_mode, "phase") == 0) 252 271 onset_type = aubio_onset_phase; 272 else if (strcmp (onset_mode, "wphase") == 0) 273 onset_type = aubio_onset_wphase; 253 274 else if (strcmp (onset_mode, "mkl") == 0) 254 275 onset_type = aubio_onset_mkl; … … 271 292 else if (strcmp (onset_mode, "rolloff") == 0) 272 293 onset_type = aubio_specmethod_rolloff; 294 else if (strcmp (onset_mode, "old_default") == 0) 295 onset_type = aubio_onset_default; 273 296 else if (strcmp (onset_mode, "default") == 0) 274 297 onset_type = aubio_onset_default; 275 298 else { 276 AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode); 299 AUBIO_ERR("specdesc: unknown spectral descriptor type '%s'\n", 300 onset_mode); 277 301 AUBIO_FREE(o); 278 302 return NULL; … … 292 316 break; 293 317 case aubio_onset_phase: 318 case aubio_onset_wphase: 294 319 o->dev1 = new_fvec(rsize); 295 320 o->theta1 = new_fvec(rsize); … … 326 351 o->funcpointer = aubio_specdesc_phase; 327 352 break; 353 case aubio_onset_wphase: 354 o->funcpointer = aubio_specdesc_wphase; 355 break; 328 356 case aubio_onset_specdiff: 329 357 o->funcpointer = aubio_specdesc_specdiff; … … 379 407 break; 380 408 case aubio_onset_phase: 409 case aubio_onset_wphase: 381 410 del_fvec(o->dev1); 382 411 del_fvec(o->theta1); -
src/spectral/specdesc.h
r5b46bc3 r633400d 60 60 Hong-Kong, 2003. 61 61 62 \b \p wphase : Weighted Phase Deviation onset detection function 63 64 S. Dixon. Onset detection revisited. In Proceedings of the 9th International 65 Conference on Digital Audio Ef- fects (DAFx) , pages 133–137, 2006. 66 67 http://www.eecs.qmul.ac.uk/~simond/pub/2006/dafx.pdf 68 62 69 \b \p specdiff : Spectral difference method onset detection function 63 70 … … 175 182 The parameter \p method is a string that can be any of: 176 183 177 - `energy`, `hfc`, `complex`, `phase`, `specdiff`, `kl`, `mkl`, `specflux` 178 - `centroid`, `spread`, `skewness`, `kurtosis`, `slope`, `decrease`, `rolloff` 184 - onset novelty functions: `complex`, `energy`, `hfc`, `kl`, `mkl`, 185 `phase`, `specdiff`, `specflux`, `wphase`, 186 187 - spectral descriptors: `centroid`, `decrease`, `kurtosis`, `rolloff`, 188 `skewness`, `slope`, `spread`. 179 189 180 190 */ -
src/synth/sampler.c
r5b46bc3 r633400d 20 20 21 21 22 #include "config.h"23 22 #include "aubio_priv.h" 24 23 #include "fvec.h" -
src/synth/wavetable.c
r5b46bc3 r633400d 20 20 21 21 22 #include "config.h"23 22 #include "aubio_priv.h" 24 23 #include "fvec.h" … … 105 104 output->data[i] += input->data[i]; 106 105 } 106 fvec_clamp(output, 1.); 107 107 } 108 108 } … … 165 165 aubio_wavetable_set_amp (s, 0.); 166 166 //s->last_pos = 0; 167 return aubio_wavetable_set_playing (s, 1); 167 return aubio_wavetable_set_playing (s, 0); 168 } 169 170 uint_t 171 aubio_wavetable_load ( aubio_wavetable_t *s UNUSED, const char_t *uri UNUSED) 172 { 173 AUBIO_ERR("wavetable: load method not implemented yet, see sampler\n"); 174 return AUBIO_FAIL; 168 175 } 169 176 -
src/synth/wavetable.h
r5b46bc3 r633400d 53 53 54 54 /** load source in wavetable 55 56 TODO: This function is not implemented yet. See new_aubio_sampler() instead. 55 57 56 58 \param o wavetable, created by new_aubio_wavetable() -
src/tempo/beattracking.h
r5b46bc3 r633400d 32 32 Matthew E. P. Davies, Paul Brossier, and Mark D. Plumbley. Beat tracking 33 33 towards automatic musical accompaniment. In Proceedings of the Audio 34 Eng eeniring Society 118th Convention, Barcelona, Spain, May 2005.34 Engineering Society 118th Convention, Barcelona, Spain, May 2005. 35 35 36 36 \example tempo/test-beattracking.c -
src/tempo/tempo.c
r5b46bc3 r633400d 129 129 130 130 uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) { 131 o->delay = 1000. * delay * o->samplerate; 132 return AUBIO_OK; 131 return aubio_tempo_set_delay_s(o, delay / 1000.); 133 132 } 134 133 … … 142 141 143 142 smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) { 144 return o->delay / (smpl_t)(o->samplerate) /1000.;143 return aubio_tempo_get_delay_s(o) * 1000.; 145 144 } 146 145 … … 169 168 { 170 169 aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t); 171 char_t specdesc_func[ 20];170 char_t specdesc_func[PATH_MAX]; 172 171 o->samplerate = samplerate; 173 172 // check parameters are valid … … 204 203 aubio_peakpicker_set_threshold (o->pp, o->threshold); 205 204 if ( strcmp(tempo_mode, "default") == 0 ) { 206 str cpy(specdesc_func, "specflux");205 strncpy(specdesc_func, "specflux", PATH_MAX - 1); 207 206 } else { 208 strcpy(specdesc_func, tempo_mode); 207 strncpy(specdesc_func, tempo_mode, PATH_MAX - 1); 208 specdesc_func[PATH_MAX - 1] = '\0'; 209 209 } 210 210 o->od = new_aubio_specdesc(specdesc_func,buf_size); … … 216 216 onset2 = new_fvec(1); 217 217 }*/ 218 if (!o->dfframe || !o->fftgrain || !o->out || !o->pv || 219 !o->pp || !o->od || !o->of || !o->bt || !o->onset) { 220 AUBIO_ERR("tempo: failed creating tempo object\n"); 221 goto beach; 222 } 218 223 o->last_tatum = 0; 219 224 o->tatum_signature = 4; … … 221 226 222 227 beach: 223 AUBIO_FREE(o);228 del_aubio_tempo(o); 224 229 return NULL; 225 230 } … … 278 283 void del_aubio_tempo (aubio_tempo_t *o) 279 284 { 280 del_aubio_specdesc(o->od); 281 del_aubio_beattracking(o->bt); 282 del_aubio_peakpicker(o->pp); 283 del_aubio_pvoc(o->pv); 284 del_fvec(o->out); 285 del_fvec(o->of); 286 del_cvec(o->fftgrain); 287 del_fvec(o->dfframe); 288 del_fvec(o->onset); 285 if (o->od) 286 del_aubio_specdesc(o->od); 287 if (o->bt) 288 del_aubio_beattracking(o->bt); 289 if (o->pp) 290 del_aubio_peakpicker(o->pp); 291 if (o->pv) 292 del_aubio_pvoc(o->pv); 293 if (o->out) 294 del_fvec(o->out); 295 if (o->of) 296 del_fvec(o->of); 297 if (o->fftgrain) 298 del_cvec(o->fftgrain); 299 if (o->dfframe) 300 del_fvec(o->dfframe); 301 if (o->onset) 302 del_fvec(o->onset); 289 303 AUBIO_FREE(o); 290 return; 291 } 304 } -
src/tempo/tempo.h
r5b46bc3 r633400d 155 155 \param o beat tracking object 156 156 157 \return confidence with which the tempo has been observed, `0` if no158 consistent value is found.157 \return confidence with which the tempo has been observed, the higher the 158 more confidence, `0` if no consistent value is found. 159 159 160 160 */ -
src/temporal/biquad.c
r5b46bc3 r633400d 42 42 as->data[0] = 1.; 43 43 as->data[1] = a1; 44 as->data[ 1] = a2;44 as->data[2] = a2; 45 45 return AUBIO_OK; 46 46 } -
src/temporal/resampler.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include "config.h"22 23 21 #include "aubio_priv.h" 24 22 #include "fvec.h" … … 26 24 27 25 #ifdef HAVE_SAMPLERATE 26 27 #if HAVE_AUBIO_DOUBLE 28 #error "Should not use libsamplerate with aubio in double precision" 29 #endif 28 30 29 31 #include <samplerate.h> /* from libsamplerate */ -
src/utils/hist.c
r5b46bc3 r633400d 44 44 smpl_t accum = step; 45 45 uint_t i; 46 if ((sint_t)nelems <= 0) { 47 return NULL; 48 } 46 49 s->nelems = nelems; 47 50 s->hist = new_fvec(nelems); -
src/utils/log.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "log.h" … … 36 35 FILE *out; 37 36 out = stdout; 38 if (level == AUBIO_LOG_ DBG || level == AUBIO_LOG_ERR) {37 if (level == AUBIO_LOG_ERR || level == AUBIO_LOG_DBG || level == AUBIO_LOG_WRN) { 39 38 out = stderr; 40 39 } -
src/utils/log.h
r5b46bc3 r633400d 46 46 enum aubio_log_level { 47 47 AUBIO_LOG_ERR, /**< critical errors */ 48 AUBIO_LOG_ WRN, /**< warnings */48 AUBIO_LOG_INF, /**< infos */ 49 49 AUBIO_LOG_MSG, /**< general messages */ 50 50 AUBIO_LOG_DBG, /**< debug messages */ 51 AUBIO_LOG_WRN, /**< warnings */ 51 52 AUBIO_LOG_LAST_LEVEL, /**< number of valid levels */ 52 53 }; -
src/utils/parameter.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "parameter.h" -
src/utils/windll.c
r5b46bc3 r633400d 25 25 */ 26 26 27 #include " config.h"27 #include "aubio_priv.h" 28 28 29 29 #ifdef HAVE_WIN_HACKS … … 42 42 #include "aubio.h" 43 43 44 BOOL APIENTRY DllMain( HMODULE hModule ,44 BOOL APIENTRY DllMain( HMODULE hModule UNUSED, 45 45 DWORD ul_reason_for_call, 46 LPVOID lpReserved )46 LPVOID lpReserved UNUSED) 47 47 { 48 48 switch (ul_reason_for_call) -
src/vecutils.c
r5b46bc3 r633400d 1 #include "config.h"2 1 #include "aubio_priv.h" 3 2 #include "types.h" -
src/wscript_build
r5b46bc3 r633400d 4 4 uselib += ['M'] 5 5 uselib += ['FFTW3', 'FFTW3F'] 6 uselib += ['INTEL_IPP'] 6 7 uselib += ['SAMPLERATE'] 7 8 uselib += ['SNDFILE'] … … 9 10 uselib += ['AVCODEC'] 10 11 uselib += ['AVFORMAT'] 12 uselib += ['SWRESAMPLE'] 11 13 uselib += ['AVRESAMPLE'] 12 14 uselib += ['AVUTIL'] … … 25 27 build_features = ['cstlib', 'cshlib'] 26 28 elif ctx.env['DEST_OS'] in ['win32', 'win64']: 29 build_features = ['cstlib', 'cshlib gensyms'] 30 elif ctx.env['DEST_OS'] in ['emscripten']: 31 build_features = ['cstlib','cshlib'] 32 elif '--static' in ctx.env['LDFLAGS'] or '--static' in ctx.env['LINKFLAGS']: 33 # static in cflags, ... 34 build_features = ['cstlib'] 35 else: 36 # linux, darwin, android, mingw, ... 27 37 build_features = ['cstlib', 'cshlib'] 28 elif ctx.env['DEST_OS'] in ['emscripten']: 29 build_features = ['cstlib'] 30 else: #linux, darwin, android, mingw, ... 31 build_features = ['cstlib', 'cshlib'] 38 39 # also install static lib 40 from waflib.Tools.c import cstlib 41 cstlib.inst_to = '${LIBDIR}' 32 42 33 43 for target in build_features: … … 35 45 use = uselib + ['lib_objects'], 36 46 target = 'aubio', 47 export_symbols_regex=r'(?:.*aubio|fvec|lvec|cvec|fmat|new|del)_.*', 37 48 vnum = ctx.env['LIB_VERSION']) 38 49 39 50 # install headers, except _priv.h ones 40 ctx.install_files('${ PREFIX}/include/aubio/',51 ctx.install_files('${INCLUDEDIR}/aubio/', 41 52 ctx.path.ant_glob('**/*.h', excl = ['**_priv.h', 'config.h']), 42 53 relative_trick=True)
Note: See TracChangeset
for help on using the changeset viewer.