- Timestamp:
- Mar 10, 2017, 2:26:32 PM (8 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/applefworks, fix/ffmpeg5, master, sampler
- Children:
- ee8a57c
- Parents:
- 00d0275 (diff), 67b6618 (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:
-
- 7 added
- 96 edited
Legend:
- Unmodified
- Added
- Removed
-
src/aubio.h
r00d0275 r155cc10 112 112 directories of the source tree. 113 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 122 114 123 \subsection unstable_api Unstable API 115 124 … … 131 140 132 141 Latest versions, further documentation, examples, wiki, and mailing lists can 133 be found at http ://aubio.org .142 be found at https://aubio.org . 134 143 135 144 */ … … 184 193 #include "onset/onset.h" 185 194 #include "tempo/tempo.h" 195 #include "notes/notes.h" 186 196 #include "io/source.h" 187 197 #include "io/sink.h" … … 189 199 #include "synth/wavetable.h" 190 200 #include "utils/parameter.h" 201 #include "utils/log.h" 191 202 192 203 #if AUBIO_UNSTABLE -
src/aubio_priv.h
r00d0275 r155cc10 25 25 */ 26 26 27 #ifndef _AUBIO__PRIV_H28 #define _AUBIO__PRIV_H27 #ifndef AUBIO_PRIV_H 28 #define AUBIO_PRIV_H 29 29 30 30 /********************* … … 34 34 */ 35 35 36 #ifdef HAVE_CONFIG_H 36 37 #include "config.h" 37 38 #if HAVE_STDLIB_H 38 #endif 39 40 #ifdef HAVE_STDLIB_H 39 41 #include <stdlib.h> 40 42 #endif 41 43 42 #if HAVE_STDIO_H44 #ifdef HAVE_STDIO_H 43 45 #include <stdio.h> 44 46 #endif … … 65 67 #endif 66 68 69 #ifdef HAVE_STDARG_H 70 #include <stdarg.h> 71 #endif 72 67 73 #ifdef HAVE_ACCELERATE 68 74 #define HAVE_ATLAS 1 69 75 #include <Accelerate/Accelerate.h> 70 #elif HAVE_ATLAS_CBLAS_H76 #elif defined(HAVE_ATLAS_CBLAS_H) 71 77 #define HAVE_ATLAS 1 72 78 #include <atlas/cblas.h> … … 77 83 #ifdef HAVE_ACCELERATE 78 84 #include <Accelerate/Accelerate.h> 79 #if !HAVE_AUBIO_DOUBLE85 #ifndef HAVE_AUBIO_DOUBLE 80 86 #define aubio_vDSP_mmov vDSP_mmov 81 87 #define aubio_vDSP_vmul vDSP_vmul … … 87 93 #define aubio_vDSP_minv vDSP_minv 88 94 #define aubio_vDSP_minvi vDSP_minvi 95 #define aubio_vDSP_dotpr vDSP_dotpr 89 96 #else /* HAVE_AUBIO_DOUBLE */ 90 97 #define aubio_vDSP_mmov vDSP_mmovD … … 97 104 #define aubio_vDSP_minv vDSP_minvD 98 105 #define aubio_vDSP_minvi vDSP_minviD 106 #define aubio_vDSP_dotpr vDSP_dotprD 99 107 #endif /* HAVE_AUBIO_DOUBLE */ 100 108 #endif /* HAVE_ACCELERATE */ 101 109 102 110 #ifdef HAVE_ATLAS 103 #if !HAVE_AUBIO_DOUBLE111 #ifndef HAVE_AUBIO_DOUBLE 104 112 #define aubio_catlas_set catlas_sset 105 113 #define aubio_cblas_copy cblas_scopy … … 167 175 } aubio_status; 168 176 177 /* Logging */ 178 179 #include "utils/log.h" 180 181 /** internal logging function, defined in utils/log.c */ 182 uint_t aubio_log(sint_t level, const char_t *fmt, ...); 183 169 184 #ifdef HAVE_C99_VARARGS_MACROS 170 #define AUBIO_ERR(...) fprintf(stderr, "AUBIO ERROR: " __VA_ARGS__) 171 #define AUBIO_MSG(...) fprintf(stdout, __VA_ARGS__) 172 #define AUBIO_DBG(...) fprintf(stderr, __VA_ARGS__) 173 #define AUBIO_WRN(...) fprintf(stderr, "AUBIO WARNING: " __VA_ARGS__) 174 #else 175 #define AUBIO_ERR(format, args...) fprintf(stderr, "AUBIO ERROR: " format , ##args) 176 #define AUBIO_MSG(format, args...) fprintf(stdout, format , ##args) 177 #define AUBIO_DBG(format, args...) fprintf(stderr, format , ##args) 178 #define AUBIO_WRN(format, args...) fprintf(stderr, "AUBIO WARNING: " format, ##args) 185 #define AUBIO_ERR(...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__) 186 #define AUBIO_INF(...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " __VA_ARGS__) 187 #define AUBIO_MSG(...) aubio_log(AUBIO_LOG_MSG, __VA_ARGS__) 188 #define AUBIO_DBG(...) aubio_log(AUBIO_LOG_DBG, __VA_ARGS__) 189 #define AUBIO_WRN(...) aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__) 190 #else 191 #define AUBIO_ERR(format, args...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " format , ##args) 192 #define AUBIO_INF(format, args...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " format , ##args) 193 #define AUBIO_MSG(format, args...) aubio_log(AUBIO_LOG_MSG, format , ##args) 194 #define AUBIO_DBG(format, args...) aubio_log(AUBIO_LOG_DBG, format , ##args) 195 #define AUBIO_WRN(format, args...) aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " format, ##args) 179 196 #endif 180 197 … … 183 200 #define AUBIO_QUIT(_s) exit(_s) 184 201 #define AUBIO_SPRINTF sprintf 202 203 #define AUBIO_MAX_SAMPLERATE (192000*8) 204 #define AUBIO_MAX_CHANNELS 1024 185 205 186 206 /* pi and 2*pi */ … … 191 211 #endif 192 212 #define TWO_PI (PI*2.) 213 214 #ifndef PATH_MAX 215 #define PATH_MAX 1024 216 #endif 193 217 194 218 /* aliases to math.h functions */ … … 204 228 #define FLOOR floorf 205 229 #define CEIL ceilf 230 #define ATAN atanf 206 231 #define ATAN2 atan2f 207 232 #else … … 216 241 #define FLOOR floor 217 242 #define CEIL ceil 243 #define ATAN atan 218 244 #define ATAN2 atan2 219 245 #endif … … 249 275 #endif 250 276 277 /* avoid unresolved symbol with msvc 9 */ 278 #if defined(_MSC_VER) && (_MSC_VER < 1900) 279 #define isnan _isnan 280 #endif 281 251 282 /* handy shortcuts */ 252 283 #define DB2LIN(g) (POW(10.0,(g)*0.05f)) … … 284 315 #endif 285 316 286 #endif /* _AUBIO__PRIV_H */ 317 /* are we using gcc -std=c99 ? */ 318 #if defined(__STRICT_ANSI__) 319 #define strnlen(a,b) MIN(strlen(a),b) 320 #if !HAVE_AUBIO_DOUBLE 321 #define floorf floor 322 #endif 323 #endif /* __STRICT_ANSI__ */ 324 325 #endif /* AUBIO_PRIV_H */ -
src/cvec.c
r00d0275 r155cc10 22 22 #include "cvec.h" 23 23 24 cvec_t * new_cvec( 24 cvec_t * new_cvec(uint_t length) { 25 25 cvec_t * s; 26 26 if ((sint_t)length <= 0) { … … 56 56 } 57 57 58 smpl_t * cvec_norm_get_data (c vec_t *s) {58 smpl_t * cvec_norm_get_data (const cvec_t *s) { 59 59 return s->norm; 60 60 } 61 61 62 smpl_t * cvec_phas_get_data (c vec_t *s) {62 smpl_t * cvec_phas_get_data (const cvec_t *s) { 63 63 return s->phas; 64 64 } … … 66 66 /* helper functions */ 67 67 68 void cvec_print(c vec_t *s) {68 void cvec_print(const cvec_t *s) { 69 69 uint_t j; 70 70 AUBIO_MSG("norm: "); … … 80 80 } 81 81 82 void cvec_copy(c vec_t *s, cvec_t *t) {82 void cvec_copy(const cvec_t *s, cvec_t *t) { 83 83 if (s->length != t->length) { 84 84 AUBIO_ERR("trying to copy %d elements to %d elements \n", … … 86 86 return; 87 87 } 88 #if HAVE_MEMCPY_HACKS88 #ifdef HAVE_MEMCPY_HACKS 89 89 memcpy(t->norm, s->norm, t->length * sizeof(smpl_t)); 90 90 memcpy(t->phas, s->phas, t->length * sizeof(smpl_t)); 91 #else 91 #else /* HAVE_MEMCPY_HACKS */ 92 92 uint_t j; 93 93 for (j=0; j< t->length; j++) { … … 95 95 t->phas[j] = s->phas[j]; 96 96 } 97 #endif 97 #endif /* HAVE_MEMCPY_HACKS */ 98 98 } 99 99 … … 106 106 107 107 void cvec_norm_zeros(cvec_t *s) { 108 #if HAVE_MEMCPY_HACKS108 #ifdef HAVE_MEMCPY_HACKS 109 109 memset(s->norm, 0, s->length * sizeof(smpl_t)); 110 #else 110 #else /* HAVE_MEMCPY_HACKS */ 111 111 cvec_norm_set_all (s, 0.); 112 #endif 112 #endif /* HAVE_MEMCPY_HACKS */ 113 113 } 114 114 … … 125 125 126 126 void cvec_phas_zeros(cvec_t *s) { 127 #if HAVE_MEMCPY_HACKS127 #ifdef HAVE_MEMCPY_HACKS 128 128 memset(s->phas, 0, s->length * sizeof(smpl_t)); 129 129 #else -
src/cvec.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO__CVEC_H22 #define _AUBIO__CVEC_H21 #ifndef AUBIO_CVEC_H 22 #define AUBIO_CVEC_H 23 23 24 24 #ifdef __cplusplus … … 151 151 152 152 */ 153 smpl_t * cvec_norm_get_data (c vec_t *s);153 smpl_t * cvec_norm_get_data (const cvec_t *s); 154 154 155 155 /** read phase data from a complex buffer … … 163 163 164 164 */ 165 smpl_t * cvec_phas_get_data (c vec_t *s);165 smpl_t * cvec_phas_get_data (const cvec_t *s); 166 166 167 167 /** print out cvec data … … 170 170 171 171 */ 172 void cvec_print(c vec_t *s);172 void cvec_print(const cvec_t *s); 173 173 174 174 /** make a copy of a vector … … 178 178 179 179 */ 180 void cvec_copy(c vec_t *s, cvec_t *t);180 void cvec_copy(const cvec_t *s, cvec_t *t); 181 181 182 182 /** set all norm elements to a given value … … 235 235 #endif 236 236 237 #endif /* _AUBIO__CVEC_H */237 #endif /* AUBIO_CVEC_H */ -
src/fmat.c
r00d0275 r155cc10 54 54 } 55 55 56 smpl_t fmat_get_sample( fmat_t *s, uint_t channel, uint_t position) {56 smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position) { 57 57 return s->data[channel][position]; 58 58 } 59 59 60 void fmat_get_channel( fmat_t *s, uint_t channel, fvec_t *output) {60 void fmat_get_channel(const fmat_t *s, uint_t channel, fvec_t *output) { 61 61 output->data = s->data[channel]; 62 62 output->length = s->length; … … 64 64 } 65 65 66 smpl_t * fmat_get_channel_data( fmat_t *s, uint_t channel) {66 smpl_t * fmat_get_channel_data(const fmat_t *s, uint_t channel) { 67 67 return s->data[channel]; 68 68 } 69 69 70 smpl_t ** fmat_get_data( fmat_t *s) {70 smpl_t ** fmat_get_data(const fmat_t *s) { 71 71 return s->data; 72 72 } … … 74 74 /* helper functions */ 75 75 76 void fmat_print( fmat_t *s) {76 void fmat_print(const fmat_t *s) { 77 77 uint_t i,j; 78 78 for (i=0; i< s->height; i++) { … … 94 94 95 95 void fmat_zeros(fmat_t *s) { 96 #if HAVE_MEMCPY_HACKS96 #ifdef HAVE_MEMCPY_HACKS 97 97 uint_t i; 98 98 for (i=0; i< s->height; i++) { 99 99 memset(s->data[i], 0, s->length * sizeof(smpl_t)); 100 100 } 101 #else 101 #else /* HAVE_MEMCPY_HACKS */ 102 102 fmat_set(s, 0.); 103 #endif 103 #endif /* HAVE_MEMCPY_HACKS */ 104 104 } 105 105 … … 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 } … … 117 117 } 118 118 119 void fmat_weight(fmat_t *s, fmat_t *weight) {119 void fmat_weight(fmat_t *s, const fmat_t *weight) { 120 120 uint_t i,j; 121 121 uint_t length = MIN(s->length, weight->length); … … 127 127 } 128 128 129 void fmat_copy( fmat_t *s, fmat_t *t) {129 void fmat_copy(const fmat_t *s, fmat_t *t) { 130 130 uint_t i; 131 #if !HAVE_MEMCPY_HACKS131 #ifndef HAVE_MEMCPY_HACKS 132 132 uint_t j; 133 #endif 133 #endif /* HAVE_MEMCPY_HACKS */ 134 134 if (s->height != t->height) { 135 135 AUBIO_ERR("trying to copy %d rows to %d rows \n", … … 142 142 return; 143 143 } 144 #if HAVE_MEMCPY_HACKS144 #ifdef HAVE_MEMCPY_HACKS 145 145 for (i=0; i< s->height; i++) { 146 146 memcpy(t->data[i], s->data[i], t->length * sizeof(smpl_t)); 147 147 } 148 #else 148 #else /* HAVE_MEMCPY_HACKS */ 149 149 for (i=0; i< t->height; i++) { 150 150 for (j=0; j< t->length; j++) { … … 152 152 } 153 153 } 154 #endif /* HAVE_MEMCPY_HACKS */ 155 } 156 157 void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output) { 158 uint_t k; 159 #if 0 160 assert(s->height == output->length); 161 assert(s->length == scale->length); 162 #endif 163 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS) 164 uint_t j; 165 fvec_zeros(output); 166 for (j = 0; j < s->length; j++) { 167 for (k = 0; k < s->height; k++) { 168 output->data[k] += scale->data[j] 169 * s->data[k][j]; 170 } 171 } 172 #elif defined(HAVE_ATLAS) 173 for (k = 0; k < s->height; k++) { 174 output->data[k] = aubio_cblas_dot( s->length, scale->data, 1, s->data[k], 1); 175 } 176 #elif defined(HAVE_ACCELERATE) 177 #if 0 178 // seems slower and less precise (and dangerous?) 179 vDSP_mmul (s->data[0], 1, scale->data, 1, output->data, 1, s->height, 1, s->length); 180 #else 181 for (k = 0; k < s->height; k++) { 182 aubio_vDSP_dotpr( scale->data, 1, s->data[k], 1, &(output->data[k]), s->length); 183 } 184 #endif 154 185 #endif 155 186 } 156 -
src/fmat.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO__FMAT_H22 #define _AUBIO__FMAT_H21 #ifndef AUBIO_FMAT_H 22 #define AUBIO_FMAT_H 23 23 24 24 #ifdef __cplusplus … … 66 66 67 67 */ 68 smpl_t fmat_get_sample( fmat_t *s, uint_t channel, uint_t position);68 smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position); 69 69 70 70 /** write sample value in a buffer … … 85 85 86 86 */ 87 void fmat_get_channel ( fmat_t *s, uint_t channel, fvec_t *output);87 void fmat_get_channel (const fmat_t *s, uint_t channel, fvec_t *output); 88 88 89 89 /** get vector buffer from an fmat data … … 93 93 94 94 */ 95 smpl_t * fmat_get_channel_data ( fmat_t *s, uint_t channel);95 smpl_t * fmat_get_channel_data (const fmat_t *s, uint_t channel); 96 96 97 97 /** read data from a buffer … … 100 100 101 101 */ 102 smpl_t ** fmat_get_data( fmat_t *s);102 smpl_t ** fmat_get_data(const fmat_t *s); 103 103 104 104 /** print out fmat data … … 107 107 108 108 */ 109 void fmat_print( fmat_t *s);109 void fmat_print(const fmat_t *s); 110 110 111 111 /** set all elements to a given value … … 147 147 148 148 */ 149 void fmat_weight(fmat_t *s, fmat_t *weight);149 void fmat_weight(fmat_t *s, const fmat_t *weight); 150 150 151 151 /** make a copy of a matrix … … 155 155 156 156 */ 157 void fmat_copy(fmat_t *s, fmat_t *t); 157 void fmat_copy(const fmat_t *s, fmat_t *t); 158 159 /** compute the product of a matrix by a vector 160 161 \param s matrix to compute product with 162 \param scale vector to compute product with 163 \param output vector to store restults in 164 165 */ 166 void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output); 158 167 159 168 #ifdef __cplusplus … … 161 170 #endif 162 171 163 #endif /* _AUBIO__FMAT_H */172 #endif /* AUBIO_FMAT_H */ -
src/fvec.c
r00d0275 r155cc10 22 22 #include "fvec.h" 23 23 24 fvec_t * new_fvec( 24 fvec_t * new_fvec(uint_t length) { 25 25 fvec_t * s; 26 26 if ((sint_t)length <= 0) { … … 42 42 } 43 43 44 smpl_t fvec_get_sample( fvec_t *s, uint_t position) {44 smpl_t fvec_get_sample(const fvec_t *s, uint_t position) { 45 45 return s->data[position]; 46 46 } 47 47 48 smpl_t * fvec_get_data( fvec_t *s) {48 smpl_t * fvec_get_data(const fvec_t *s) { 49 49 return s->data; 50 50 } … … 52 52 /* helper functions */ 53 53 54 void fvec_print( fvec_t *s) {54 void fvec_print(const fvec_t *s) { 55 55 uint_t j; 56 56 for (j=0; j< s->length; j++) { … … 91 91 void fvec_rev(fvec_t *s) { 92 92 uint_t j; 93 for (j=0; j< FLOOR( s->length/2); j++) {93 for (j=0; j< FLOOR((smpl_t)s->length/2); j++) { 94 94 ELEM_SWAP(s->data[j], s->data[s->length-1-j]); 95 95 } 96 96 } 97 97 98 void fvec_weight(fvec_t *s, fvec_t *weight) {98 void fvec_weight(fvec_t *s, const fvec_t *weight) { 99 99 #ifndef HAVE_ACCELERATE 100 100 uint_t j; … … 108 108 } 109 109 110 void fvec_weighted_copy( fvec_t *in,fvec_t *weight, fvec_t *out) {110 void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) { 111 111 #ifndef HAVE_ACCELERATE 112 112 uint_t j; … … 120 120 } 121 121 122 void fvec_copy( fvec_t *s, fvec_t *t) {122 void fvec_copy(const fvec_t *s, fvec_t *t) { 123 123 if (s->length != t->length) { 124 124 AUBIO_ERR("trying to copy %d elements to %d elements \n", … … 126 126 return; 127 127 } 128 #if HAVE_NOOPT128 #ifdef HAVE_NOOPT 129 129 uint_t j; 130 130 for (j=0; j< t->length; j++) { -
src/fvec.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO__FVEC_H22 #define _AUBIO__FVEC_H21 #ifndef AUBIO_FVEC_H 22 #define AUBIO_FVEC_H 23 23 24 24 #ifdef __cplusplus … … 90 90 91 91 */ 92 smpl_t fvec_get_sample( fvec_t *s, uint_t position);92 smpl_t fvec_get_sample(const fvec_t *s, uint_t position); 93 93 94 94 /** write sample value in a buffer … … 106 106 107 107 */ 108 smpl_t * fvec_get_data( fvec_t *s);108 smpl_t * fvec_get_data(const fvec_t *s); 109 109 110 110 /** print out fvec data … … 113 113 114 114 */ 115 void fvec_print( fvec_t *s);115 void fvec_print(const fvec_t *s); 116 116 117 117 /** set all elements to a given value … … 153 153 154 154 */ 155 void fvec_weight(fvec_t *s, fvec_t *weight);155 void fvec_weight(fvec_t *s, const fvec_t *weight); 156 156 157 157 /** make a copy of a vector … … 161 161 162 162 */ 163 void fvec_copy( fvec_t *s, fvec_t *t);163 void fvec_copy(const fvec_t *s, fvec_t *t); 164 164 165 165 /** make a copy of a vector, applying weights to each element … … 170 170 171 171 */ 172 void fvec_weighted_copy( fvec_t *in,fvec_t *weight, fvec_t *out);172 void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out); 173 173 174 174 #ifdef __cplusplus … … 176 176 #endif 177 177 178 #endif /* _AUBIO__FVEC_H */178 #endif /* AUBIO_FVEC_H */ -
src/io/audio_unit.c
r00d0275 r155cc10 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/audio_unit.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_AUDIO_UNIT_H22 #define _AUBIO_AUDIO_UNIT_H21 #ifndef AUBIO_AUDIO_UNIT_H 22 #define AUBIO_AUDIO_UNIT_H 23 23 24 24 /** \file … … 59 59 #endif 60 60 61 #endif /* _AUBIO_AUDIO_UNIT_H */61 #endif /* AUBIO_AUDIO_UNIT_H */ -
src/io/sink.c
r00d0275 r155cc10 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "fvec.h" … … 55 54 }; 56 55 57 aubio_sink_t * new_aubio_sink(c har_t * uri, uint_t samplerate) {56 aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) { 58 57 aubio_sink_t * s = AUBIO_NEW(aubio_sink_t); 59 58 #ifdef HAVE_SINK_APPLE_AUDIO … … 71 70 } 72 71 #endif /* HAVE_SINK_APPLE_AUDIO */ 73 #if HAVE_SNDFILE72 #ifdef HAVE_SNDFILE 74 73 s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate); 75 74 if (s->sink) { … … 85 84 } 86 85 #endif /* HAVE_SNDFILE */ 87 #if HAVE_WAVWRITE86 #ifdef HAVE_WAVWRITE 88 87 s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate); 89 88 if (s->sink) { … … 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; … … 121 123 } 122 124 123 uint_t aubio_sink_get_samplerate( aubio_sink_t * s) {125 uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) { 124 126 return s->s_get_samplerate((void *)s->sink); 125 127 } 126 128 127 uint_t aubio_sink_get_channels( aubio_sink_t * s) {129 uint_t aubio_sink_get_channels(const aubio_sink_t * s) { 128 130 return s->s_get_channels((void *)s->sink); 129 131 } -
src/io/sink.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SINK_H22 #define _AUBIO_SINK_H21 #ifndef AUBIO_SINK_H 22 #define AUBIO_SINK_H 23 23 24 24 /** \file … … 77 77 78 78 */ 79 aubio_sink_t * new_aubio_sink(c har_t * uri, uint_t samplerate);79 aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate); 80 80 81 81 /** … … 121 121 122 122 */ 123 uint_t aubio_sink_get_samplerate( aubio_sink_t *s);123 uint_t aubio_sink_get_samplerate(const aubio_sink_t *s); 124 124 125 125 /** … … 131 131 132 132 */ 133 uint_t aubio_sink_get_channels( aubio_sink_t *s);133 uint_t aubio_sink_get_channels(const aubio_sink_t *s); 134 134 135 135 /** … … 179 179 #endif 180 180 181 #endif /* _AUBIO_SINK_H */181 #endif /* AUBIO_SINK_H */ -
src/io/sink_apple_audio.c
r00d0275 r155cc10 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, ... … … 44 43 #define MAX_SIZE 4096 // the maximum number of frames that can be written at a time 45 44 45 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write); 46 46 47 struct _aubio_sink_apple_audio_t { 47 48 uint_t samplerate; … … 56 57 }; 57 58 58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(c har_t * uri, uint_t samplerate) {59 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) { 59 60 aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t); 60 s->path = uri;61 61 s->max_frames = MAX_SIZE; 62 s->async = true;63 64 if ( uri == NULL) {62 s->async = false; 63 64 if ( (uri == NULL) || (strlen(uri) < 1) ) { 65 65 AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n"); 66 66 goto beach; 67 67 } 68 if (s->path != NULL) AUBIO_FREE(s->path); 69 s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1); 70 strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1); 68 71 69 72 s->samplerate = 0; 70 73 s->channels = 0; 71 74 72 // negative samplerate given, abort73 if ((sint_t)samplerate < 0) goto beach;74 75 // zero samplerate given. do not open yet 75 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 } 76 83 77 84 s->samplerate = samplerate; … … 91 98 uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate) 92 99 { 93 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 } 94 103 s->samplerate = samplerate; 95 104 // automatically open when both samplerate and channels have been set … … 102 111 uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels) 103 112 { 104 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 } 105 116 s->channels = channels; 106 117 // automatically open when both samplerate and channels have been set … … 111 122 } 112 123 113 uint_t aubio_sink_apple_audio_get_samplerate( aubio_sink_apple_audio_t *s)124 uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s) 114 125 { 115 126 return s->samplerate; 116 127 } 117 128 118 uint_t aubio_sink_apple_audio_get_channels( aubio_sink_apple_audio_t *s)129 uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s) 119 130 { 120 131 return s->channels; … … 163 174 164 175 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) { 165 OSStatus err = noErr;166 176 UInt32 c, v; 167 177 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 180 190 } 181 191 } 182 if (s->async) { 183 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); 184 185 if (err) { 186 char_t errorstr[20]; 187 AUBIO_ERROR("sink_apple_audio: error while writing %s " 188 "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path, 189 getPrintableOSStatusError(errorstr, err)); 190 s->async = false; 191 } else { 192 return; 193 } 194 195 } else { 196 err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList); 197 198 if (err) { 199 char_t errorstr[20]; 200 AUBIO_ERROR("sink_apple_audio: error while writing %s " 201 "in ExtAudioFileWrite (%s)\n", s->path, 202 getPrintableOSStatusError(errorstr, err)); 203 } 204 } 205 return; 192 aubio_sink_apple_audio_write(s, write); 206 193 } 207 194 208 195 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) { 209 OSStatus err = noErr;210 196 UInt32 c, v; 211 197 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 224 210 } 225 211 } 212 aubio_sink_apple_audio_write(s, write); 213 } 214 215 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) { 216 OSStatus err = noErr; 226 217 if (s->async) { 227 218 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); 228 229 219 if (err) { 230 220 char_t errorstr[20]; 221 if (err == kExtAudioFileError_AsyncWriteBufferOverflow) { 222 sprintf(errorstr,"buffer overflow"); 223 } else if (err == kExtAudioFileError_AsyncWriteTooLarge) { 224 sprintf(errorstr,"write too large"); 225 } else { 226 // unknown error 227 getPrintableOSStatusError(errorstr, err); 228 } 231 229 AUBIO_ERROR("sink_apple_audio: error while writing %s " 232 "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path, 233 getPrintableOSStatusError(errorstr, err)); 234 s->async = false; 235 } else { 236 return; 230 "in ExtAudioFileWriteAsync (%s)\n", s->path, errorstr); 237 231 } 238 239 232 } else { 240 233 err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList); 241 242 234 if (err) { 243 235 char_t errorstr[20]; … … 247 239 } 248 240 } 249 return;250 241 } 251 242 … … 268 259 void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) { 269 260 if (s->audioFile) aubio_sink_apple_audio_close (s); 261 if (s->path) AUBIO_FREE(s->path); 270 262 freeAudioBufferList(&s->bufferList); 271 263 AUBIO_FREE(s); -
src/io/sink_apple_audio.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SINK_APPLE_AUDIO_H22 #define _AUBIO_SINK_APPLE_AUDIO_H21 #ifndef AUBIO_SINK_APPLE_AUDIO_H 22 #define AUBIO_SINK_APPLE_AUDIO_H 23 23 24 24 /** \file … … 59 59 60 60 */ 61 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(c har_t * uri, uint_t samplerate);61 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate); 62 62 63 63 /** … … 103 103 104 104 */ 105 uint_t aubio_sink_apple_audio_get_samplerate( aubio_sink_apple_audio_t *s);105 uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s); 106 106 107 107 /** … … 113 113 114 114 */ 115 uint_t aubio_sink_apple_audio_get_channels( aubio_sink_apple_audio_t *s);115 uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s); 116 116 117 117 /** … … 161 161 #endif 162 162 163 #endif /* _AUBIO_SINK_APPLE_AUDIO_H */163 #endif /* AUBIO_SINK_APPLE_AUDIO_H */ -
src/io/sink_sndfile.c
r00d0275 r155cc10 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 … … 54 53 uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s); 55 54 56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(c har_t * path, uint_t samplerate) {55 aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) { 57 56 aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t); 58 57 s->max_size = MAX_SIZE; 59 s->path = path;60 58 61 59 if (path == NULL) { … … 64 62 } 65 63 64 if (s->path) AUBIO_FREE(s->path); 65 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 66 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 67 66 68 s->samplerate = 0; 67 69 s->channels = 0; 68 70 69 // negative samplerate given, abort70 if ((sint_t)samplerate < 0) goto beach;71 71 // zero samplerate given. do not open yet 72 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 } 73 79 74 80 s->samplerate = samplerate; … … 87 93 uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate) 88 94 { 89 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 95 if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) { 96 return AUBIO_FAIL; 97 } 90 98 s->samplerate = samplerate; 91 99 // automatically open when both samplerate and channels have been set … … 98 106 uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels) 99 107 { 100 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 108 if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) { 109 return AUBIO_FAIL; 110 } 101 111 s->channels = channels; 102 112 // automatically open when both samplerate and channels have been set … … 107 117 } 108 118 109 uint_t aubio_sink_sndfile_get_samplerate( aubio_sink_sndfile_t *s)119 uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s) 110 120 { 111 121 return s->samplerate; 112 122 } 113 123 114 uint_t aubio_sink_sndfile_get_channels( aubio_sink_sndfile_t *s)124 uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s) 115 125 { 116 126 return s->channels; … … 130 140 if (s->handle == NULL) { 131 141 /* show libsndfile err msg */ 132 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)); 133 144 return AUBIO_FAIL; 134 145 } … … 136 147 s->scratch_size = s->max_size*s->channels; 137 148 /* allocate data for de/interleaving reallocated when needed. */ 138 if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) { 149 if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) { 150 abort(); 139 151 AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n", 140 s->max_size, s->channels, MAX_ CHANNELS *MAX_CHANNELS);152 s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS); 141 153 return AUBIO_FAIL; 142 154 } … … 220 232 void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){ 221 233 if (!s) return; 234 if (s->path) AUBIO_FREE(s->path); 222 235 aubio_sink_sndfile_close(s); 223 236 AUBIO_FREE(s->scratch_data); -
src/io/sink_sndfile.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SINK_SNDFILE_H22 #define _AUBIO_SINK_SNDFILE_H21 #ifndef AUBIO_SINK_SNDFILE_H 22 #define AUBIO_SINK_SNDFILE_H 23 23 24 24 /** \file … … 58 58 59 59 */ 60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(c har_t * uri, uint_t samplerate);60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * uri, uint_t samplerate); 61 61 62 62 /** … … 102 102 103 103 */ 104 uint_t aubio_sink_sndfile_get_samplerate( aubio_sink_sndfile_t *s);104 uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s); 105 105 106 106 /** … … 112 112 113 113 */ 114 uint_t aubio_sink_sndfile_get_channels( aubio_sink_sndfile_t *s);114 uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s); 115 115 116 116 /** … … 160 160 #endif 161 161 162 #endif /* _AUBIO_SINK_SNDFILE_H */162 #endif /* AUBIO_SINK_SNDFILE_H */ -
src/io/sink_wavwrite.c
r00d0275 r155cc10 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 … … 69 68 }; 70 69 71 unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length); 72 unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length) { 70 static unsigned char *write_little_endian (unsigned int s, unsigned char *str, 71 unsigned int length); 72 73 static unsigned char *write_little_endian (unsigned int s, unsigned char *str, 74 unsigned int length) 75 { 73 76 uint_t i; 74 77 for (i = 0; i < length; i++) { … … 78 81 } 79 82 80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(c har_t * path, uint_t samplerate) {83 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samplerate) { 81 84 aubio_sink_wavwrite_t * s = AUBIO_NEW(aubio_sink_wavwrite_t); 82 85 … … 90 93 } 91 94 92 s->path = path; 95 if (s->path) AUBIO_FREE(s->path); 96 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 97 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 98 93 99 s->max_size = MAX_SIZE; 94 100 s->bitspersample = 16; … … 98 104 s->channels = 0; 99 105 100 // negative samplerate given, abort101 if ((sint_t)samplerate < 0) goto beach;102 106 // zero samplerate given. do not open yet 103 if ((sint_t)samplerate == 0) return s; 104 // samplerate way too large, fail 105 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 } 106 114 107 115 s->samplerate = samplerate; … … 123 131 uint_t aubio_sink_wavwrite_preset_samplerate(aubio_sink_wavwrite_t *s, uint_t samplerate) 124 132 { 125 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 133 if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) { 134 return AUBIO_FAIL; 135 } 126 136 s->samplerate = samplerate; 127 137 // automatically open when both samplerate and channels have been set … … 134 144 uint_t aubio_sink_wavwrite_preset_channels(aubio_sink_wavwrite_t *s, uint_t channels) 135 145 { 136 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 146 if (aubio_io_validate_channels("sink_wavwrite", s->path, channels)) { 147 return AUBIO_FAIL; 148 } 137 149 s->channels = channels; 138 150 // automatically open when both samplerate and channels have been set … … 143 155 } 144 156 145 uint_t aubio_sink_wavwrite_get_samplerate( aubio_sink_wavwrite_t *s)157 uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s) 146 158 { 147 159 return s->samplerate; 148 160 } 149 161 150 uint_t aubio_sink_wavwrite_get_channels( aubio_sink_wavwrite_t *s)162 uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s) 151 163 { 152 164 return s->channels; … … 207 219 s->scratch_size = s->max_size * s->channels; 208 220 /* allocate data for de/interleaving reallocated when needed. */ 209 if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {221 if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) { 210 222 AUBIO_ERR("sink_wavwrite: %d x %d exceeds SIZE maximum buffer size %d\n", 211 s->max_size, s->channels, MAX_SIZE * MAX_CHANNELS);223 s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS); 212 224 goto beach; 213 225 } … … 288 300 if (!s) return; 289 301 aubio_sink_wavwrite_close(s); 302 if (s->path) AUBIO_FREE(s->path); 290 303 AUBIO_FREE(s->scratch_data); 291 304 AUBIO_FREE(s); -
src/io/sink_wavwrite.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SINK_WAVWRITE_H22 #define _AUBIO_SINK_WAVWRITE_H21 #ifndef AUBIO_SINK_WAVWRITE_H 22 #define AUBIO_SINK_WAVWRITE_H 23 23 24 24 /** \file … … 58 58 59 59 */ 60 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(c har_t * uri, uint_t samplerate);60 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * uri, uint_t samplerate); 61 61 62 62 /** … … 102 102 103 103 */ 104 uint_t aubio_sink_wavwrite_get_samplerate( aubio_sink_wavwrite_t *s);104 uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s); 105 105 106 106 /** … … 112 112 113 113 */ 114 uint_t aubio_sink_wavwrite_get_channels( aubio_sink_wavwrite_t *s);114 uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s); 115 115 116 116 /** … … 160 160 #endif 161 161 162 #endif /* _AUBIO_SINK_WAVWRITE_H */162 #endif /* AUBIO_SINK_WAVWRITE_H */ -
src/io/source.c
r00d0275 r155cc10 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "fvec.h" … … 41 40 typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s); 42 41 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s); 42 typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s); 43 43 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek); 44 44 typedef uint_t (*aubio_source_close_t)(aubio_source_t * s); … … 51 51 aubio_source_get_samplerate_t s_get_samplerate; 52 52 aubio_source_get_channels_t s_get_channels; 53 aubio_source_get_duration_t s_get_duration; 53 54 aubio_source_seek_t s_seek; 54 55 aubio_source_close_t s_close; … … 56 57 }; 57 58 58 aubio_source_t * new_aubio_source(c har_t * uri, uint_t samplerate, uint_t hop_size) {59 aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) { 59 60 aubio_source_t * s = AUBIO_NEW(aubio_source_t); 60 #if HAVE_LIBAV61 #ifdef HAVE_LIBAV 61 62 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); 62 63 if (s->source) { … … 65 66 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels); 66 67 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate); 68 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration); 67 69 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); 68 70 s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close); … … 78 80 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels); 79 81 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate); 82 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration); 80 83 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); 81 84 s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close); … … 84 87 } 85 88 #endif /* HAVE_SOURCE_APPLE_AUDIO */ 86 #if HAVE_SNDFILE89 #ifdef HAVE_SNDFILE 87 90 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); 88 91 if (s->source) { … … 91 94 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels); 92 95 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate); 96 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration); 93 97 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); 94 98 s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close); … … 97 101 } 98 102 #endif /* HAVE_SNDFILE */ 99 #if HAVE_WAVREAD103 #ifdef HAVE_WAVREAD 100 104 s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size); 101 105 if (s->source) { … … 104 108 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels); 105 109 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate); 110 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration); 106 111 s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek); 107 112 s->s_close = (aubio_source_close_t)(aubio_source_wavread_close); … … 110 115 } 111 116 #endif /* HAVE_WAVREAD */ 112 AUBIO_ERROR("source: failed creating aubio source with %s" 113 " 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 114 124 AUBIO_FREE(s); 115 125 return NULL; … … 142 152 } 143 153 154 uint_t aubio_source_get_duration(aubio_source_t *s) { 155 return s->s_get_duration((void *)s->source); 156 } 157 144 158 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) { 145 159 return s->s_seek((void *)s->source, seek); -
src/io/source.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SOURCE_H22 #define _AUBIO_SOURCE_H21 #ifndef AUBIO_SOURCE_H 22 #define AUBIO_SOURCE_H 23 23 24 24 /** \file … … 86 86 87 87 */ 88 aubio_source_t * new_aubio_source(c har_t * uri, uint_t samplerate, uint_t hop_size);88 aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size); 89 89 90 90 /** … … 150 150 /** 151 151 152 get the duration of source object, in frames 153 154 \param s source object, created with ::new_aubio_source 155 \return number of frames in file 156 157 */ 158 uint_t aubio_source_get_duration (aubio_source_t * s); 159 160 /** 161 152 162 close source object 153 163 … … 172 182 #endif 173 183 174 #endif /* _AUBIO_SOURCE_H */184 #endif /* AUBIO_SOURCE_H */ -
src/io/source_apple_audio.c
r00d0275 r155cc10 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" … … 55 54 char_t *getPrintableOSStatusError(char_t *str, OSStatus error); 56 55 57 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, c har_t * path);58 59 aubio_source_apple_audio_t * new_aubio_source_apple_audio(c har_t * path, uint_t samplerate, uint_t block_size)56 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path); 57 58 aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, uint_t samplerate, uint_t block_size) 60 59 { 61 60 aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t); … … 80 79 s->block_size = block_size; 81 80 s->samplerate = samplerate; 82 s->path = path;83 81 84 82 if ( aubio_source_apple_audio_open ( s, path ) ) { … … 92 90 } 93 91 94 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, c har_t * path)92 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path) 95 93 { 96 94 OSStatus err = noErr; 97 95 UInt32 propSize; 98 s->path = path; 96 97 if (s->path) AUBIO_FREE(s->path); 98 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 99 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 99 100 100 101 // open the resource url 101 CFURLRef fileURL = createURLFromPath( path);102 CFURLRef fileURL = createURLFromPath(s->path); 102 103 err = ExtAudioFileOpenURL(fileURL, &s->audioFile); 103 104 CFRelease(fileURL); … … 279 280 { 280 281 OSStatus err = noErr; 281 if (!s->audioFile) { return AUBIO_ FAIL; }282 if (!s->audioFile) { return AUBIO_OK; } 282 283 err = ExtAudioFileDispose(s->audioFile); 283 284 s->audioFile = NULL; … … 294 295 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 295 296 aubio_source_apple_audio_close (s); 297 if (s->path) AUBIO_FREE(s->path); 296 298 freeAudioBufferList(&s->bufferList); 297 299 AUBIO_FREE(s); … … 309 311 } 310 312 // check if we are not seeking out of the file 311 SInt64 fileLengthFrames = 0; 312 UInt32 propSize = sizeof(fileLengthFrames); 313 ExtAudioFileGetProperty(s->audioFile, 314 kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames); 313 uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s); 315 314 // compute position in the source file, before resampling 316 315 smpl_t ratio = s->source_samplerate * 1. / s->samplerate; … … 353 352 } 354 353 355 uint_t aubio_source_apple_audio_get_samplerate( aubio_source_apple_audio_t * s) {354 uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s) { 356 355 return s->samplerate; 357 356 } 358 357 359 uint_t aubio_source_apple_audio_get_channels( aubio_source_apple_audio_t * s) {358 uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s) { 360 359 return s->channels; 361 360 } 362 361 362 uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) { 363 SInt64 fileLengthFrames = 0; 364 UInt32 propSize = sizeof(fileLengthFrames); 365 OSStatus err = ExtAudioFileGetProperty(s->audioFile, 366 kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames); 367 if (err) { 368 char_t errorstr[20]; 369 AUBIO_ERROR("source_apple_audio: Failed getting %s duration, " 370 "error in ExtAudioFileGetProperty (%s)\n", s->path, 371 getPrintableOSStatusError(errorstr, err)); 372 return err; 373 } 374 return (uint_t)fileLengthFrames; 375 } 376 363 377 #endif /* HAVE_SOURCE_APPLE_AUDIO */ -
src/io/source_apple_audio.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SOURCE_APPLE_AUDIO_H22 #define _AUBIO_SOURCE_APPLE_AUDIO_H21 #ifndef AUBIO_SOURCE_APPLE_AUDIO_H 22 #define AUBIO_SOURCE_APPLE_AUDIO_H 23 23 24 24 /** \file … … 58 58 59 59 */ 60 aubio_source_apple_audio_t * new_aubio_source_apple_audio(c har_t * uri, uint_t samplerate, uint_t hop_size);60 aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * uri, uint_t samplerate, uint_t hop_size); 61 61 62 62 /** … … 96 96 97 97 */ 98 uint_t aubio_source_apple_audio_get_samplerate( aubio_source_apple_audio_t * s);98 uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s); 99 99 100 100 /** … … 106 106 107 107 */ 108 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s); 108 uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s); 109 110 /** 111 112 get the duration of source object, in frames 113 114 \param s source object, created with ::new_aubio_source_apple_audio 115 \return number of frames in file 116 117 */ 118 uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s); 109 119 110 120 /** … … 144 154 #endif 145 155 146 #endif /* _AUBIO_SOURCE_APPLE_AUDIO_H */156 #endif /* AUBIO_SOURCE_APPLE_AUDIO_H */ -
src/io/source_avcodec.c
r00d0275 r155cc10 19 19 */ 20 20 21 22 #include "config.h" 21 #include "aubio_priv.h" 23 22 24 23 #ifdef HAVE_LIBAV 25 26 // determine whether we use libavformat from ffmpe or libav27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99)28 24 29 25 #include <libavcodec/avcodec.h> … … 33 29 #include <stdlib.h> 34 30 31 // determine whether we use libavformat from ffmpeg or from libav 32 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 ) 33 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100 34 #define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \ 35 (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \ 36 || (LIBAVFORMAT_VERSION_MAJOR == 56) \ 37 || (LIBAVFORMAT_VERSION_MAJOR == 57 && LIBAVFORMAT_VERSION_MINOR < 2) \ 38 ) 39 40 // backward compatibility with libavcodec55 41 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) 42 #warning "libavcodec55 is deprecated" 43 #define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1 44 #define av_frame_alloc avcodec_alloc_frame 45 #define av_frame_free avcodec_free_frame 46 #define av_packet_unref av_free_packet 47 #endif 48 35 49 #include "aubio_priv.h" 36 50 #include "fvec.h" … … 54 68 AVCodecContext *avCodecCtx; 55 69 AVFrame *avFrame; 70 AVPacket avPacket; 56 71 AVAudioResampleContext *avr; 57 float *output;72 smpl_t *output; 58 73 uint_t read_samples; 59 74 uint_t read_index; … … 67 82 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples); 68 83 69 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplerate, uint_t hop_size) { 84 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s); 85 86 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) { 87 char proto[20], authorization[256], hostname[128], uripath[256]; 88 int proto_size = 20, authorization_size = 256, hostname_size = 128, 89 *port_ptr = 0, path_size = 256; 90 av_url_split(proto, proto_size, authorization, authorization_size, hostname, 91 hostname_size, port_ptr, uripath, path_size, s->path); 92 if (strlen(proto)) { 93 return 1; 94 } 95 return 0; 96 } 97 98 99 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { 70 100 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 71 101 int err; … … 85 115 s->hop_size = hop_size; 86 116 s->channels = 1; 87 s->path = path; 117 118 if (s->path) AUBIO_FREE(s->path); 119 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 120 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 88 121 89 122 // register all formats and codecs 90 123 av_register_all(); 91 124 92 // if path[0] != '/' 93 //avformat_network_init(); 125 if (aubio_source_avcodec_has_network_url(s)) { 126 avformat_network_init(); 127 } 94 128 95 129 // try opening the file and get some info about it … … 104 138 105 139 // try to make sure max_analyze_duration is big enough for most songs 106 #if FFMPEG_LIBAVFORMAT 140 #if FFMPEG_LIBAVFORMAT_MAX_DUR2 107 141 avFormatCtx->max_analyze_duration2 *= 100; 108 142 #else … … 126 160 sint_t selected_stream = -1; 127 161 for (i = 0; i < avFormatCtx->nb_streams; i++) { 162 #if FF_API_LAVF_AVCTX 163 if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { 164 #else 128 165 if (avFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { 166 #endif 129 167 if (selected_stream == -1) { 130 168 selected_stream = i; … … 143 181 144 182 AVCodecContext *avCodecCtx = s->avCodecCtx; 183 #if FF_API_LAVF_AVCTX 184 AVCodecParameters *codecpar = avFormatCtx->streams[selected_stream]->codecpar; 185 if (codecpar == NULL) { 186 AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path); 187 goto beach; 188 } 189 AVCodec *codec = avcodec_find_decoder(codecpar->codec_id); 190 191 /* Allocate a codec context for the decoder */ 192 avCodecCtx = avcodec_alloc_context3(codec); 193 if (!avCodecCtx) { 194 AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context for path %s\n", 195 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 196 goto beach; 197 } 198 #else 145 199 avCodecCtx = avFormatCtx->streams[selected_stream]->codec; 146 200 AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id); 201 #endif 147 202 if (codec == NULL) { 148 203 AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path); 149 204 goto beach; 150 205 } 206 207 #if FF_API_LAVF_AVCTX 208 /* Copy codec parameters from input stream to output codec context */ 209 if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) { 210 AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to decoder context for %s\n", 211 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 212 goto beach; 213 } 214 #endif 151 215 152 216 if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) { … … 164 228 165 229 if (samplerate == 0) { 166 s amplerate = s->input_samplerate;167 //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);168 }169 s->samplerate = samplerate;230 s->samplerate = s->input_samplerate; 231 } else { 232 s->samplerate = samplerate; 233 } 170 234 171 235 if (s->samplerate > s->input_samplerate) { … … 181 245 182 246 /* allocate output for avr */ 183 s->output = ( float *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(float));247 s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(smpl_t)); 184 248 185 249 s->read_samples = 0; … … 208 272 209 273 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi) { 274 // create or reset resampler to/from mono/multi-channel 210 275 if ( (multi != s->multi) || (s->avr == NULL) ) { 211 276 int64_t input_layout = av_get_default_channel_layout(s->input_channels); 212 277 uint_t output_channels = multi ? s->input_channels : 1; 213 278 int64_t output_layout = av_get_default_channel_layout(output_channels); 214 if (s->avr != NULL) { 215 avresample_close( s->avr ); 216 av_free ( s->avr ); 217 s->avr = NULL; 218 } 219 AVAudioResampleContext *avr = s->avr; 220 avr = avresample_alloc_context(); 279 AVAudioResampleContext *avr = avresample_alloc_context(); 280 AVAudioResampleContext *oldavr = s->avr; 221 281 222 282 av_opt_set_int(avr, "in_channel_layout", input_layout, 0); … … 225 285 av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0); 226 286 av_opt_set_int(avr, "in_sample_fmt", s->avCodecCtx->sample_fmt, 0); 287 #if HAVE_AUBIO_DOUBLE 288 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0); 289 #else 227 290 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); 291 #endif 292 // TODO: use planar? 293 //av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 228 294 int err; 229 295 if ( ( err = avresample_open(avr) ) < 0) { … … 236 302 } 237 303 s->avr = avr; 304 if (oldavr != NULL) { 305 avresample_close( oldavr ); 306 av_free ( oldavr ); 307 oldavr = NULL; 308 } 238 309 s->multi = multi; 239 310 } … … 244 315 AVCodecContext *avCodecCtx = s->avCodecCtx; 245 316 AVFrame *avFrame = s->avFrame; 246 AVPacket avPacket ;317 AVPacket avPacket = s->avPacket; 247 318 av_init_packet (&avPacket); 248 319 AVAudioResampleContext *avr = s->avr; 249 float *output = s->output;320 smpl_t *output = s->output; 250 321 *read_samples = 0; 251 322 … … 260 331 char errorstr[256]; 261 332 av_strerror (err, errorstr, sizeof(errorstr)); 262 AUBIO_ERR(" Could not read frame in %s (%s)\n", s->path, errorstr);333 AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", s->path, errorstr); 263 334 goto beach; 264 335 } … … 266 337 267 338 int got_frame = 0; 339 #if FF_API_LAVF_AVCTX 340 int ret = avcodec_send_packet(avCodecCtx, &avPacket); 341 if (ret < 0 && ret != AVERROR_EOF) { 342 AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); 343 goto beach; 344 } 345 ret = avcodec_receive_frame(avCodecCtx, avFrame); 346 if (ret >= 0) { 347 got_frame = 1; 348 } 349 if (ret < 0) { 350 if (ret == AVERROR(EAGAIN)) { 351 AUBIO_WRN("source_avcodec: output is not available right now - user must try to send new input\n"); 352 } else if (ret == AVERROR_EOF) { 353 AUBIO_WRN("source_avcodec: the decoder has been fully flushed, and there will be no more output frames\n"); 354 } else { 355 AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path); 356 goto beach; 357 } 358 } 359 #else 268 360 int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket); 269 361 270 362 if (len < 0) { 271 AUBIO_ERR("Error while decoding %s\n", s->path); 272 goto beach; 273 } 363 AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path); 364 goto beach; 365 } 366 #endif 274 367 if (got_frame == 0) { 275 //AUBIO_ERR("Could not get frame for (%s)\n", s->path);368 AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n", s->path); 276 369 goto beach; 277 370 } … … 287 380 (uint8_t **)avFrame->data, in_linesize, in_samples); 288 381 if (out_samples <= 0) { 289 //AUBIO_ERR("No sample found while converting frame (%s)\n", s->path);382 AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", s->path); 290 383 goto beach; 291 384 } … … 300 393 s->output = output; 301 394 302 av_ free_packet(&avPacket);395 av_packet_unref(&avPacket); 303 396 } 304 397 305 398 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){ 306 if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);307 399 uint_t i; 308 400 uint_t end = 0; 309 401 uint_t total_wrote = 0; 402 // switch from multi 403 if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0); 310 404 while (total_wrote < s->hop_size) { 311 405 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 327 421 } 328 422 if (total_wrote < s->hop_size) { 329 for (i = end; i < s->hop_size; i++) {423 for (i = total_wrote; i < s->hop_size; i++) { 330 424 read_data->data[i] = 0.; 331 425 } … … 335 429 336 430 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, fmat_t * read_data, uint_t * read){ 337 if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);338 431 uint_t i,j; 339 432 uint_t end = 0; 340 433 uint_t total_wrote = 0; 434 // switch from mono 435 if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1); 341 436 while (total_wrote < s->hop_size) { 342 437 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 362 457 if (total_wrote < s->hop_size) { 363 458 for (j = 0; j < read_data->height; j++) { 364 for (i = end; i < s->hop_size; i++) {459 for (i = total_wrote; i < s->hop_size; i++) { 365 460 read_data->data[j][i] = 0.; 366 461 } … … 370 465 } 371 466 372 uint_t aubio_source_avcodec_get_samplerate( aubio_source_avcodec_t * s) {467 uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s) { 373 468 return s->samplerate; 374 469 } 375 470 376 uint_t aubio_source_avcodec_get_channels( aubio_source_avcodec_t * s) {471 uint_t aubio_source_avcodec_get_channels(const aubio_source_avcodec_t * s) { 377 472 return s->input_channels; 378 473 } … … 383 478 int64_t max_ts = MIN(resampled_pos + 2000, INT64_MAX); 384 479 int seek_flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_ANY; 385 int ret = avformat_seek_file(s->avFormatCtx, s->selected_stream, 480 int ret = AUBIO_FAIL; 481 if (s->avFormatCtx != NULL && s->avr != NULL) { 482 ret = AUBIO_OK; 483 } else { 484 AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)", s->path); 485 return ret; 486 } 487 if ((sint_t)pos < 0) { 488 AUBIO_ERR("source_avcodec: could not seek %s at %d (seeking position" 489 " should be >= 0)\n", s->path, pos); 490 return AUBIO_FAIL; 491 } 492 ret = avformat_seek_file(s->avFormatCtx, s->selected_stream, 386 493 min_ts, resampled_pos, max_ts, seek_flags); 387 494 if (ret < 0) { 388 AUBIO_ERR(" Failed seeking to %d in file %s", pos, s->path);495 AUBIO_ERR("source_avcodec: failed seeking to %d in file %s", pos, s->path); 389 496 } 390 497 // reset read status … … 398 505 } 399 506 507 uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) { 508 if (s && &(s->avFormatCtx) != NULL) { 509 int64_t duration = s->avFormatCtx->duration; 510 return s->samplerate * ((uint_t)duration / 1e6 ); 511 } 512 return 0; 513 } 514 400 515 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { 401 516 if (s->avr != NULL) { … … 409 524 s->avCodecCtx = NULL; 410 525 if (s->avFormatCtx != NULL) { 411 avformat_close_input ( &(s->avFormatCtx) ); 412 } 413 s->avFormatCtx = NULL; 526 avformat_close_input(&s->avFormatCtx); 527 #ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED // avoid crash on old libavcodec54 528 avformat_free_context(s->avFormatCtx); 529 #endif 530 s->avFormatCtx = NULL; 531 } 532 av_packet_unref(&s->avPacket); 414 533 return AUBIO_OK; 415 534 } … … 426 545 } 427 546 s->avFrame = NULL; 547 if (s->path) { 548 AUBIO_FREE(s->path); 549 } 550 s->path = NULL; 428 551 AUBIO_FREE(s); 429 552 } -
src/io/source_avcodec.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SOURCE_AVCODEC_H22 #define _AUBIO_SOURCE_AVCODEC_H21 #ifndef AUBIO_SOURCE_AVCODEC_H 22 #define AUBIO_SOURCE_AVCODEC_H 23 23 24 24 /** \file … … 57 57 58 58 */ 59 aubio_source_avcodec_t * new_aubio_source_avcodec(c har_t * uri, uint_t samplerate, uint_t hop_size);59 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * uri, uint_t samplerate, uint_t hop_size); 60 60 61 61 /** … … 95 95 96 96 */ 97 uint_t aubio_source_avcodec_get_samplerate( aubio_source_avcodec_t * s);97 uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s); 98 98 99 99 /** … … 105 105 106 106 */ 107 uint_t aubio_source_avcodec_get_channels ( aubio_source_avcodec_t * s);107 uint_t aubio_source_avcodec_get_channels (const aubio_source_avcodec_t * s); 108 108 109 109 /** … … 118 118 */ 119 119 uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t *s, uint_t pos); 120 121 /** 122 123 get the duration of source object, in frames 124 125 \param s source object, created with ::new_aubio_source_avcodec 126 \return number of frames in file 127 128 */ 129 uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s); 120 130 121 131 /** … … 143 153 #endif 144 154 145 #endif /* _AUBIO_SOURCE_AVCODEC_H */155 #endif /* AUBIO_SOURCE_AVCODEC_H */ -
src/io/source_sndfile.c
r00d0275 r155cc10 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_SIZE 34 #define MAX_SAMPLES AUBIO_MAX_CHANNELS * MAX_SIZE 35 36 #if !HAVE_AUBIO_DOUBLE 37 #define aubio_sf_read_smpl sf_read_float 38 #else /* HAVE_AUBIO_DOUBLE */ 39 #define aubio_sf_read_smpl sf_read_double 40 #endif /* HAVE_AUBIO_DOUBLE */ 38 41 39 42 struct _aubio_source_sndfile_t { … … 48 51 int input_channels; 49 52 int input_format; 53 int duration; 50 54 51 55 // resampling stuff … … 53 57 uint_t input_hop_size; 54 58 #ifdef HAVE_SAMPLERATE 55 aubio_resampler_t * resampler;59 aubio_resampler_t **resamplers; 56 60 fvec_t *input_data; 61 fmat_t *input_mat; 57 62 #endif /* HAVE_SAMPLERATE */ 58 63 59 64 // some temporary memory for sndfile to write at 60 65 uint_t scratch_size; 61 float *scratch_data;66 smpl_t *scratch_data; 62 67 }; 63 68 64 aubio_source_sndfile_t * new_aubio_source_sndfile(c har_t * path, uint_t samplerate, uint_t hop_size) {69 aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t samplerate, uint_t hop_size) { 65 70 aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t); 66 71 SF_INFO sfinfo; … … 81 86 s->hop_size = hop_size; 82 87 s->channels = 1; 83 s->path = path; 88 89 if (s->path) AUBIO_FREE(s->path); 90 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 91 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 84 92 85 93 // try opening the file, getting the info in sfinfo … … 89 97 if (s->handle == NULL) { 90 98 /* show libsndfile err msg */ 91 AUBIO_ERR("source_sndfile: Failed opening %s: %s\n", s->path, sf_strerror (NULL)); 99 AUBIO_ERR("source_sndfile: Failed opening %s (%s)\n", s->path, 100 sf_strerror (NULL)); 92 101 goto beach; 93 102 } … … 97 106 s->input_channels = sfinfo.channels; 98 107 s->input_format = sfinfo.format; 108 s->duration = sfinfo.frames; 99 109 100 110 if (samplerate == 0) { 101 s amplerate = s->input_samplerate;111 s->samplerate = s->input_samplerate; 102 112 //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate); 103 } 104 s->samplerate = samplerate; 113 } else { 114 s->samplerate = samplerate; 115 } 105 116 /* compute input block size required before resampling */ 106 s->ratio = s->samplerate/( float)s->input_samplerate;117 s->ratio = s->samplerate/(smpl_t)s->input_samplerate; 107 118 s->input_hop_size = (uint_t)FLOOR(s->hop_size / s->ratio + .5); 108 119 … … 114 125 115 126 #ifdef HAVE_SAMPLERATE 116 s->resampler = NULL;117 127 s->input_data = NULL; 128 s->input_mat = NULL; 129 s->resamplers = NULL; 118 130 if (s->ratio != 1) { 131 uint_t i; 132 s->resamplers = AUBIO_ARRAY(aubio_resampler_t*, s->input_channels); 119 133 s->input_data = new_fvec(s->input_hop_size); 120 s->resampler = new_aubio_resampler(s->ratio, 4); 134 s->input_mat = new_fmat(s->input_channels, s->input_hop_size); 135 for (i = 0; i < (uint_t)s->input_channels; i++) { 136 s->resamplers[i] = new_aubio_resampler(s->ratio, 4); 137 } 121 138 if (s->ratio > 1) { 122 139 // we would need to add a ring buffer for these 123 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 ) { 124 141 AUBIO_ERR("source_sndfile: can not upsample %s from %d to %d\n", s->path, 125 142 s->input_samplerate, s->samplerate); … … 129 146 s->input_samplerate, s->samplerate); 130 147 } 148 s->duration = (uint_t)FLOOR(s->duration * s->ratio); 131 149 } 132 150 #else … … 139 157 /* allocate data for de/interleaving reallocated when needed. */ 140 158 s->scratch_size = s->input_hop_size * s->input_channels; 141 s->scratch_data = AUBIO_ARRAY( float,s->scratch_size);159 s->scratch_data = AUBIO_ARRAY(smpl_t, s->scratch_size); 142 160 143 161 return s; … … 153 171 uint_t i,j, input_channels = s->input_channels; 154 172 /* read from file into scratch_data */ 155 sf_count_t read_samples = sf_read_float(s->handle, s->scratch_data, s->scratch_size);173 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 156 174 157 175 /* where to store de-interleaved data */ … … 176 194 177 195 #ifdef HAVE_SAMPLERATE 178 if (s->resampler ) {179 aubio_resampler_do(s->resampler , s->input_data, read_data);196 if (s->resamplers) { 197 aubio_resampler_do(s->resamplers[0], s->input_data, read_data); 180 198 } 181 199 #endif /* HAVE_SAMPLERATE */ … … 194 212 uint_t i,j, input_channels = s->input_channels; 195 213 /* do actual reading */ 196 sf_count_t read_samples = sf_read_float(s->handle, s->scratch_data, s->scratch_size);214 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 197 215 198 216 /* where to store de-interleaved data */ … … 200 218 #ifdef HAVE_SAMPLERATE 201 219 if (s->ratio != 1) { 202 AUBIO_ERR("source_sndfile: no multi channel resampling yet\n"); 203 return; 204 //ptr_data = s->input_data->data; 220 ptr_data = s->input_mat->data; 205 221 } else 206 222 #endif /* HAVE_SAMPLERATE */ … … 214 230 for (j = 0; j < read_samples / input_channels; j++) { 215 231 for (i = 0; i < read_data->height; i++) { 216 ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];232 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 217 233 } 218 234 } … … 222 238 for (j = 0; j < read_samples / input_channels; j++) { 223 239 for (i = 0; i < input_channels; i++) { 224 ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];240 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 225 241 } 226 242 } … … 232 248 for (j = 0; j < read_samples / input_channels; j++) { 233 249 for (i = input_channels; i < read_data->height; i++) { 234 ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + (input_channels - 1)]; 235 } 236 } 237 } 238 239 #ifdef HAVE_SAMPLERATE 240 if (s->resampler) { 241 //aubio_resampler_do(s->resampler, s->input_data, read_data); 250 ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)]; 251 } 252 } 253 } 254 255 #ifdef HAVE_SAMPLERATE 256 if (s->resamplers) { 257 for (i = 0; i < input_channels; i++) { 258 fvec_t input_chan, read_chan; 259 input_chan.data = s->input_mat->data[i]; 260 input_chan.length = s->input_mat->length; 261 read_chan.data = read_data->data[i]; 262 read_chan.length = read_data->length; 263 aubio_resampler_do(s->resamplers[i], &input_chan, &read_chan); 264 } 242 265 } 243 266 #endif /* HAVE_SAMPLERATE */ … … 263 286 } 264 287 288 uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) { 289 if (s && s->duration) { 290 return s->duration; 291 } 292 return 0; 293 } 294 265 295 uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) { 266 296 uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio); 267 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); 268 309 if (sf_ret == -1) { 269 310 AUBIO_ERR("source_sndfile: Failed seeking %s at %d: %s\n", s->path, pos, sf_strerror (NULL)); … … 280 321 uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) { 281 322 if (!s->handle) { 282 return AUBIO_ FAIL;323 return AUBIO_OK; 283 324 } 284 325 if(sf_close(s->handle)) { … … 286 327 return AUBIO_FAIL; 287 328 } 329 s->handle = NULL; 288 330 return AUBIO_OK; 289 331 } … … 293 335 aubio_source_sndfile_close(s); 294 336 #ifdef HAVE_SAMPLERATE 295 if (s->resampler != NULL) { 296 del_aubio_resampler(s->resampler); 337 if (s->resamplers != NULL) { 338 uint_t i = 0, input_channels = s->input_channels; 339 for (i = 0; i < input_channels; i ++) { 340 if (s->resamplers[i] != NULL) { 341 del_aubio_resampler(s->resamplers[i]); 342 } 343 } 344 AUBIO_FREE(s->resamplers); 297 345 } 298 346 if (s->input_data) { 299 347 del_fvec(s->input_data); 300 348 } 301 #endif /* HAVE_SAMPLERATE */ 349 if (s->input_mat) { 350 del_fmat(s->input_mat); 351 } 352 #endif /* HAVE_SAMPLERATE */ 353 if (s->path) AUBIO_FREE(s->path); 302 354 AUBIO_FREE(s->scratch_data); 303 355 AUBIO_FREE(s); -
src/io/source_sndfile.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SOURCE_SNDFILE_H22 #define _AUBIO_SOURCE_SNDFILE_H21 #ifndef AUBIO_SOURCE_SNDFILE_H 22 #define AUBIO_SOURCE_SNDFILE_H 23 23 24 24 /** \file … … 57 57 58 58 */ 59 aubio_source_sndfile_t * new_aubio_source_sndfile(c har_t * uri, uint_t samplerate, uint_t hop_size);59 aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * uri, uint_t samplerate, uint_t hop_size); 60 60 61 61 /** … … 121 121 /** 122 122 123 get the duration of source object, in frames 124 125 \param s source object, created with ::new_aubio_source_sndfile 126 \return number of frames in file 127 128 */ 129 uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t *s); 130 131 /** 132 123 133 close source 124 134 … … 143 153 #endif 144 154 145 #endif /* _AUBIO_SOURCE_SNDFILE_H */155 #endif /* AUBIO_SOURCE_SNDFILE_H */ -
src/io/source_wavread.c
r00d0275 r155cc10 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" … … 53 52 uint_t eof; 54 53 54 uint_t duration; 55 55 56 size_t seek_start; 56 57 … … 59 60 }; 60 61 61 unsigned int read_little_endian (unsigned char *buf, unsigned int length); 62 unsigned int read_little_endian (unsigned char *buf, unsigned int length) { 62 static unsigned int read_little_endian (unsigned char *buf, 63 unsigned int length); 64 65 static unsigned int read_little_endian (unsigned char *buf, 66 unsigned int length) 67 { 63 68 uint_t i, ret = 0; 64 69 for (i = 0; i < length; i++) { … … 68 73 } 69 74 70 aubio_source_wavread_t * new_aubio_source_wavread(c har_t * path, uint_t samplerate, uint_t hop_size) {75 aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) { 71 76 aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t); 72 size_t bytes_read = 0, bytes_ expected = 44;73 unsigned char buf[5] ;74 unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size;77 size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44; 78 unsigned char buf[5] = "\0"; 79 unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size; 75 80 76 81 if (path == NULL) { … … 87 92 } 88 93 89 s->path = path; 94 if (s->path) AUBIO_FREE(s->path); 95 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 96 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 97 90 98 s->samplerate = samplerate; 91 99 s->hop_size = hop_size; … … 101 109 buf[4] = '\0'; 102 110 if ( strcmp((const char *)buf, "RIFF") != 0 ) { 103 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); 104 112 goto beach; 105 113 } … … 112 120 buf[4] = '\0'; 113 121 if ( strcmp((const char *)buf, "WAVE") != 0 ) { 114 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); 115 123 goto beach; 116 124 } … … 119 127 bytes_read += fread(buf, 1, 4, s->fid); 120 128 buf[4] = '\0'; 129 130 // check if we have a JUNK Chunk 131 if ( strcmp((const char *)buf, "JUNK") == 0 ) { 132 bytes_junk = fread(buf, 1, 4, s->fid); 133 buf[4] = '\0'; 134 bytes_junk += read_little_endian(buf, 4); 135 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 136 AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n", 137 s->path, strerror(errno)); 138 goto beach; 139 } 140 bytes_read += bytes_junk; 141 bytes_expected += bytes_junk + 4; 142 // now really read the fmt chunk 143 bytes_read += fread(buf, 1, 4, s->fid); 144 buf[4] = '\0'; 145 } 146 147 // get the fmt chunk 121 148 if ( strcmp((const char *)buf, "fmt ") != 0 ) { 122 AUBIO_ERR("source_wavread: 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); 123 150 goto beach; 124 151 } … … 129 156 if ( format != 16 ) { 130 157 // TODO accept format 18 131 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); 132 159 goto beach; 133 160 } 134 161 if ( buf[1] || buf[2] | buf[3] ) { 135 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); 136 163 goto beach; 137 164 } … … 140 167 bytes_read += fread(buf, 1, 2, s->fid); 141 168 if ( buf[0] != 1 || buf[1] != 0) { 142 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); 143 170 goto beach; 144 171 } … … 172 199 173 200 if ( byterate * 8 != sr * channels * bitspersample ) { 174 AUBIO_ERR("source_wavread: wrong byterate in %s\n", s->path);201 AUBIO_ERR("source_wavread: Failed opening %s (wrong byterate)\n", s->path); 175 202 goto beach; 176 203 } 177 204 178 205 if ( blockalign * 8 != channels * bitspersample ) { 179 AUBIO_ERR("source_wavread: wrong blockalign in %s\n", s->path);206 AUBIO_ERR("source_wavread: Failed opening %s (wrong blockalign)\n", s->path); 180 207 goto beach; 181 208 } … … 206 233 bytes_read += fread(buf, 1, 4, s->fid); 207 234 buf[4] = '\0'; 208 if ( strcmp((const char *)buf, "data") != 0 ) { 209 AUBIO_ERR("source_wavread: data RIFF header not found in %s\n", s->path); 210 goto beach; 235 while ( strcmp((const char *)buf, "data") != 0 ) { 236 if (feof(s->fid) || ferror(s->fid)) { 237 AUBIO_ERR("source_wavread: no data RIFF header found in %s\n", s->path); 238 goto beach; 239 } 240 bytes_junk = fread(buf, 1, 4, s->fid); 241 buf[4] = '\0'; 242 bytes_junk += read_little_endian(buf, 4); 243 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 244 AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n", 245 s->path, strerror(errno)); 246 goto beach; 247 } 248 bytes_read += bytes_junk; 249 bytes_expected += bytes_junk+ 4; 250 bytes_read += fread(buf, 1, 4, s->fid); 251 buf[4] = '\0'; 211 252 } 212 253 213 254 // Subchunk2Size 214 255 bytes_read += fread(buf, 1, 4, s->fid); 256 duration = read_little_endian(buf, 4) / blockalign; 257 215 258 //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24); 216 259 //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path); … … 233 276 s->bitspersample = bitspersample; 234 277 278 s->duration = duration; 279 235 280 s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE); 236 281 s->read_index = 0; … … 284 329 uint_t end = 0; 285 330 uint_t total_wrote = 0; 331 if (s->fid == NULL) { 332 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 333 s->path); 334 return; 335 } 286 336 while (total_wrote < s->hop_size) { 287 337 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 318 368 uint_t end = 0; 319 369 uint_t total_wrote = 0; 370 if (s->fid == NULL) { 371 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 372 s->path); 373 return; 374 } 320 375 while (total_wrote < s->hop_size) { 321 376 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 358 413 uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) { 359 414 uint_t ret = 0; 415 if (s->fid == NULL) { 416 AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos); 417 return AUBIO_FAIL; 418 } 360 419 if ((sint_t)pos < 0) { 420 AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos); 361 421 return AUBIO_FAIL; 362 422 } … … 372 432 } 373 433 434 uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t * s) { 435 if (s && s->duration) { 436 return s->duration; 437 } 438 return 0; 439 } 440 374 441 uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) { 375 if ( !s->fid) {376 return AUBIO_ FAIL;442 if (s->fid == NULL) { 443 return AUBIO_OK; 377 444 } 378 445 if (fclose(s->fid)) { … … 389 456 if (s->short_output) AUBIO_FREE(s->short_output); 390 457 if (s->output) del_fmat(s->output); 458 if (s->path) AUBIO_FREE(s->path); 391 459 AUBIO_FREE(s); 392 460 } -
src/io/source_wavread.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SOURCE_WAVREAD_H22 #define _AUBIO_SOURCE_WAVREAD_H21 #ifndef AUBIO_SOURCE_WAVREAD_H 22 #define AUBIO_SOURCE_WAVREAD_H 23 23 24 24 /** \file … … 62 62 63 63 */ 64 aubio_source_wavread_t * new_aubio_source_wavread(c har_t * uri, uint_t samplerate, uint_t hop_size);64 aubio_source_wavread_t * new_aubio_source_wavread(const char_t * uri, uint_t samplerate, uint_t hop_size); 65 65 66 66 /** … … 126 126 /** 127 127 128 get the duration of source object, in frames 129 130 \param s source object, created with ::new_aubio_source_sndfile 131 \return number of frames in file 132 133 */ 134 uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t *s); 135 136 /** 137 128 138 close source 129 139 … … 148 158 #endif 149 159 150 #endif /* _AUBIO_SOURCE_WAVREAD_H */160 #endif /* AUBIO_SOURCE_WAVREAD_H */ -
src/io/utils_apple_audio.c
r00d0275 r155cc10 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/lvec.c
r00d0275 r155cc10 22 22 #include "lvec.h" 23 23 24 lvec_t * new_lvec( 24 lvec_t * new_lvec(uint_t length) { 25 25 lvec_t * s; 26 26 if ((sint_t)length <= 0) { … … 46 46 } 47 47 48 lsmp_t * lvec_get_data( lvec_t *s) {48 lsmp_t * lvec_get_data(const lvec_t *s) { 49 49 return s->data; 50 50 } … … 52 52 /* helper functions */ 53 53 54 void lvec_print( lvec_t *s) {54 void lvec_print(const lvec_t *s) { 55 55 uint_t j; 56 56 for (j=0; j< s->length; j++) { -
src/lvec.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO__LVEC_H22 #define _AUBIO__LVEC_H21 #ifndef AUBIO_LVEC_H 22 #define AUBIO_LVEC_H 23 23 24 24 #ifdef __cplusplus … … 81 81 82 82 */ 83 lsmp_t * lvec_get_data( lvec_t *s);83 lsmp_t * lvec_get_data(const lvec_t *s); 84 84 85 85 /** print out lvec data … … 88 88 89 89 */ 90 void lvec_print( lvec_t *s);90 void lvec_print(const lvec_t *s); 91 91 92 92 /** set all elements to a given value … … 116 116 #endif 117 117 118 #endif /* _AUBIO__LVEC_H */118 #endif /* AUBIO_LVEC_H */ -
src/mathutils.c
r00d0275 r155cc10 25 25 #include "mathutils.h" 26 26 #include "musicutils.h" 27 #include "config.h"28 27 29 28 /** Window types */ … … 254 253 fvec_shift (fvec_t * s) 255 254 { 255 uint_t half = s->length / 2, start = half, j; 256 // if length is odd, middle element is moved to the end 257 if (2 * half < s->length) start ++; 256 258 #ifndef HAVE_ATLAS 257 uint_t j; 258 for (j = 0; j < s->length / 2; j++) { 259 ELEM_SWAP (s->data[j], s->data[j + s->length / 2]); 260 } 261 #else 262 uint_t half = s->length / 2; 263 aubio_cblas_swap(half, s->data, 1, s->data + half, 1); 264 #endif 265 } 266 267 smpl_t 268 aubio_level_lin (fvec_t * f) 259 for (j = 0; j < half; j++) { 260 ELEM_SWAP (s->data[j], s->data[j + start]); 261 } 262 #else 263 aubio_cblas_swap(half, s->data, 1, s->data + start, 1); 264 #endif 265 if (start != half) { 266 for (j = 0; j < half; j++) { 267 ELEM_SWAP (s->data[j + start - 1], s->data[j + start]); 268 } 269 } 270 } 271 272 void 273 fvec_ishift (fvec_t * s) 274 { 275 uint_t half = s->length / 2, start = half, j; 276 // if length is odd, middle element is moved to the beginning 277 if (2 * half < s->length) start ++; 278 #ifndef HAVE_ATLAS 279 for (j = 0; j < half; j++) { 280 ELEM_SWAP (s->data[j], s->data[j + start]); 281 } 282 #else 283 aubio_cblas_swap(half, s->data, 1, s->data + start, 1); 284 #endif 285 if (start != half) { 286 for (j = 0; j < half; j++) { 287 ELEM_SWAP (s->data[half], s->data[j]); 288 } 289 } 290 } 291 292 smpl_t 293 aubio_level_lin (const fvec_t * f) 269 294 { 270 295 smpl_t energy = 0.; … … 415 440 } 416 441 417 smpl_t fvec_quadratic_peak_pos ( fvec_t * x, uint_t pos) {442 smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t pos) { 418 443 smpl_t s0, s1, s2; uint_t x0, x2; 444 smpl_t half = .5, two = 2.; 419 445 if (pos == 0 || pos == x->length - 1) return pos; 420 446 x0 = (pos < 1) ? pos : pos - 1; … … 425 451 s1 = x->data[pos]; 426 452 s2 = x->data[x2]; 427 return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);453 return pos + half * (s0 - s2 ) / (s0 - two * s1 + s2); 428 454 } 429 455 … … 439 465 } 440 466 441 uint_t fvec_peakpick( fvec_t * onset, uint_t pos) {467 uint_t fvec_peakpick(const fvec_t * onset, uint_t pos) { 442 468 uint_t tmp=0; 443 469 tmp = (onset->data[pos] > onset->data[pos-1] … … 526 552 527 553 smpl_t 528 aubio_db_spl ( fvec_t * o)554 aubio_db_spl (const fvec_t * o) 529 555 { 530 556 return 10. * LOG10 (aubio_level_lin (o)); … … 532 558 533 559 uint_t 534 aubio_silence_detection ( fvec_t * o, smpl_t threshold)560 aubio_silence_detection (const fvec_t * o, smpl_t threshold) 535 561 { 536 562 return (aubio_db_spl (o) < threshold); … … 538 564 539 565 smpl_t 540 aubio_level_detection ( fvec_t * o, smpl_t threshold)566 aubio_level_detection (const fvec_t * o, smpl_t threshold) 541 567 { 542 568 smpl_t db_spl = aubio_db_spl (o); … … 572 598 573 599 void 574 aubio_autocorr ( fvec_t * input, fvec_t * output)600 aubio_autocorr (const fvec_t * input, fvec_t * output) 575 601 { 576 602 uint_t i, j, length = input->length; -
src/mathutils.h
r00d0275 r155cc10 28 28 */ 29 29 30 #ifndef _AUBIO_MATHUTILS_H31 #define _AUBIO_MATHUTILS_H30 #ifndef AUBIO_MATHUTILS_H 31 #define AUBIO_MATHUTILS_H 32 32 33 33 #include "fvec.h" … … 99 99 */ 100 100 void fvec_shift (fvec_t * v); 101 102 /** swap the left and right halves of a vector 103 104 This function swaps the left part of the signal with the right part of the 105 signal. Therefore 106 107 \f$ a[0], a[1], ..., a[\frac{N}{2}], a[\frac{N}{2}+1], ..., a[N-1], a[N] \f$ 108 109 becomes 110 111 \f$ a[\frac{N}{2}+1], ..., a[N-1], a[N], a[0], a[1], ..., a[\frac{N}{2}] \f$ 112 113 This operation, known as 'ifftshift' in the Matlab Signal Processing Toolbox, 114 can be used after computing the inverse FFT to simplify the phase relationship 115 of the resulting spectrum. See Amalia de Götzen's paper referred to above. 116 117 */ 118 void fvec_ishift (fvec_t * v); 101 119 102 120 /** compute the sum of all elements of a vector … … 233 251 234 252 */ 235 smpl_t fvec_quadratic_peak_pos ( fvec_t * x, uint_t p);253 smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t p); 236 254 237 255 /** finds magnitude of peak by quadratic interpolation … … 276 294 277 295 */ 278 uint_t fvec_peakpick ( fvec_t * v, uint_t p);296 uint_t fvec_peakpick (const fvec_t * v, uint_t p); 279 297 280 298 /** return 1 if a is a power of 2, 0 otherwise */ … … 290 308 291 309 */ 292 void aubio_autocorr ( fvec_t * input, fvec_t * output);310 void aubio_autocorr (const fvec_t * input, fvec_t * output); 293 311 294 312 #ifdef __cplusplus … … 296 314 #endif 297 315 298 #endif /* _AUBIO_MATHUTILS_H */316 #endif /* AUBIO_MATHUTILS_H */ -
src/musicutils.h
r00d0275 r155cc10 23 23 */ 24 24 25 #ifndef _AUBIO__MUSICUTILS_H26 #define _AUBIO__MUSICUTILS_H25 #ifndef AUBIO_MUSICUTILS_H 26 #define AUBIO_MUSICUTILS_H 27 27 28 28 #ifdef __cplusplus … … 122 122 123 123 */ 124 smpl_t aubio_level_lin ( fvec_t * v);124 smpl_t aubio_level_lin (const fvec_t * v); 125 125 126 126 /** compute sound pressure level (SPL) in dB … … 135 135 136 136 */ 137 smpl_t aubio_db_spl ( fvec_t * v);137 smpl_t aubio_db_spl (const fvec_t * v); 138 138 139 139 /** check if buffer level in dB SPL is under a given threshold … … 145 145 146 146 */ 147 uint_t aubio_silence_detection ( fvec_t * v, smpl_t threshold);147 uint_t aubio_silence_detection (const fvec_t * v, smpl_t threshold); 148 148 149 149 /** get buffer level if level >= threshold, 1. otherwise … … 155 155 156 156 */ 157 smpl_t aubio_level_detection ( fvec_t * v, smpl_t threshold);157 smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold); 158 158 159 159 #ifdef __cplusplus … … 161 161 #endif 162 162 163 #endif /* _AUBIO__MUSICUTILS_H */163 #endif /* AUBIO_MUSICUTILS_H */ -
src/onset/onset.c
r00d0275 r155cc10 52 52 53 53 /* execute onset detection function on iput buffer */ 54 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)54 void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset) 55 55 { 56 56 smpl_t isonset = 0; … … 100 100 } 101 101 102 uint_t aubio_onset_get_last ( aubio_onset_t *o)102 uint_t aubio_onset_get_last (const aubio_onset_t *o) 103 103 { 104 104 return o->last_onset - o->delay; 105 105 } 106 106 107 smpl_t aubio_onset_get_last_s ( aubio_onset_t *o)107 smpl_t aubio_onset_get_last_s (const aubio_onset_t *o) 108 108 { 109 109 return aubio_onset_get_last (o) / (smpl_t) (o->samplerate); 110 110 } 111 111 112 smpl_t aubio_onset_get_last_ms ( aubio_onset_t *o)112 smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o) 113 113 { 114 114 return aubio_onset_get_last_s (o) * 1000.; … … 131 131 } 132 132 133 smpl_t aubio_onset_get_silence( aubio_onset_t * o) {133 smpl_t aubio_onset_get_silence(const aubio_onset_t * o) { 134 134 return o->silence; 135 135 } … … 140 140 } 141 141 142 smpl_t aubio_onset_get_threshold( aubio_onset_t * o) {142 smpl_t aubio_onset_get_threshold(const aubio_onset_t * o) { 143 143 return aubio_peakpicker_get_threshold(o->pp); 144 144 } … … 149 149 } 150 150 151 uint_t aubio_onset_get_minioi( aubio_onset_t * o) {151 uint_t aubio_onset_get_minioi(const aubio_onset_t * o) { 152 152 return o->minioi; 153 153 } 154 154 155 155 uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) { 156 return aubio_onset_set_minioi (o, minioi * o->samplerate);157 } 158 159 smpl_t aubio_onset_get_minioi_s( aubio_onset_t * o) {156 return aubio_onset_set_minioi (o, (uint_t)ROUND(minioi * o->samplerate)); 157 } 158 159 smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o) { 160 160 return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate; 161 161 } … … 165 165 } 166 166 167 smpl_t aubio_onset_get_minioi_ms( aubio_onset_t * o) {167 smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o) { 168 168 return aubio_onset_get_minioi_s (o) * 1000.; 169 169 } … … 174 174 } 175 175 176 uint_t aubio_onset_get_delay( aubio_onset_t * o) {176 uint_t aubio_onset_get_delay(const aubio_onset_t * o) { 177 177 return o->delay; 178 178 } … … 182 182 } 183 183 184 smpl_t aubio_onset_get_delay_s( aubio_onset_t * o) {184 smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o) { 185 185 return aubio_onset_get_delay (o) / (smpl_t) o->samplerate; 186 186 } … … 190 190 } 191 191 192 smpl_t aubio_onset_get_delay_ms( aubio_onset_t * o) {192 smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o) { 193 193 return aubio_onset_get_delay_s (o) * 1000.; 194 194 } 195 195 196 smpl_t aubio_onset_get_descriptor( aubio_onset_t * o) {196 smpl_t aubio_onset_get_descriptor(const aubio_onset_t * o) { 197 197 return o->desc->data[0]; 198 198 } 199 199 200 smpl_t aubio_onset_get_thresholded_descriptor( aubio_onset_t * o) {200 smpl_t aubio_onset_get_thresholded_descriptor(const aubio_onset_t * o) { 201 201 fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp); 202 202 return thresholded->data[0]; … … 204 204 205 205 /* Allocate memory for an onset detection */ 206 aubio_onset_t * new_aubio_onset (c har_t * onset_mode,206 aubio_onset_t * new_aubio_onset (const char_t * onset_mode, 207 207 uint_t buf_size, uint_t hop_size, uint_t samplerate) 208 208 { … … 213 213 AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size); 214 214 goto beach; 215 } else if ((sint_t)buf_size < 1) {216 AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", buf_size);215 } else if ((sint_t)buf_size < 2) { 216 AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size); 217 217 goto beach; 218 218 } else if (buf_size < hop_size) { 219 AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", buf_size, hop_size);219 AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", hop_size, buf_size); 220 220 goto beach; 221 221 } else if ((sint_t)samplerate < 1) { … … 232 232 o->pp = new_aubio_peakpicker(); 233 233 o->od = new_aubio_specdesc(onset_mode,buf_size); 234 if (o->od == NULL) goto beach_specdesc; 234 235 o->fftgrain = new_cvec(buf_size); 235 236 o->desc = new_fvec(1); … … 244 245 return o; 245 246 247 beach_specdesc: 248 del_aubio_peakpicker(o->pp); 249 del_aubio_pvoc(o->pv); 246 250 beach: 247 251 AUBIO_FREE(o); -
src/onset/onset.h
r00d0275 r155cc10 40 40 41 41 42 #ifndef _AUBIO_ONSET_H43 #define _AUBIO_ONSET_H42 #ifndef AUBIO_ONSET_H 43 #define AUBIO_ONSET_H 44 44 45 45 #ifdef __cplusplus … … 60 60 61 61 */ 62 aubio_onset_t * new_aubio_onset (c har_t * method,62 aubio_onset_t * new_aubio_onset (const char_t * method, 63 63 uint_t buf_size, uint_t hop_size, uint_t samplerate); 64 64 … … 89 89 90 90 */ 91 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset);91 void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset); 92 92 93 93 /** get the time of the latest onset detected, in samples … … 98 98 99 99 */ 100 uint_t aubio_onset_get_last ( aubio_onset_t *o);100 uint_t aubio_onset_get_last (const aubio_onset_t *o); 101 101 102 102 /** get the time of the latest onset detected, in seconds … … 107 107 108 108 */ 109 smpl_t aubio_onset_get_last_s ( aubio_onset_t *o);109 smpl_t aubio_onset_get_last_s (const aubio_onset_t *o); 110 110 111 111 /** get the time of the latest onset detected, in milliseconds … … 116 116 117 117 */ 118 smpl_t aubio_onset_get_last_ms ( aubio_onset_t *o);118 smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o); 119 119 120 120 /** set onset detection adaptive whitening … … 150 150 151 151 */ 152 smpl_t aubio_onset_get_silence( aubio_onset_t * o);152 smpl_t aubio_onset_get_silence(const aubio_onset_t * o); 153 153 154 154 /** get onset detection function … … 158 158 159 159 */ 160 smpl_t aubio_onset_get_descriptor ( aubio_onset_t *o);160 smpl_t aubio_onset_get_descriptor (const aubio_onset_t *o); 161 161 162 162 /** get thresholded onset detection function … … 166 166 167 167 */ 168 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);168 smpl_t aubio_onset_get_thresholded_descriptor (const aubio_onset_t *o); 169 169 170 170 /** set onset detection peak picking threshold … … 237 237 238 238 */ 239 uint_t aubio_onset_get_minioi( aubio_onset_t * o);239 uint_t aubio_onset_get_minioi(const aubio_onset_t * o); 240 240 241 241 /** get minimum inter onset interval in seconds … … 246 246 247 247 */ 248 smpl_t aubio_onset_get_minioi_s( aubio_onset_t * o);248 smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o); 249 249 250 250 /** get minimum inter onset interval in milliseconds … … 255 255 256 256 */ 257 smpl_t aubio_onset_get_minioi_ms( aubio_onset_t * o);257 smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o); 258 258 259 259 /** get delay in samples … … 264 264 265 265 */ 266 uint_t aubio_onset_get_delay( aubio_onset_t * o);266 uint_t aubio_onset_get_delay(const aubio_onset_t * o); 267 267 268 268 /** get delay in seconds … … 273 273 274 274 */ 275 smpl_t aubio_onset_get_delay_s( aubio_onset_t * o);275 smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o); 276 276 277 277 /** get delay in milliseconds … … 282 282 283 283 */ 284 smpl_t aubio_onset_get_delay_ms( aubio_onset_t * o);284 smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o); 285 285 286 286 /** get onset peak picking threshold … … 290 290 291 291 */ 292 smpl_t aubio_onset_get_threshold( aubio_onset_t * o);292 smpl_t aubio_onset_get_threshold(const aubio_onset_t * o); 293 293 294 294 /** delete onset detection object … … 303 303 #endif 304 304 305 #endif /* _AUBIO_ONSET_H */305 #endif /* AUBIO_ONSET_H */ -
src/onset/peakpicker.c
r00d0275 r155cc10 186 186 */ 187 187 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 188 -0.59488894, 0.23484048); 188 // FIXME: broken since c9e20ca, revert for now 189 //-0.59488894, 0.23484048); 190 0.23484048, 0); 189 191 190 192 return t; -
src/onset/peakpicker.h
r00d0275 r155cc10 27 27 */ 28 28 29 #ifndef _AUBIO_PEAKPICK_H30 #define _AUBIO_PEAKPICK_H29 #ifndef AUBIO_PEAKPICK_H 30 #define AUBIO_PEAKPICK_H 31 31 32 32 #ifdef __cplusplus … … 55 55 #endif 56 56 57 #endif /* _AUBIO_PEAKPICK_H */57 #endif /* AUBIO_PEAKPICK_H */ -
src/pitch/pitch.c
r00d0275 r155cc10 62 62 63 63 /** callback to get pitch candidate, defined below */ 64 typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);64 typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 65 65 66 66 /** callback to convert pitch from one unit to another, defined below */ … … 79 79 void *p_object; /**< pointer to pitch object */ 80 80 aubio_filter_t *filter; /**< filter */ 81 fvec_t *filtered; /**< filtered input */ 81 82 aubio_pvoc_t *pv; /**< phase vocoder for mcomb */ 82 83 cvec_t *fftgrain; /**< spectral frame for mcomb */ … … 89 90 90 91 /* callback functions for pitch detection */ 91 static void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);92 static void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);93 static void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);94 static void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);95 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);96 static void aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);97 98 /* conversion functions for frequency conversions*/99 s mpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);100 s mpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);101 s mpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);92 static void aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 93 static void aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 94 static void aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 95 static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 96 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 97 static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf); 98 99 /* internal functions for frequency conversion */ 100 static smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize); 101 static smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize); 102 static smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize); 102 103 103 104 /* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */ 104 void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf);105 void aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf); 105 106 106 107 107 108 aubio_pitch_t * 108 new_aubio_pitch (c har_t * pitch_mode,109 new_aubio_pitch (const char_t * pitch_mode, 109 110 uint_t bufsize, uint_t hopsize, uint_t samplerate) 110 111 { 111 112 aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t); 112 113 aubio_pitch_type pitch_type; 114 if (pitch_mode == NULL) { 115 AUBIO_ERR ("pitch: can not use ‘NULL‘ for pitch detection method\n"); 116 goto beach; 117 } 113 118 if (strcmp (pitch_mode, "mcomb") == 0) 114 119 pitch_type = aubio_pitcht_mcomb; … … 126 131 pitch_type = aubio_pitcht_default; 127 132 else { 128 AUBIO_ERR ("unknown pitch detection method %s, using default.\n", 129 pitch_mode); 130 pitch_type = aubio_pitcht_default; 133 AUBIO_ERR ("pitch: unknown pitch detection method ‘%s’\n", pitch_mode); 134 goto beach; 131 135 } 132 136 133 137 // check parameters are valid 134 138 if ((sint_t)hopsize < 1) { 135 AUBIO_ERR(" onset: got hopsize %d, but can not be < 1\n", hopsize);139 AUBIO_ERR("pitch: got hopsize %d, but can not be < 1\n", hopsize); 136 140 goto beach; 137 141 } else if ((sint_t)bufsize < 1) { 138 AUBIO_ERR(" onset: got buffer_size %d, but can not be < 1\n", bufsize);142 AUBIO_ERR("pitch: got buffer_size %d, but can not be < 1\n", bufsize); 139 143 goto beach; 140 144 } else if (bufsize < hopsize) { 141 AUBIO_ERR(" onset: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);145 AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", hopsize, bufsize); 142 146 goto beach; 143 147 } else if ((sint_t)samplerate < 1) { 144 AUBIO_ERR(" onset: samplerate (%d) can not be < 1\n", samplerate);148 AUBIO_ERR("pitch: samplerate (%d) can not be < 1\n", samplerate); 145 149 goto beach; 146 150 } … … 156 160 p->buf = new_fvec (bufsize); 157 161 p->p_object = new_aubio_pitchyin (bufsize); 162 if (!p->p_object) goto beach; 158 163 p->detect_cb = aubio_pitch_do_yin; 159 164 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence; … … 161 166 break; 162 167 case aubio_pitcht_mcomb: 168 p->filtered = new_fvec (hopsize); 163 169 p->pv = new_aubio_pvoc (bufsize, hopsize); 170 if (!p->pv) goto beach; 164 171 p->fftgrain = new_cvec (bufsize); 165 172 p->p_object = new_aubio_pitchmcomb (bufsize, hopsize); … … 170 177 p->buf = new_fvec (bufsize); 171 178 p->p_object = new_aubio_pitchfcomb (bufsize, hopsize); 179 if (!p->p_object) goto beach; 172 180 p->detect_cb = aubio_pitch_do_fcomb; 173 181 break; … … 180 188 p->buf = new_fvec (bufsize); 181 189 p->p_object = new_aubio_pitchyinfft (samplerate, bufsize); 190 if (!p->p_object) goto beach; 182 191 p->detect_cb = aubio_pitch_do_yinfft; 183 192 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence; … … 187 196 p->buf = new_fvec (bufsize); 188 197 p->p_object = new_aubio_pitchspecacf (bufsize); 198 if (!p->p_object) goto beach; 189 199 p->detect_cb = aubio_pitch_do_specacf; 190 200 p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance; … … 197 207 198 208 beach: 209 if (p->filtered) del_fvec(p->filtered); 210 if (p->buf) del_fvec(p->buf); 199 211 AUBIO_FREE(p); 200 212 return NULL; … … 210 222 break; 211 223 case aubio_pitcht_mcomb: 224 del_fvec (p->filtered); 212 225 del_aubio_pvoc (p->pv); 213 226 del_cvec (p->fftgrain); … … 238 251 239 252 void 240 aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)253 aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf) 241 254 { 242 255 uint_t overlap_size = p->buf->length - ibuf->length; … … 258 271 259 272 uint_t 260 aubio_pitch_set_unit (aubio_pitch_t * p, c har_t * pitch_unit)273 aubio_pitch_set_unit (aubio_pitch_t * p, const char_t * pitch_unit) 261 274 { 262 275 uint_t err = AUBIO_OK; … … 281 294 pitch_mode = aubio_pitchm_default; 282 295 else { 283 AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit); 296 AUBIO_WRN("pitch: unknown pitch detection unit ‘%s’, using default\n", 297 pitch_unit); 284 298 pitch_mode = aubio_pitchm_default; 285 299 err = AUBIO_FAIL; … … 322 336 } 323 337 338 smpl_t 339 aubio_pitch_get_tolerance (aubio_pitch_t * p) 340 { 341 smpl_t tolerance = 1.; 342 switch (p->type) { 343 case aubio_pitcht_yin: 344 tolerance = aubio_pitchyin_get_tolerance (p->p_object); 345 break; 346 case aubio_pitcht_yinfft: 347 tolerance = aubio_pitchyinfft_get_tolerance (p->p_object); 348 break; 349 default: 350 break; 351 } 352 return tolerance; 353 } 354 324 355 uint_t 325 356 aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence) … … 329 360 return AUBIO_OK; 330 361 } else { 331 AUBIO_ ERR("pitch: could not set silence to %.2f", silence);362 AUBIO_WRN("pitch: could not set silence to %.2f\n", silence); 332 363 return AUBIO_FAIL; 333 364 } … … 343 374 /* do method, calling the detection callback, then the conversion callback */ 344 375 void 345 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)376 aubio_pitch_do (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) 346 377 { 347 378 p->detect_cb (p, ibuf, obuf); … … 354 385 /* do method for each algorithm */ 355 386 void 356 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)357 { 358 aubio_filter_do (p->filter, ibuf);387 aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) 388 { 389 aubio_filter_do_outplace (p->filter, ibuf, p->filtered); 359 390 aubio_pvoc_do (p->pv, ibuf, p->fftgrain); 360 391 aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf); … … 363 394 364 395 void 365 aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)396 aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) 366 397 { 367 398 smpl_t pitch = 0.; … … 379 410 380 411 void 381 aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)412 aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) 382 413 { 383 414 smpl_t pitch = 0.; … … 394 425 395 426 void 396 aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)427 aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out) 397 428 { 398 429 smpl_t pitch = 0., period; … … 410 441 411 442 void 412 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)443 aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out) 413 444 { 414 445 aubio_pitch_slideblock (p, ibuf); … … 418 449 419 450 void 420 aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)451 aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out) 421 452 { 422 453 smpl_t period, pitch = 0.; -
src/pitch/pitch.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_PITCH_H22 #define _AUBIO_PITCH_H21 #ifndef AUBIO_PITCH_H 22 #define AUBIO_PITCH_H 23 23 24 24 #ifdef __cplusplus … … 108 108 109 109 */ 110 void aubio_pitch_do (aubio_pitch_t * o, fvec_t * in, fvec_t * out);110 void aubio_pitch_do (aubio_pitch_t * o, const fvec_t * in, fvec_t * out); 111 111 112 112 /** change yin or yinfft tolerance threshold … … 117 117 */ 118 118 uint_t aubio_pitch_set_tolerance (aubio_pitch_t * o, smpl_t tol); 119 120 /** get yin or yinfft tolerance threshold 121 122 \param o pitch detection object as returned by new_aubio_pitch() 123 \return tolerance (default is 0.15 for yin and 0.85 for yinfft) 124 125 */ 126 smpl_t aubio_pitch_get_tolerance (aubio_pitch_t * o); 119 127 120 128 /** deletion of the pitch detection object … … 135 143 136 144 */ 137 aubio_pitch_t *new_aubio_pitch (c har_t * method,145 aubio_pitch_t *new_aubio_pitch (const char_t * method, 138 146 uint_t buf_size, uint_t hop_size, uint_t samplerate); 139 147 … … 143 151 \param mode set pitch units for output 144 152 153 mode can be one of "Hz", "midi", "cent", or "bin". Defaults to "Hz". 154 145 155 \return 0 if successfull, non-zero otherwise 146 156 147 157 */ 148 uint_t aubio_pitch_set_unit (aubio_pitch_t * o, c har_t * mode);158 uint_t aubio_pitch_set_unit (aubio_pitch_t * o, const char_t * mode); 149 159 150 160 /** set the silence threshold of the pitch detection object … … 180 190 #endif 181 191 182 #endif /* _AUBIO_PITCH_H */192 #endif /* AUBIO_PITCH_H */ -
src/pitch/pitchfcomb.c
r00d0275 r155cc10 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 64 69 /* input must be stepsize long */ 65 70 void 66 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)71 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output) 67 72 { 68 73 uint_t k, l, maxharm = 0; -
src/pitch/pitchfcomb.h
r00d0275 r155cc10 35 35 */ 36 36 37 #ifndef _AUBIO_PITCHFCOMB_H38 #define _AUBIO_PITCHFCOMB_H37 #ifndef AUBIO_PITCHFCOMB_H 38 #define AUBIO_PITCHFCOMB_H 39 39 40 40 #ifdef __cplusplus … … 52 52 53 53 */ 54 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input,54 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, 55 55 fvec_t * output); 56 56 … … 74 74 #endif 75 75 76 #endif /* _AUBIO_PITCHFCOMB_H */76 #endif /* AUBIO_PITCHFCOMB_H */ -
src/pitch/pitchmcomb.c
r00d0275 r155cc10 32 32 uint_t length); 33 33 uint_t aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, 34 fvec_t * X);35 void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * oldmag);36 void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag);34 const fvec_t * X); 35 void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * oldmag); 36 void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag); 37 37 /* not used but useful : sort by amplitudes (or anything else) 38 38 * sort_pitchpeak(peaks, length); … … 43 43 void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins); 44 44 /** select the best candidates */ 45 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, c vec_t * fftgrain,45 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, 46 46 smpl_t * cands); 47 47 … … 102 102 103 103 void 104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, c vec_t * fftgrain, fvec_t * output)104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, fvec_t * output) 105 105 { 106 106 uint_t j; … … 135 135 136 136 uint_t 137 aubio_pitch_cands (aubio_pitchmcomb_t * p, c vec_t * fftgrain, smpl_t * cands)137 aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, smpl_t * cands) 138 138 { 139 139 uint_t j; … … 166 166 167 167 void 168 aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * newmag)168 aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * newmag) 169 169 { 170 170 fvec_t *mag = (fvec_t *) p->scratch; … … 198 198 199 199 void 200 aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag)200 aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag) 201 201 { 202 202 aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks; … … 286 286 */ 287 287 uint_t 288 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)288 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, const fvec_t * X) 289 289 { 290 290 uint_t j, ispeak, count = 0; … … 365 365 uint_t i, j; 366 366 uint_t spec_size; 367 p->spec_partition = 4;367 p->spec_partition = 2; 368 368 p->ncand = 5; 369 369 p->npartials = 5; … … 377 377 p->phasefreq = bufsize / hopsize / TWO_PI; 378 378 p->phasediff = TWO_PI * hopsize / bufsize; 379 spec_size = bufsize / p->spec_partition ;379 spec_size = bufsize / p->spec_partition + 1; 380 380 //p->pickerfn = quadpick; 381 381 //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348); -
src/pitch/pitchmcomb.h
r00d0275 r155cc10 36 36 */ 37 37 38 #ifndef _AUBIO_PITCHMCOMB_H39 #define _AUBIO_PITCHMCOMB_H38 #ifndef AUBIO_PITCHMCOMB_H 39 #define AUBIO_PITCHMCOMB_H 40 40 41 41 #ifdef __cplusplus … … 53 53 54 54 */ 55 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, c vec_t * in_fftgrain,55 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * in_fftgrain, 56 56 fvec_t * out_cands); 57 57 … … 75 75 #endif 76 76 77 #endif /* _AUBIO_PITCHMCOMB_H */77 #endif /* AUBIO_PITCHMCOMB_H */ -
src/pitch/pitchschmitt.c
r00d0275 r155cc10 48 48 49 49 void 50 aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * input,50 aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * input, 51 51 fvec_t * output) 52 52 { -
src/pitch/pitchschmitt.h
r00d0275 r155cc10 35 35 */ 36 36 37 #ifndef _AUBIO_PITCHSCHMITT_H38 #define _AUBIO_PITCHSCHMITT_H37 #ifndef AUBIO_PITCHSCHMITT_H 38 #define AUBIO_PITCHSCHMITT_H 39 39 40 40 #ifdef __cplusplus … … 52 52 53 53 */ 54 void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * samples_in,54 void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * samples_in, 55 55 fvec_t * cands_out); 56 56 … … 73 73 #endif 74 74 75 #endif /* _AUBIO_PITCHSCHMITT_H */ 76 75 #endif /* AUBIO_PITCHSCHMITT_H */ -
src/pitch/pitchspecacf.c
r00d0275 r155cc10 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 56 61 void 57 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)62 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, const fvec_t * input, fvec_t * output) 58 63 { 59 64 uint_t l, tau; … … 92 97 93 98 smpl_t 94 aubio_pitchspecacf_get_confidence ( aubio_pitchspecacf_t * o) {99 aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o) { 95 100 // no confidence for now 96 101 return o->confidence; … … 105 110 106 111 smpl_t 107 aubio_pitchspecacf_get_tolerance ( aubio_pitchspecacf_t * p)112 aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * p) 108 113 { 109 114 return p->tol; -
src/pitch/pitchspecacf.h
r00d0275 r155cc10 39 39 */ 40 40 41 #ifndef _AUBIO_PITCHSPECACF_H42 #define _AUBIO_PITCHSPECACF_H41 #ifndef AUBIO_PITCHSPECACF_H 42 #define AUBIO_PITCHSPECACF_H 43 43 44 44 #ifdef __cplusplus … … 56 56 57 57 */ 58 void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, fvec_t * samples_in, fvec_t * cands_out);58 void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, const fvec_t * samples_in, fvec_t * cands_out); 59 59 /** creation of the pitch detection object 60 60 … … 77 77 78 78 */ 79 smpl_t aubio_pitchspecacf_get_tolerance ( aubio_pitchspecacf_t * o);79 smpl_t aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * o); 80 80 81 81 /** set tolerance parameter for `specacf` pitch detection object … … 95 95 96 96 */ 97 smpl_t aubio_pitchspecacf_get_confidence ( aubio_pitchspecacf_t * o);97 smpl_t aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o); 98 98 99 99 #ifdef __cplusplus … … 101 101 #endif 102 102 103 #endif /* _AUBIO_PITCHSPECACF_H */103 #endif /* AUBIO_PITCHSPECACF_H */ -
src/pitch/pitchyin.c
r00d0275 r155cc10 41 41 42 42 /** compute difference function 43 44 \param input input signal 43 44 \param input input signal 45 45 \param yinbuf output buffer to store difference function (half shorter than input) 46 46 … … 48 48 void aubio_pitchyin_diff (fvec_t * input, fvec_t * yinbuf); 49 49 50 /** in place computation of the YIN cumulative normalised function 51 52 \param yinbuf input signal (a square difference function), also used to store function 50 /** in place computation of the YIN cumulative normalised function 51 52 \param yinbuf input signal (a square difference function), also used to store function 53 53 54 54 */ … … 56 56 57 57 /** detect pitch in a YIN function 58 58 59 59 \param yinbuf input buffer as computed by aubio_pitchyin_getcum 60 60 61 61 */ 62 uint_t aubio_pitchyin_getpitch ( fvec_t * yinbuf);62 uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf); 63 63 64 64 aubio_pitchyin_t * … … 112 112 113 113 uint_t 114 aubio_pitchyin_getpitch ( fvec_t * yin)114 aubio_pitchyin_getpitch (const fvec_t * yin) 115 115 { 116 116 uint_t tau = 1; … … 128 128 } 129 129 130 131 130 /* all the above in one */ 132 131 void 133 aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * input, fvec_t * out)132 aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out) 134 133 { 135 smpl_t tol = o->tol; 136 fvec_t *yin = o->yin; 137 uint_t j, tau = 0; 134 const smpl_t tol = o->tol; 135 fvec_t* yin = o->yin; 136 const smpl_t *input_data = input->data; 137 const uint_t length = yin->length; 138 smpl_t *yin_data = yin->data; 139 uint_t j, tau; 138 140 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); 141 smpl_t tmp, tmp2 = 0.; 142 143 yin_data[0] = 1.; 144 for (tau = 1; tau < length; tau++) { 145 yin_data[tau] = 0.; 146 for (j = 0; j < length; j++) { 147 tmp = input_data[j] - input_data[j + tau]; 148 yin_data[tau] += SQR (tmp); 146 149 } 147 tmp2 += yin ->data[tau];150 tmp2 += yin_data[tau]; 148 151 if (tmp2 != 0) { 149 152 yin->data[tau] *= tau / tmp2; … … 152 155 } 153 156 period = tau - 3; 154 if (tau > 4 && (yin ->data[period] < tol) &&155 (yin ->data[period] < yin->data[period + 1])) {157 if (tau > 4 && (yin_data[period] < tol) && 158 (yin_data[period] < yin_data[period + 1])) { 156 159 out->data[0] = fvec_quadratic_peak_pos (yin, period); 157 160 goto beach; -
src/pitch/pitchyin.h
r00d0275 r155cc10 36 36 */ 37 37 38 #ifndef _AUBIO_PITCHYIN_H39 #define _AUBIO_PITCHYIN_H38 #ifndef AUBIO_PITCHYIN_H 39 #define AUBIO_PITCHYIN_H 40 40 41 41 #ifdef __cplusplus … … 67 67 68 68 */ 69 void aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * samples_in, fvec_t * cands_out);69 void aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * samples_in, fvec_t * cands_out); 70 70 71 71 … … 98 98 #endif 99 99 100 #endif /* _AUBIO_PITCHYIN_H */100 #endif /* AUBIO_PITCHYIN_H */ -
src/pitch/pitchyinfft.c
r00d0275 r155cc10 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); … … 96 97 p->short_period = (uint_t)ROUND(samplerate / 1300.); 97 98 return p; 99 100 beach: 101 if (p->winput) del_fvec(p->winput); 102 AUBIO_FREE(p); 103 return NULL; 98 104 } 99 105 100 106 void 101 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)107 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, const fvec_t * input, fvec_t * output) 102 108 { 103 109 uint_t tau, l; -
src/pitch/pitchyinfft.h
r00d0275 r155cc10 36 36 */ 37 37 38 #ifndef _AUBIO_PITCHYINFFT_H39 #define _AUBIO_PITCHYINFFT_H38 #ifndef AUBIO_PITCHYINFFT_H 39 #define AUBIO_PITCHYINFFT_H 40 40 41 41 #ifdef __cplusplus … … 53 53 54 54 */ 55 void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, fvec_t * samples_in, fvec_t * cands_out);55 void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, const fvec_t * samples_in, fvec_t * cands_out); 56 56 /** creation of the pitch detection object 57 57 … … 97 97 #endif 98 98 99 #endif /* _AUBIO_PITCHYINFFT_H */99 #endif /* AUBIO_PITCHYINFFT_H */ -
src/spectral/fft.c
r00d0275 r155cc10 65 65 #ifdef HAVE_FFTW3F 66 66 #if HAVE_AUBIO_DOUBLE 67 # warning"Using aubio in double precision with fftw3 in single precision"67 #error "Using aubio in double precision with fftw3 in single precision" 68 68 #endif /* HAVE_AUBIO_DOUBLE */ 69 69 #define real_t float 70 #el se/* HAVE_FFTW3F */70 #elif defined (HAVE_FFTW3) /* HAVE_FFTW3F */ 71 71 #if !HAVE_AUBIO_DOUBLE 72 # warning"Using aubio in single precision with fftw3 in double precision"72 #error "Using aubio in single precision with fftw3 in double precision" 73 73 #endif /* HAVE_AUBIO_DOUBLE */ 74 74 #define real_t double … … 115 115 #else // using OOURA 116 116 // let's use ooura instead 117 extern void rdft(int, int, smpl_t *, int *, smpl_t *);117 extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *); 118 118 119 119 #endif /* HAVE_ACCELERATE */ … … 144 144 aubio_fft_t * new_aubio_fft (uint_t winsize) { 145 145 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 146 if ((sint_t)winsize < 1) {147 AUBIO_ERR("fft: got winsize %d, but can not be < 1\n", winsize);146 if ((sint_t)winsize < 2) { 147 AUBIO_ERR("fft: got winsize %d, but can not be < 2\n", winsize); 148 148 goto beach; 149 149 } … … 189 189 #else // using OOURA 190 190 if (aubio_is_power_of_two(winsize) != 1) { 191 AUBIO_ERR("fft: can only create with sizes power of two, "192 " requested %d\n", winsize);191 AUBIO_ERR("fft: can only create with sizes power of two, requested %d," 192 " try recompiling aubio with --enable-fftw3\n", winsize); 193 193 goto beach; 194 194 } … … 213 213 del_fvec(s->compspec); 214 214 #ifdef HAVE_FFTW3 // using FFTW3 215 pthread_mutex_lock(&aubio_fftw_mutex); 215 216 fftw_destroy_plan(s->pfw); 216 217 fftw_destroy_plan(s->pbw); 217 218 fftw_free(s->specdata); 219 pthread_mutex_unlock(&aubio_fftw_mutex); 218 220 #else /* HAVE_FFTW3 */ 219 221 #ifdef HAVE_ACCELERATE // using ACCELERATE … … 231 233 } 232 234 233 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {235 void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) { 234 236 aubio_fft_do_complex(s, input, s->compspec); 235 237 aubio_fft_get_spectrum(s->compspec, spectrum); 236 238 } 237 239 238 void aubio_fft_rdo(aubio_fft_t * s, c vec_t * spectrum, fvec_t * output) {240 void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) { 239 241 aubio_fft_get_realimag(spectrum, s->compspec); 240 242 aubio_fft_rdo_complex(s, s->compspec, output); 241 243 } 242 244 243 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {245 void aubio_fft_do_complex(aubio_fft_t * s, const fvec_t * input, fvec_t * compspec) { 244 246 uint_t i; 245 247 #ifndef HAVE_MEMCPY_HACKS … … 281 283 aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size); 282 284 #else // using OOURA 283 rdft(s->winsize, 1, s->in, s->ip, s->w);285 aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w); 284 286 compspec->data[0] = s->in[0]; 285 287 compspec->data[s->winsize / 2] = s->in[1]; … … 292 294 } 293 295 294 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {296 void aubio_fft_rdo_complex(aubio_fft_t * s, const fvec_t * compspec, fvec_t * output) { 295 297 uint_t i; 296 298 #ifdef HAVE_FFTW3 … … 339 341 s->out[2 * i + 1] = - compspec->data[s->winsize - i]; 340 342 } 341 rdft(s->winsize, -1, s->out, s->ip, s->w);343 aubio_ooura_rdft(s->winsize, -1, s->out, s->ip, s->w); 342 344 for (i=0; i < s->winsize; i++) { 343 345 output->data[i] = s->out[i] * scale; … … 347 349 } 348 350 349 void aubio_fft_get_spectrum( fvec_t * compspec, cvec_t * spectrum) {351 void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) { 350 352 aubio_fft_get_phas(compspec, spectrum); 351 353 aubio_fft_get_norm(compspec, spectrum); 352 354 } 353 355 354 void aubio_fft_get_realimag(c vec_t * spectrum, fvec_t * compspec) {356 void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) { 355 357 aubio_fft_get_imag(spectrum, compspec); 356 358 aubio_fft_get_real(spectrum, compspec); 357 359 } 358 360 359 void aubio_fft_get_phas( fvec_t * compspec, cvec_t * spectrum) {361 void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) { 360 362 uint_t i; 361 363 if (compspec->data[0] < 0) { … … 375 377 } 376 378 377 void aubio_fft_get_norm( fvec_t * compspec, cvec_t * spectrum) {379 void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) { 378 380 uint_t i = 0; 379 381 spectrum->norm[0] = ABS(compspec->data[0]); … … 386 388 } 387 389 388 void aubio_fft_get_imag(c vec_t * spectrum, fvec_t * compspec) {390 void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) { 389 391 uint_t i; 390 392 for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) { … … 394 396 } 395 397 396 void aubio_fft_get_real(c vec_t * spectrum, fvec_t * compspec) {398 void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) { 397 399 uint_t i; 398 400 for (i = 0; i < compspec->length / 2 + 1; i++) { -
src/spectral/fft.h
r00d0275 r155cc10 28 28 - [vDSP](https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html) 29 29 30 \example s rc/spectral/test-fft.c30 \example spectral/test-fft.c 31 31 32 32 */ 33 33 34 #ifndef _AUBIO_FFT_H35 #define _AUBIO_FFT_H34 #ifndef AUBIO_FFT_H 35 #define AUBIO_FFT_H 36 36 37 37 #ifdef __cplusplus … … 66 66 67 67 */ 68 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);68 void aubio_fft_do (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum); 69 69 /** compute backward (inverse) FFT 70 70 … … 74 74 75 75 */ 76 void aubio_fft_rdo (aubio_fft_t *s, c vec_t * spectrum, fvec_t * output);76 void aubio_fft_rdo (aubio_fft_t *s, const cvec_t * spectrum, fvec_t * output); 77 77 78 78 /** compute forward FFT … … 83 83 84 84 */ 85 void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);85 void aubio_fft_do_complex (aubio_fft_t *s, const fvec_t * input, fvec_t * compspec); 86 86 /** compute backward (inverse) FFT from real/imag 87 87 … … 91 91 92 92 */ 93 void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);93 void aubio_fft_rdo_complex (aubio_fft_t *s, const fvec_t * compspec, fvec_t * output); 94 94 95 95 /** convert real/imag spectrum to norm/phas spectrum … … 99 99 100 100 */ 101 void aubio_fft_get_spectrum( fvec_t * compspec, cvec_t * spectrum);101 void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum); 102 102 /** convert real/imag spectrum to norm/phas spectrum 103 103 … … 106 106 107 107 */ 108 void aubio_fft_get_realimag(c vec_t * spectrum, fvec_t * compspec);108 void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec); 109 109 110 110 /** compute phas spectrum from real/imag parts … … 114 114 115 115 */ 116 void aubio_fft_get_phas( fvec_t * compspec, cvec_t * spectrum);116 void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum); 117 117 /** compute imaginary part from the norm/phas cvec 118 118 … … 121 121 122 122 */ 123 void aubio_fft_get_imag(c vec_t * spectrum, fvec_t * compspec);123 void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec); 124 124 125 125 /** compute norm component from real/imag parts … … 129 129 130 130 */ 131 void aubio_fft_get_norm( fvec_t * compspec, cvec_t * spectrum);131 void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum); 132 132 /** compute real part from norm/phas components 133 133 … … 136 136 137 137 */ 138 void aubio_fft_get_real(c vec_t * spectrum, fvec_t * compspec);138 void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec); 139 139 140 140 #ifdef __cplusplus … … 142 142 #endif 143 143 144 #endif /* _AUBIO_FFT_H */144 #endif /* AUBIO_FFT_H */ -
src/spectral/filterbank.c
r00d0275 r155cc10 57 57 58 58 void 59 aubio_filterbank_do (aubio_filterbank_t * f, c vec_t * in, fvec_t * out)59 aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out) 60 60 { 61 uint_t j, fn; 61 /* apply filter to all input channel, provided out has enough channels */ 62 //uint_t max_filters = MIN (f->n_filters, out->length); 63 //uint_t max_length = MIN (in->length, f->filters->length); 62 64 63 /* apply filter to all input channel, provided out has enough channels */ 64 uint_t max_filters = MIN (f->n_filters, out->length); 65 uint_t max_length = MIN (in->length, f->filters->length); 65 // view cvec->norm as fvec->data 66 fvec_t tmp; 67 tmp.length = in->length; 68 tmp.data = in->norm; 66 69 67 /* reset all values in output vector */ 68 fvec_zeros (out); 69 70 /* for each filter */ 71 for (fn = 0; fn < max_filters; fn++) { 72 /* for each sample */ 73 for (j = 0; j < max_length; j++) { 74 out->data[fn] += in->norm[j] * f->filters->data[fn][j]; 75 } 76 } 70 fmat_vecmul(f->filters, &tmp, out); 77 71 78 72 return; … … 80 74 81 75 fmat_t * 82 aubio_filterbank_get_coeffs ( aubio_filterbank_t * f)76 aubio_filterbank_get_coeffs (const aubio_filterbank_t * f) 83 77 { 84 78 return f->filters; … … 86 80 87 81 uint_t 88 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)82 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filter_coeffs) 89 83 { 90 84 fmat_copy(filter_coeffs, f->filters); -
src/spectral/filterbank.h
r00d0275 r155cc10 30 30 */ 31 31 32 #ifndef _AUBIO_FILTERBANK_H33 #define _AUBIO_FILTERBANK_H32 #ifndef AUBIO_FILTERBANK_H 33 #define AUBIO_FILTERBANK_H 34 34 35 35 #ifdef __cplusplus … … 67 67 68 68 */ 69 void aubio_filterbank_do (aubio_filterbank_t * f, c vec_t * in, fvec_t * out);69 void aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out); 70 70 71 71 /** return a pointer to the matrix object containing all filter coefficients … … 74 74 75 75 */ 76 fmat_t *aubio_filterbank_get_coeffs ( aubio_filterbank_t * f);76 fmat_t *aubio_filterbank_get_coeffs (const aubio_filterbank_t * f); 77 77 78 78 /** copy filter coefficients to the filterbank … … 82 82 83 83 */ 84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters); 85 85 86 86 #ifdef __cplusplus … … 88 88 #endif 89 89 90 #endif /* _AUBIO_FILTERBANK_H */90 #endif /* AUBIO_FILTERBANK_H */ -
src/spectral/filterbank_mel.c
r00d0275 r155cc10 30 30 uint_t 31 31 aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 32 fvec_t * freqs, smpl_t samplerate)32 const fvec_t * freqs, smpl_t samplerate) 33 33 { 34 34 -
src/spectral/filterbank_mel.h
r00d0275 r155cc10 32 32 */ 33 33 34 #ifndef _AUBIO_FILTERBANK_MEL_H35 #define _AUBIO_FILTERBANK_MEL_H34 #ifndef AUBIO_FILTERBANK_MEL_H 35 #define AUBIO_FILTERBANK_MEL_H 36 36 37 37 #ifdef __cplusplus … … 51 51 */ 52 52 uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 53 fvec_t * freqs, smpl_t samplerate);53 const fvec_t * freqs, smpl_t samplerate); 54 54 55 55 /** filterbank initialization for Mel filters using Slaney's coefficients … … 70 70 #endif 71 71 72 #endif /* _AUBIO_FILTERBANK_MEL_H */72 #endif /* AUBIO_FILTERBANK_MEL_H */ -
src/spectral/mfcc.c
r00d0275 r155cc10 68 68 mfcc->in_dct = new_fvec (n_filters); 69 69 70 mfcc->dct_coeffs = new_fmat (n_ filters, n_coefs);70 mfcc->dct_coeffs = new_fmat (n_coefs, n_filters); 71 71 72 /* compute DCT transform dct_coeffs[ i][j] as72 /* compute DCT transform dct_coeffs[j][i] as 73 73 cos ( j * (i+.5) * PI / n_filters ) */ 74 74 scaling = 1. / SQRT (n_filters / 2.); 75 75 for (i = 0; i < n_filters; i++) { 76 76 for (j = 0; j < n_coefs; j++) { 77 mfcc->dct_coeffs->data[ i][j] =77 mfcc->dct_coeffs->data[j][i] = 78 78 scaling * COS (j * (i + 0.5) * PI / n_filters); 79 79 } 80 mfcc->dct_coeffs->data[ i][0] *= SQRT (2.) / 2.;80 mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.; 81 81 } 82 82 83 83 return mfcc; 84 } ;84 } 85 85 86 86 void … … 101 101 102 102 void 103 aubio_mfcc_do (aubio_mfcc_t * mf, c vec_t * in, fvec_t * out)103 aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out) 104 104 { 105 uint_t j, k;106 107 105 /* compute filterbank */ 108 106 aubio_filterbank_do (mf->fb, in, mf->in_dct); … … 114 112 //fvec_pow (mf->in_dct, 3.); 115 113 116 /* zeros output */ 117 fvec_zeros(out); 118 119 /* compute discrete cosine transform */ 120 for (j = 0; j < mf->n_filters; j++) { 121 for (k = 0; k < mf->n_coefs; k++) { 122 out->data[k] += mf->in_dct->data[j] 123 * mf->dct_coeffs->data[j][k]; 124 } 125 } 114 /* compute mfccs */ 115 fmat_vecmul(mf->dct_coeffs, mf->in_dct, out); 126 116 127 117 return; -
src/spectral/mfcc.h
r00d0275 r155cc10 35 35 */ 36 36 37 #ifndef _AUBIO_MFCC_H38 #define _AUBIO_MFCC_H37 #ifndef AUBIO_MFCC_H 38 #define AUBIO_MFCC_H 39 39 40 40 #ifdef __cplusplus … … 71 71 72 72 */ 73 void aubio_mfcc_do (aubio_mfcc_t * mf, c vec_t * in, fvec_t * out);73 void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out); 74 74 75 75 #ifdef __cplusplus … … 77 77 #endif 78 78 79 #endif /* _AUBIO_MFCC_H */79 #endif /* AUBIO_MFCC_H */ -
src/spectral/ooura_fft8g.c
r00d0275 r155cc10 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 7 // - declare initialization as static 8 // - prefix public function with aubio_ooura_ 6 9 7 10 #include "aubio_priv.h" 8 11 9 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);10 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);11 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);12 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);13 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);14 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);15 void makewt(int nw, int *ip, smpl_t *w);16 void makect(int nc, int *ip, smpl_t *c);17 void bitrv2(int n, int *ip, smpl_t *a);18 void bitrv2conj(int n, int *ip, smpl_t *a);19 void cftfsub(int n, smpl_t *a, smpl_t *w);20 void cftbsub(int n, smpl_t *a, smpl_t *w);21 void cft1st(int n, smpl_t *a, smpl_t *w);22 void cftmdl(int n, int l, smpl_t *a, smpl_t *w);23 void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);24 void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);25 void dctsub(int n, smpl_t *a, int nc, smpl_t *c);26 void dstsub(int n, smpl_t *a, int nc, smpl_t *c);12 void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 13 void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 14 void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 15 void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 16 void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w); 17 void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w); 18 static void makewt(int nw, int *ip, smpl_t *w); 19 static void makect(int nc, int *ip, smpl_t *c); 20 static void bitrv2(int n, int *ip, smpl_t *a); 21 static void bitrv2conj(int n, int *ip, smpl_t *a); 22 static void cftfsub(int n, smpl_t *a, smpl_t *w); 23 static void cftbsub(int n, smpl_t *a, smpl_t *w); 24 static void cft1st(int n, smpl_t *a, smpl_t *w); 25 static void cftmdl(int n, int l, smpl_t *a, smpl_t *w); 26 static void rftfsub(int n, smpl_t *a, int nc, smpl_t *c); 27 static void rftbsub(int n, smpl_t *a, int nc, smpl_t *c); 28 static void dctsub(int n, smpl_t *a, int nc, smpl_t *c); 29 static void dstsub(int n, smpl_t *a, int nc, smpl_t *c); 27 30 28 31 /* … … 303 306 304 307 305 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)308 void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 306 309 { 307 310 void makewt(int nw, int *ip, smpl_t *w); … … 328 331 329 332 330 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)333 void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 331 334 { 332 335 void makewt(int nw, int *ip, smpl_t *w); … … 362 365 a[1] = xi; 363 366 } else { 364 a[1] = 0.5 * (a[0] - a[1]);367 a[1] = (smpl_t)0.5 * (a[0] - a[1]); 365 368 a[0] -= a[1]; 366 369 if (n > 4) { … … 375 378 376 379 377 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)380 void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 378 381 { 379 382 void makewt(int nw, int *ip, smpl_t *w); … … 434 437 435 438 436 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)439 void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 437 440 { 438 441 void makewt(int nw, int *ip, smpl_t *w); … … 493 496 494 497 495 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)498 void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w) 496 499 { 497 500 void makewt(int nw, int *ip, smpl_t *w); … … 589 592 590 593 591 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)594 void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w) 592 595 { 593 596 void makewt(int nw, int *ip, smpl_t *w); … … 691 694 if (nw > 2) { 692 695 nwh = nw >> 1; 693 delta = atan(1.0) / nwh;696 delta = ATAN(1.0) / nwh; 694 697 w[0] = 1; 695 698 w[1] = 0; … … 725 728 if (nc > 1) { 726 729 nch = nc >> 1; 727 delta = atan(1.0) / nch;728 c[0] = cos(delta * nch);729 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]; 730 733 for (j = 1; j < nch; j++) { 731 c[j] = 0.5 * cos(delta * j);732 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); 733 736 } 734 737 } … … 1586 1589 k = n - j; 1587 1590 kk += ks; 1588 wkr = 0.5 - c[nc - kk];1591 wkr = (smpl_t)0.5 - c[nc - kk]; 1589 1592 wki = c[kk]; 1590 1593 xr = a[j] - a[k]; … … 1612 1615 k = n - j; 1613 1616 kk += ks; 1614 wkr = 0.5 - c[nc - kk];1617 wkr = (smpl_t)0.5 - c[nc - kk]; 1615 1618 wki = c[kk]; 1616 1619 xr = a[j] - a[k]; -
src/spectral/phasevoc.c
r00d0275 r155cc10 45 45 46 46 /** returns data and dataold slided by hop_s */ 47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new);47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new); 48 48 49 49 /** do additive synthesis from 'old' and 'cur' */ 50 50 static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew); 51 51 52 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {52 void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) { 53 53 /* slide */ 54 54 aubio_pvoc_swapbuffers(pv, datanew); … … 65 65 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 66 66 /* unshift */ 67 fvec_shift(pv->synth); 67 fvec_ishift(pv->synth); 68 /* windowing */ 69 // if overlap = 50%, do not apply window (identity) 70 if (pv->hop_s * 2 < pv->win_s) { 71 fvec_weight(pv->synth, pv->w); 72 } 68 73 /* additive synthesis */ 69 74 aubio_pvoc_addsynth(pv, synthnew); … … 80 85 AUBIO_ERR("pvoc: got hop_size %d, but can not be < 1\n", hop_s); 81 86 goto beach; 82 } else if ((sint_t)win_s < 1) {83 AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 1\n", win_s);87 } else if ((sint_t)win_s < 2) { 88 AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 2\n", win_s); 84 89 goto beach; 85 90 } else if (win_s < hop_s) { 86 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); 87 92 goto beach; 88 93 } 89 94 90 95 pv->fft = new_aubio_fft (win_s); 96 if (pv->fft == NULL) { 97 goto beach; 98 } 91 99 92 100 /* remember old */ … … 118 126 pv->hop_datasize = pv->hop_s * sizeof(smpl_t); 119 127 120 pv->scale = pv->hop_s * 2. / pv->win_s; 128 // for reconstruction with 75% overlap 129 if (win_s == hop_s * 4) { 130 pv->scale = 2./3.; 131 } else if (win_s == hop_s * 8) { 132 pv->scale = 1./3.; 133 } else if (win_s == hop_s * 2) { 134 pv->scale = 1.; 135 } else { 136 pv->scale = .5; 137 } 121 138 122 139 return pv; … … 137 154 } 138 155 139 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new)156 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new) 140 157 { 141 158 /* some convenience pointers */ … … 143 160 smpl_t * dataold = pv->dataold->data; 144 161 smpl_t * datanew = new->data; 145 #if !HAVE_MEMCPY_HACKS162 #ifndef HAVE_MEMCPY_HACKS 146 163 uint_t i; 147 164 for (i = 0; i < pv->end; i++) -
src/spectral/phasevoc.h
r00d0275 r155cc10 32 32 */ 33 33 34 #ifndef _AUBIO_PHASEVOC_H35 #define _AUBIO_PHASEVOC_H34 #ifndef AUBIO_PHASEVOC_H 35 #define AUBIO_PHASEVOC_H 36 36 37 37 #ifdef __cplusplus … … 68 68 69 69 */ 70 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain);70 void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain); 71 71 /** compute signal from spectral frame 72 72 … … 100 100 #endif 101 101 102 #endif /* _AUBIO_PHASEVOC_H */102 #endif /* AUBIO_PHASEVOC_H */ -
src/spectral/specdesc.c
r00d0275 r155cc10 27 27 #include "utils/hist.h" 28 28 29 void aubio_specdesc_energy(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);30 void aubio_specdesc_hfc(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);31 void aubio_specdesc_complex(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);32 void aubio_specdesc_phase(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);34 void aubio_specdesc_kl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);35 void aubio_specdesc_mkl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);36 void aubio_specdesc_specflux(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);37 38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, c vec_t * spec,39 fvec_t * desc); 40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, c vec_t * spec,41 fvec_t * desc); 42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, c vec_t * spec,43 fvec_t * desc); 44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, c vec_t * spec,45 fvec_t * desc); 46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, c vec_t * spec,47 fvec_t * desc); 48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, c vec_t * spec,49 fvec_t * desc); 50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, c vec_t * spec,29 void aubio_specdesc_energy(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 30 void aubio_specdesc_hfc(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 31 void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 32 void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 34 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 35 void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 36 void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 37 38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec, 39 fvec_t * desc); 40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec, 41 fvec_t * desc); 42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec, 43 fvec_t * desc); 44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec, 45 fvec_t * desc); 46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec, 47 fvec_t * desc); 48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec, 49 fvec_t * desc); 50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec, 51 51 fvec_t * desc); 52 52 … … 76 76 /** Pointer to aubio_specdesc_<type> function */ 77 77 void (*funcpointer)(aubio_specdesc_t *o, 78 c vec_t * fftgrain, fvec_t * onset);78 const cvec_t * fftgrain, fvec_t * onset); 79 79 smpl_t threshold; /**< minimum norm threshold for phase and specdiff */ 80 80 fvec_t *oldmag; /**< previous norm vector */ … … 88 88 /* Energy based onset detection function */ 89 89 void aubio_specdesc_energy (aubio_specdesc_t *o UNUSED, 90 c vec_t * fftgrain, fvec_t * onset) {90 const cvec_t * fftgrain, fvec_t * onset) { 91 91 uint_t j; 92 92 onset->data[0] = 0.; … … 98 98 /* High Frequency Content onset detection function */ 99 99 void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED, 100 c vec_t * fftgrain, fvec_t * onset){100 const cvec_t * fftgrain, fvec_t * onset){ 101 101 uint_t j; 102 102 onset->data[0] = 0.; … … 108 108 109 109 /* Complex Domain Method onset detection function */ 110 void aubio_specdesc_complex (aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset) {110 void aubio_specdesc_complex (aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset) { 111 111 uint_t j; 112 112 uint_t nbins = fftgrain->length; … … 132 132 /* Phase Based Method onset detection function */ 133 133 void aubio_specdesc_phase(aubio_specdesc_t *o, 134 c vec_t * fftgrain, fvec_t * onset){134 const cvec_t * fftgrain, fvec_t * onset){ 135 135 uint_t j; 136 136 uint_t nbins = fftgrain->length; … … 162 162 /* Spectral difference method onset detection function */ 163 163 void aubio_specdesc_specdiff(aubio_specdesc_t *o, 164 c vec_t * fftgrain, fvec_t * onset){164 const cvec_t * fftgrain, fvec_t * onset){ 165 165 uint_t j; 166 166 uint_t nbins = fftgrain->length; … … 189 189 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid 190 190 * negative (1.+) and infinite values (+1.e-10) */ 191 void aubio_specdesc_kl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){191 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 192 192 uint_t j; 193 193 onset->data[0] = 0.; … … 203 203 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid 204 204 * negative (1.+) and infinite values (+1.e-10) */ 205 void aubio_specdesc_mkl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){205 void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 206 206 uint_t j; 207 207 onset->data[0] = 0.; … … 214 214 215 215 /* Spectral flux */ 216 void aubio_specdesc_specflux(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){216 void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 217 217 uint_t j; 218 218 onset->data[0] = 0.; … … 226 226 /* Generic function pointing to the choosen one */ 227 227 void 228 aubio_specdesc_do (aubio_specdesc_t *o, c vec_t * fftgrain,228 aubio_specdesc_do (aubio_specdesc_t *o, const cvec_t * fftgrain, 229 229 fvec_t * onset) { 230 230 o->funcpointer(o,fftgrain,onset); … … 235 235 */ 236 236 aubio_specdesc_t * 237 new_aubio_specdesc (c har_t * onset_mode, uint_t size){237 new_aubio_specdesc (const char_t * onset_mode, uint_t size){ 238 238 aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t); 239 239 uint_t rsize = size/2+1; … … 274 274 onset_type = aubio_onset_default; 275 275 else { 276 AUBIO_ERR("unknown spectral descriptor type %s, using default.\n", onset_mode); 277 onset_type = aubio_onset_default; 276 AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode); 277 AUBIO_FREE(o); 278 return NULL; 278 279 } 279 280 switch(onset_type) { 280 281 /* for both energy and hfc, only fftgrain->norm is required */ 281 case aubio_onset_energy: 282 case aubio_onset_energy: 282 283 break; 283 284 case aubio_onset_hfc: … … 367 368 void del_aubio_specdesc (aubio_specdesc_t *o){ 368 369 switch(o->onset_type) { 369 case aubio_onset_energy: 370 case aubio_onset_energy: 370 371 break; 371 372 case aubio_onset_hfc: -
src/spectral/specdesc.h
r00d0275 r155cc10 146 146 147 147 148 #ifndef _AUBIO_SPECDESC_H149 #define _AUBIO_SPECDESC_H148 #ifndef AUBIO_SPECDESC_H 149 #define AUBIO_SPECDESC_H 150 150 151 151 #ifdef __cplusplus … … 165 165 166 166 */ 167 void aubio_specdesc_do (aubio_specdesc_t * o, c vec_t * fftgrain,167 void aubio_specdesc_do (aubio_specdesc_t * o, const cvec_t * fftgrain, 168 168 fvec_t * desc); 169 169 … … 179 179 180 180 */ 181 aubio_specdesc_t *new_aubio_specdesc (c har_t * method, uint_t buf_size);181 aubio_specdesc_t *new_aubio_specdesc (const char_t * method, uint_t buf_size); 182 182 183 183 /** deletion of a spectral descriptor … … 192 192 #endif 193 193 194 #endif /* _AUBIO_SPECDESC_H */194 #endif /* AUBIO_SPECDESC_H */ -
src/spectral/statistics.c
r00d0275 r155cc10 23 23 #include "spectral/specdesc.h" 24 24 25 void aubio_specdesc_centroid (aubio_specdesc_t * o, c vec_t * spec,26 fvec_t * desc); 27 void aubio_specdesc_spread (aubio_specdesc_t * o, c vec_t * spec,28 fvec_t * desc); 29 void aubio_specdesc_skewness (aubio_specdesc_t * o, c vec_t * spec,30 fvec_t * desc); 31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, c vec_t * spec,32 fvec_t * desc); 33 void aubio_specdesc_slope (aubio_specdesc_t * o, c vec_t * spec,34 fvec_t * desc); 35 void aubio_specdesc_decrease (aubio_specdesc_t * o, c vec_t * spec,36 fvec_t * desc); 37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, c vec_t * spec,38 fvec_t * desc); 39 40 41 smpl_t cvec_sum (c vec_t * s);42 smpl_t cvec_mean (c vec_t * s);43 smpl_t cvec_centroid (c vec_t * s);44 smpl_t cvec_moment (c vec_t * s, uint_t moment);45 46 smpl_t 47 cvec_sum (c vec_t * s)25 void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec, 26 fvec_t * desc); 27 void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec, 28 fvec_t * desc); 29 void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec, 30 fvec_t * desc); 31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec, 32 fvec_t * desc); 33 void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec, 34 fvec_t * desc); 35 void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec, 36 fvec_t * desc); 37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec, 38 fvec_t * desc); 39 40 41 smpl_t cvec_sum (const cvec_t * s); 42 smpl_t cvec_mean (const cvec_t * s); 43 smpl_t cvec_centroid (const cvec_t * s); 44 smpl_t cvec_moment (const cvec_t * s, uint_t moment); 45 46 smpl_t 47 cvec_sum (const cvec_t * s) 48 48 { 49 49 uint_t j; … … 56 56 57 57 smpl_t 58 cvec_mean (c vec_t * s)58 cvec_mean (const cvec_t * s) 59 59 { 60 60 return cvec_sum (s) / (smpl_t) (s->length); … … 62 62 63 63 smpl_t 64 cvec_centroid (c vec_t * spec)64 cvec_centroid (const cvec_t * spec) 65 65 { 66 66 smpl_t sum = 0., sc = 0.; … … 78 78 79 79 smpl_t 80 cvec_moment (c vec_t * spec, uint_t order)80 cvec_moment (const cvec_t * spec, uint_t order) 81 81 { 82 82 smpl_t sum = 0., centroid = 0., sc = 0.; … … 95 95 96 96 void 97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, c vec_t * spec,97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 98 98 fvec_t * desc) 99 99 { … … 102 102 103 103 void 104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, c vec_t * spec,104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 105 105 fvec_t * desc) 106 106 { … … 109 109 110 110 void 111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, c vec_t * spec,111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 112 112 fvec_t * desc) 113 113 { … … 123 123 124 124 void 125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, c vec_t * spec,125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 126 126 fvec_t * desc) 127 127 { … … 137 137 138 138 void 139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, c vec_t * spec,139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 140 140 fvec_t * desc) 141 141 { … … 165 165 166 166 void 167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, c vec_t * spec,167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, const cvec_t * spec, 168 168 fvec_t * desc) 169 169 { … … 183 183 184 184 void 185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, c vec_t * spec,185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, const cvec_t * spec, 186 186 fvec_t *desc) 187 187 { -
src/spectral/tss.c
r00d0275 r155cc10 41 41 }; 42 42 43 void aubio_tss_do(aubio_tss_t *o, c vec_t * input,43 void aubio_tss_do(aubio_tss_t *o, const cvec_t * input, 44 44 cvec_t * trans, cvec_t * stead) 45 45 { -
src/spectral/tss.h
r00d0275 r155cc10 37 37 */ 38 38 39 #ifndef _AUBIO_TSS_H40 #define _AUBIO_TSS_H39 #ifndef AUBIO_TSS_H 40 #define AUBIO_TSS_H 41 41 42 42 #ifdef __cplusplus … … 70 70 71 71 */ 72 void aubio_tss_do (aubio_tss_t * o, c vec_t * input, cvec_t * trans,72 void aubio_tss_do (aubio_tss_t * o, const cvec_t * input, cvec_t * trans, 73 73 cvec_t * stead); 74 74 … … 101 101 #endif 102 102 103 #endif /* _AUBIO_TSS_H */103 #endif /* AUBIO_TSS_H */ -
src/synth/sampler.c
r00d0275 r155cc10 20 20 21 21 22 #include "config.h"23 22 #include "aubio_priv.h" 24 23 #include "fvec.h" … … 56 55 } 57 56 58 uint_t aubio_sampler_load( aubio_sampler_t * o, c har_t * uri )57 uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri ) 59 58 { 60 59 if (o->source) del_aubio_source(o->source); 61 o->uri = uri; 60 61 if (o->uri) AUBIO_FREE(o->uri); 62 o->uri = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX)); 63 strncpy(o->uri, uri, strnlen(uri, PATH_MAX)); 64 62 65 o->source = new_aubio_source(uri, o->samplerate, o->blocksize); 63 66 if (o->source) return 0; … … 66 69 } 67 70 68 void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output)71 void aubio_sampler_do ( aubio_sampler_t * o, const fvec_t * input, fvec_t * output) 69 72 { 70 73 uint_t read = 0, i; … … 83 86 } 84 87 85 void aubio_sampler_do_multi ( aubio_sampler_t * o, fmat_t * input, fmat_t * output)88 void aubio_sampler_do_multi ( aubio_sampler_t * o, const fmat_t * input, fmat_t * output) 86 89 { 87 90 uint_t read = 0, i, j; … … 104 107 } 105 108 106 uint_t aubio_sampler_get_playing ( aubio_sampler_t * o )109 uint_t aubio_sampler_get_playing ( const aubio_sampler_t * o ) 107 110 { 108 111 return o->playing; … … 131 134 del_aubio_source(o->source); 132 135 } 136 if (o->uri) AUBIO_FREE(o->uri); 133 137 del_fvec(o->source_output); 134 138 del_fmat(o->source_output_multi); -
src/synth/sampler.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_SAMPLER_H22 #define _AUBIO_SAMPLER_H21 #ifndef AUBIO_SAMPLER_H 22 #define AUBIO_SAMPLER_H 23 23 24 24 /** \file … … 60 60 61 61 */ 62 uint_t aubio_sampler_load( aubio_sampler_t * o, c har_t * uri );62 uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri ); 63 63 64 64 /** process sampler function … … 74 74 75 75 */ 76 void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output);76 void aubio_sampler_do ( aubio_sampler_t * o, const fvec_t * input, fvec_t * output); 77 77 78 78 /** process sampler function, multiple channels … … 88 88 89 89 */ 90 void aubio_sampler_do_multi ( aubio_sampler_t * o, fmat_t * input, fmat_t * output);90 void aubio_sampler_do_multi ( aubio_sampler_t * o, const fmat_t * input, fmat_t * output); 91 91 92 92 /** get current playing state … … 97 97 98 98 */ 99 uint_t aubio_sampler_get_playing ( aubio_sampler_t * o );99 uint_t aubio_sampler_get_playing ( const aubio_sampler_t * o ); 100 100 101 101 /** set current playing state … … 138 138 #endif 139 139 140 #endif /* _AUBIO_SAMPLER_H */140 #endif /* AUBIO_SAMPLER_H */ -
src/synth/wavetable.c
r00d0275 r155cc10 20 20 21 21 22 #include "config.h"23 22 #include "aubio_priv.h" 24 23 #include "fvec.h" … … 69 68 } 70 69 71 static smpl_t interp_2( fvec_t *input, smpl_t pos) {70 static smpl_t interp_2(const fvec_t *input, smpl_t pos) { 72 71 uint_t idx = (uint_t)FLOOR(pos); 73 72 smpl_t frac = pos - (smpl_t)idx; … … 77 76 } 78 77 79 void aubio_wavetable_do ( aubio_wavetable_t * s, fvec_t * input, fvec_t * output)78 void aubio_wavetable_do ( aubio_wavetable_t * s, const fvec_t * input, fvec_t * output) 80 79 { 81 80 uint_t i; … … 108 107 } 109 108 110 void aubio_wavetable_do_multi ( aubio_wavetable_t * s, fmat_t * input, fmat_t * output)109 void aubio_wavetable_do_multi ( aubio_wavetable_t * s, const fmat_t * input, fmat_t * output) 111 110 { 112 111 uint_t i, j; … … 143 142 } 144 143 145 uint_t aubio_wavetable_get_playing ( aubio_wavetable_t * s )144 uint_t aubio_wavetable_get_playing ( const aubio_wavetable_t * s ) 146 145 { 147 146 return s->playing; … … 173 172 } 174 173 175 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * s) {174 smpl_t aubio_wavetable_get_freq ( const aubio_wavetable_t * s) { 176 175 return aubio_parameter_get_current_value ( s->freq); 177 176 } … … 182 181 } 183 182 184 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) {183 smpl_t aubio_wavetable_get_amp ( const aubio_wavetable_t * s) { 185 184 return aubio_parameter_get_current_value ( s->amp ); 186 185 } -
src/synth/wavetable.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_WAVETABLE_H22 #define _AUBIO_WAVETABLE_H21 #ifndef AUBIO_WAVETABLE_H 22 #define AUBIO_WAVETABLE_H 23 23 24 24 /** \file … … 60 60 61 61 */ 62 uint_t aubio_wavetable_load( aubio_wavetable_t * o, c har_t * uri );62 uint_t aubio_wavetable_load( aubio_wavetable_t * o, const char_t * uri ); 63 63 64 64 /** process wavetable function … … 74 74 75 75 */ 76 void aubio_wavetable_do ( aubio_wavetable_t * o, fvec_t * input, fvec_t * output);76 void aubio_wavetable_do ( aubio_wavetable_t * o, const fvec_t * input, fvec_t * output); 77 77 78 78 /** process wavetable function, multiple channels … … 88 88 89 89 */ 90 void aubio_wavetable_do_multi ( aubio_wavetable_t * o, fmat_t * input, fmat_t * output);90 void aubio_wavetable_do_multi ( aubio_wavetable_t * o, const fmat_t * input, fmat_t * output); 91 91 92 92 /** get current playing state … … 97 97 98 98 */ 99 uint_t aubio_wavetable_get_playing ( aubio_wavetable_t * o );99 uint_t aubio_wavetable_get_playing ( const aubio_wavetable_t * o ); 100 100 101 101 /** set current playing state … … 144 144 145 145 */ 146 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * o);146 smpl_t aubio_wavetable_get_freq ( const aubio_wavetable_t * o); 147 147 148 148 /** set wavetable amplitude … … 163 163 164 164 */ 165 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * o);165 smpl_t aubio_wavetable_get_amp ( const aubio_wavetable_t * o); 166 166 167 167 /** destroy aubio_wavetable_t object … … 176 176 #endif 177 177 178 #endif /* _AUBIO_WAVETABLE_H */178 #endif /* AUBIO_WAVETABLE_H */ -
src/tempo/beattracking.c
r00d0275 r155cc10 124 124 125 125 void 126 aubio_beattracking_do (aubio_beattracking_t * bt, fvec_t * dfframe,126 aubio_beattracking_do (aubio_beattracking_t * bt, const fvec_t * dfframe, 127 127 fvec_t * output) 128 128 { … … 410 410 411 411 smpl_t 412 aubio_beattracking_get_period ( aubio_beattracking_t * bt)412 aubio_beattracking_get_period (const aubio_beattracking_t * bt) 413 413 { 414 414 return bt->hop_size * bt->bp; … … 416 416 417 417 smpl_t 418 aubio_beattracking_get_period_s ( aubio_beattracking_t * bt)418 aubio_beattracking_get_period_s (const aubio_beattracking_t * bt) 419 419 { 420 420 return aubio_beattracking_get_period(bt) / (smpl_t) bt->samplerate; … … 422 422 423 423 smpl_t 424 aubio_beattracking_get_bpm ( aubio_beattracking_t * bt)424 aubio_beattracking_get_bpm (const aubio_beattracking_t * bt) 425 425 { 426 426 if (bt->bp != 0) { … … 432 432 433 433 smpl_t 434 aubio_beattracking_get_confidence ( aubio_beattracking_t * bt)434 aubio_beattracking_get_confidence (const aubio_beattracking_t * bt) 435 435 { 436 436 if (bt->gp) { -
src/tempo/beattracking.h
r00d0275 r155cc10 37 37 38 38 */ 39 #ifndef _AUBIO_BEATTRACKING_H40 #define _AUBIO_BEATTRACKING_H39 #ifndef AUBIO_BEATTRACKING_H 40 #define AUBIO_BEATTRACKING_H 41 41 42 42 #ifdef __cplusplus … … 65 65 66 66 */ 67 void aubio_beattracking_do (aubio_beattracking_t * bt, fvec_t * dfframes,67 void aubio_beattracking_do (aubio_beattracking_t * bt, const fvec_t * dfframes, 68 68 fvec_t * out); 69 69 … … 76 76 77 77 */ 78 smpl_t aubio_beattracking_get_period ( aubio_beattracking_t * bt);78 smpl_t aubio_beattracking_get_period (const aubio_beattracking_t * bt); 79 79 80 80 /** get current beat period in seconds … … 86 86 87 87 */ 88 smpl_t aubio_beattracking_get_period_s ( aubio_beattracking_t * bt);88 smpl_t aubio_beattracking_get_period_s (const aubio_beattracking_t * bt); 89 89 90 90 /** get current tempo in bpm … … 96 96 97 97 */ 98 smpl_t aubio_beattracking_get_bpm( aubio_beattracking_t * bt);98 smpl_t aubio_beattracking_get_bpm(const aubio_beattracking_t * bt); 99 99 100 100 /** get current tempo confidence … … 106 106 107 107 */ 108 smpl_t aubio_beattracking_get_confidence( aubio_beattracking_t * bt);108 smpl_t aubio_beattracking_get_confidence(const aubio_beattracking_t * bt); 109 109 110 110 /** delete beat tracking object … … 119 119 #endif 120 120 121 #endif /* _AUBIO_BEATTRACKING_H */121 #endif /* AUBIO_BEATTRACKING_H */ -
src/tempo/tempo.c
r00d0275 r155cc10 28 28 #include "mathutils.h" 29 29 #include "tempo/tempo.h" 30 31 // TODO implement get/set_delay32 33 /** set current delay34 35 \param o beat tracking object36 37 \return current delay, in samples38 39 */40 uint_t aubio_tempo_get_delay(aubio_tempo_t * o);41 42 /** set current delay43 44 \param o beat tracking object45 \param delay delay to set tempo to, in samples46 47 \return `0` if successful, non-zero otherwise48 49 */50 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay);51 30 52 31 /* structure to store object state */ … … 70 49 uint_t total_frames; /** total frames since beginning */ 71 50 uint_t last_beat; /** time of latest detected beat, in samples */ 72 uint_t delay; /** delay to remove to last beat, in samples */51 sint_t delay; /** delay to remove to last beat, in samples */ 73 52 uint_t last_tatum; /** time of latest detected tatum, in samples */ 74 53 uint_t tatum_signature; /** number of tatum between each beats */ … … 76 55 77 56 /* execute tempo detection function on iput buffer */ 78 void aubio_tempo_do(aubio_tempo_t *o, fvec_t * input, fvec_t * tempo)57 void aubio_tempo_do(aubio_tempo_t *o, const fvec_t * input, fvec_t * tempo) 79 58 { 80 59 uint_t i; … … 101 80 o->blockpos++; 102 81 aubio_peakpicker_do (o->pp, o->of, o->onset); 103 tempo->data[1] = o->onset->data[0]; 82 // store onset detection function in second sample of vector 83 //tempo->data[1] = o->onset->data[0]; 104 84 thresholded = aubio_peakpicker_get_thresholded_input(o->pp); 105 85 o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0]; … … 125 105 uint_t aubio_tempo_get_last (aubio_tempo_t *o) 126 106 { 127 return o->last_beat -o->delay;107 return o->last_beat + o->delay; 128 108 } 129 109 … … 138 118 } 139 119 140 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay) {120 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay) { 141 121 o->delay = delay; 122 return AUBIO_OK; 123 } 124 125 uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay) { 126 o->delay = delay * o->samplerate; 127 return AUBIO_OK; 128 } 129 130 uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) { 131 o->delay = 1000. * delay * o->samplerate; 142 132 return AUBIO_OK; 143 133 } … … 145 135 uint_t aubio_tempo_get_delay(aubio_tempo_t * o) { 146 136 return o->delay; 137 } 138 139 smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o) { 140 return o->delay / (smpl_t)(o->samplerate); 141 } 142 143 smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) { 144 return o->delay / (smpl_t)(o->samplerate) / 1000.; 147 145 } 148 146 … … 167 165 168 166 /* Allocate memory for an tempo detection */ 169 aubio_tempo_t * new_aubio_tempo (c har_t * tempo_mode,167 aubio_tempo_t * new_aubio_tempo (const char_t * tempo_mode, 170 168 uint_t buf_size, uint_t hop_size, uint_t samplerate) 171 169 { … … 177 175 AUBIO_ERR("tempo: got hop size %d, but can not be < 1\n", hop_size); 178 176 goto beach; 179 } else if ((sint_t)buf_size < 1) {180 AUBIO_ERR("tempo: got window size %d, but can not be < 1\n", buf_size);177 } else if ((sint_t)buf_size < 2) { 178 AUBIO_ERR("tempo: got window size %d, but can not be < 2\n", buf_size); 181 179 goto beach; 182 180 } else if (buf_size < hop_size) { -
src/tempo/tempo.h
r00d0275 r155cc10 31 31 */ 32 32 33 #ifndef _AUBIO_TEMPO_H34 #define _AUBIO_TEMPO_H33 #ifndef AUBIO_TEMPO_H 34 #define AUBIO_TEMPO_H 35 35 36 36 #ifdef __cplusplus … … 51 51 52 52 */ 53 aubio_tempo_t * new_aubio_tempo (c har_t * method,53 aubio_tempo_t * new_aubio_tempo (const char_t * method, 54 54 uint_t buf_size, uint_t hop_size, uint_t samplerate); 55 55 … … 61 61 62 62 */ 63 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo);63 void aubio_tempo_do (aubio_tempo_t *o, const fvec_t * input, fvec_t * tempo); 64 64 65 65 /** get the time of the latest beat detected, in samples … … 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 */ 161 161 smpl_t aubio_tempo_get_confidence(aubio_tempo_t * o); 162 162 163 /* set number of tatum per beat163 /** set number of tatum per beat 164 164 165 165 \param o beat tracking object … … 169 169 uint_t aubio_tempo_set_tatum_signature(aubio_tempo_t *o, uint_t signature); 170 170 171 /* check whether a tatum was detected in the current frame171 /** check whether a tatum was detected in the current frame 172 172 173 173 \param o beat tracking object … … 178 178 uint_t aubio_tempo_was_tatum(aubio_tempo_t *o); 179 179 180 /* get position of last_tatum, in samples180 /** get position of last_tatum, in samples 181 181 182 182 \param o beat tracking object … … 184 184 */ 185 185 smpl_t aubio_tempo_get_last_tatum(aubio_tempo_t *o); 186 187 /** get current delay 188 189 \param o beat tracking object 190 191 \return current delay, in samples 192 193 */ 194 uint_t aubio_tempo_get_delay(aubio_tempo_t * o); 195 196 /** get current delay in seconds 197 198 \param o beat tracking object 199 200 \return current delay, in seconds 201 202 */ 203 smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o); 204 205 /** get current delay in ms 206 207 \param o beat tracking object 208 209 \return current delay, in milliseconds 210 211 */ 212 smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o); 213 214 /** set current delay 215 216 \param o beat tracking object 217 \param delay delay to set tempo to, in samples 218 219 \return `0` if successful, non-zero otherwise 220 221 */ 222 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay); 223 224 /** set current delay in seconds 225 226 \param o beat tracking object 227 \param delay delay to set tempo to, in seconds 228 229 \return `0` if successful, non-zero otherwise 230 231 */ 232 uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay); 233 234 /** set current delay 235 236 \param o beat tracking object 237 \param delay delay to set tempo to, in samples 238 239 \return `0` if successful, non-zero otherwise 240 241 */ 242 uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay); 186 243 187 244 /** delete tempo detection object … … 196 253 #endif 197 254 198 #endif /* _AUBIO_TEMPO_H */255 #endif /* AUBIO_TEMPO_H */ -
src/temporal/a_weighting.c
r00d0275 r155cc10 30 30 { 31 31 uint_t order; lsmp_t *a, *b; lvec_t *as, *bs; 32 33 if ((sint_t)samplerate <= 0) { 34 AUBIO_ERROR("aubio_filter: failed setting A-weighting with samplerate %d\n", samplerate); 35 return AUBIO_FAIL; 36 } 37 if (f == NULL) { 38 AUBIO_ERROR("aubio_filter: failed setting A-weighting with filter NULL\n"); 39 return AUBIO_FAIL; 40 } 41 42 order = aubio_filter_get_order (f); 43 if (order != 7) { 44 AUBIO_ERROR ("aubio_filter: order of A-weighting filter must be 7, not %d\n", order); 45 return 1; 46 } 47 32 48 aubio_filter_set_samplerate (f, samplerate); 33 49 bs = aubio_filter_get_feedforward (f); 34 50 as = aubio_filter_get_feedback (f); 35 51 b = bs->data, a = as->data; 36 order = aubio_filter_get_order (f);37 38 if (order != 7) {39 AUBIO_ERROR ("order of A-weighting filter must be 7, not %d\n", order);40 return 1;41 }42 52 43 53 /* select coefficients according to sampling frequency */ … … 245 255 { 246 256 aubio_filter_t *f = new_aubio_filter (7); 247 aubio_filter_set_a_weighting (f, samplerate); 257 if (aubio_filter_set_a_weighting(f,samplerate) != AUBIO_OK) { 258 del_aubio_filter(f); 259 return NULL; 260 } 248 261 return f; 249 262 } -
src/temporal/a_weighting.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_FILTER_A_DESIGN_H22 #define _AUBIO_FILTER_A_DESIGN_H21 #ifndef AUBIO_FILTER_A_DESIGN_H 22 #define AUBIO_FILTER_A_DESIGN_H 23 23 24 24 /** \file … … 86 86 #endif 87 87 88 #endif /* _AUBIO_FILTER_A_DESIGN_H */88 #endif /* AUBIO_FILTER_A_DESIGN_H */ -
src/temporal/biquad.c
r00d0275 r155cc10 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/biquad.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_FILTER_BIQUAD_H22 #define _AUBIO_FILTER_BIQUAD_H21 #ifndef AUBIO_FILTER_BIQUAD_H 22 #define AUBIO_FILTER_BIQUAD_H 23 23 24 24 /** \file … … 73 73 #endif 74 74 75 #endif /* _AUBIO_FILTER_BIQUAD_H */75 #endif /* AUBIO_FILTER_BIQUAD_H */ -
src/temporal/c_weighting.c
r00d0275 r155cc10 30 30 { 31 31 uint_t order; lsmp_t *a, *b; lvec_t *as, *bs; 32 33 if ((sint_t)samplerate <= 0) { 34 AUBIO_ERROR("aubio_filter: failed setting C-weighting with samplerate %d\n", samplerate); 35 return AUBIO_FAIL; 36 } 37 if (f == NULL) { 38 AUBIO_ERROR("aubio_filter: failed setting C-weighting with filter NULL\n"); 39 return AUBIO_FAIL; 40 } 41 42 order = aubio_filter_get_order (f); 43 if ( order != 5 ) { 44 AUBIO_ERROR ("aubio_filter: order of C-weighting filter must be 5, not %d\n", order); 45 return 1; 46 } 47 32 48 aubio_filter_set_samplerate (f, samplerate); 33 49 bs = aubio_filter_get_feedforward (f); 34 50 as = aubio_filter_get_feedback (f); 35 51 b = bs->data, a = as->data; 36 order = aubio_filter_get_order (f);37 38 if ( order != 5 ) {39 AUBIO_ERROR ("order of C-weighting filter must be 5, not %d\n", order);40 return 1;41 }42 52 43 53 /* select coefficients according to sampling frequency */ … … 200 210 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) { 201 211 aubio_filter_t * f = new_aubio_filter(5); 202 aubio_filter_set_c_weighting (f, samplerate); 212 if (aubio_filter_set_c_weighting(f,samplerate) != AUBIO_OK) { 213 del_aubio_filter(f); 214 return NULL; 215 } 203 216 return f; 204 217 } 205 -
src/temporal/c_weighting.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_FILTER_C_DESIGN_H22 #define _AUBIO_FILTER_C_DESIGN_H21 #ifndef AUBIO_FILTER_C_DESIGN_H 22 #define AUBIO_FILTER_C_DESIGN_H 23 23 24 24 /** \file … … 86 86 #endif 87 87 88 #endif /* _AUBIO_FILTER_C_DESIGN_H */88 #endif /* AUBIO_FILTER_C_DESIGN_H */ -
src/temporal/filter.c
r00d0275 r155cc10 40 40 41 41 void 42 aubio_filter_do_outplace (aubio_filter_t * f, fvec_t * in, fvec_t * out)42 aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out) 43 43 { 44 44 fvec_copy (in, out); … … 94 94 95 95 lvec_t * 96 aubio_filter_get_feedback ( aubio_filter_t * f)96 aubio_filter_get_feedback (const aubio_filter_t * f) 97 97 { 98 98 return f->a; … … 100 100 101 101 lvec_t * 102 aubio_filter_get_feedforward ( aubio_filter_t * f)102 aubio_filter_get_feedforward (const aubio_filter_t * f) 103 103 { 104 104 return f->b; … … 106 106 107 107 uint_t 108 aubio_filter_get_order ( aubio_filter_t * f)108 aubio_filter_get_order (const aubio_filter_t * f) 109 109 { 110 110 return f->order; … … 112 112 113 113 uint_t 114 aubio_filter_get_samplerate ( aubio_filter_t * f)114 aubio_filter_get_samplerate (const aubio_filter_t * f) 115 115 { 116 116 return f->samplerate; … … 135 135 { 136 136 aubio_filter_t *f = AUBIO_NEW (aubio_filter_t); 137 if ((sint_t)order < 1) { 138 AUBIO_FREE(f); 139 return NULL; 140 } 137 141 f->x = new_lvec (order); 138 142 f->y = new_lvec (order); … … 143 147 f->order = order; 144 148 /* set default to identity */ 145 f->a->data[1] = 1.; 149 f->a->data[0] = 1.; 150 f->b->data[0] = 1.; 146 151 return f; 147 152 } -
src/temporal/filter.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_FILTER_H22 #define _AUBIO_FILTER_H21 #ifndef AUBIO_FILTER_H 22 #define AUBIO_FILTER_H 23 23 24 24 /** \file … … 87 87 88 88 */ 89 void aubio_filter_do_outplace (aubio_filter_t * f, fvec_t * in, fvec_t * out);89 void aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out); 90 90 91 91 /** filter input vector forward and backward … … 105 105 106 106 */ 107 lvec_t *aubio_filter_get_feedback ( aubio_filter_t * f);107 lvec_t *aubio_filter_get_feedback (const aubio_filter_t * f); 108 108 109 109 /** returns a pointer to feedforward coefficients \f$ b_i \f$ … … 114 114 115 115 */ 116 lvec_t *aubio_filter_get_feedforward ( aubio_filter_t * f);116 lvec_t *aubio_filter_get_feedforward (const aubio_filter_t * f); 117 117 118 118 /** get order of the filter … … 123 123 124 124 */ 125 uint_t aubio_filter_get_order ( aubio_filter_t * f);125 uint_t aubio_filter_get_order (const aubio_filter_t * f); 126 126 127 127 /** get sampling rate of the filter … … 132 132 133 133 */ 134 uint_t aubio_filter_get_samplerate ( aubio_filter_t * f);134 uint_t aubio_filter_get_samplerate (const aubio_filter_t * f); 135 135 136 136 /** get sampling rate of the filter … … 174 174 #endif 175 175 176 #endif /* _AUBIO_FILTER_H */176 #endif /* AUBIO_FILTER_H */ -
src/temporal/resampler.c
r00d0275 r155cc10 19 19 */ 20 20 21 #include "config.h"22 23 21 #include "aubio_priv.h" 24 22 #include "fvec.h" 25 23 #include "temporal/resampler.h" 26 24 27 #if HAVE_SAMPLERATE 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 */ … … 62 64 63 65 void 64 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)66 aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input, fvec_t * output) 65 67 { 66 68 s->proc->input_frames = input->length; … … 93 95 94 96 void 95 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)97 aubio_resampler_do (aubio_resampler_t * s UNUSED, const fvec_t * input UNUSED, fvec_t * output UNUSED) 96 98 { 97 99 } -
src/temporal/resampler.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_RESAMPLER_H22 #define _AUBIO_RESAMPLER_H21 #ifndef AUBIO_RESAMPLER_H 22 #define AUBIO_RESAMPLER_H 23 23 24 24 /** \file … … 56 56 57 57 */ 58 void aubio_resampler_do (aubio_resampler_t * s, fvec_t * input,58 void aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input, 59 59 fvec_t * output); 60 60 … … 63 63 #endif 64 64 65 #endif /* _AUBIO_RESAMPLER_H */65 #endif /* AUBIO_RESAMPLER_H */ -
src/types.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO__TYPES_H22 #define _AUBIO__TYPES_H21 #ifndef AUBIO_TYPES_H 22 #define AUBIO_TYPES_H 23 23 24 24 /** \file … … 68 68 #endif 69 69 70 #endif /* _AUBIO__TYPES_H */70 #endif /* AUBIO_TYPES_H */ -
src/utils/hist.c
r00d0275 r155cc10 138 138 } 139 139 140 smpl_t aubio_hist_mean ( aubio_hist_t *s) {140 smpl_t aubio_hist_mean (const aubio_hist_t *s) { 141 141 uint_t j; 142 142 smpl_t tmp = 0.0; -
src/utils/hist.h
r00d0275 r155cc10 26 26 */ 27 27 28 #ifndef _AUBIO_HIST_H29 #define _AUBIO_HIST_H28 #ifndef AUBIO_HIST_H 29 #define AUBIO_HIST_H 30 30 31 31 #ifdef __cplusplus … … 51 51 void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input); 52 52 /** compute the mean of the histogram */ 53 smpl_t aubio_hist_mean( aubio_hist_t *s);53 smpl_t aubio_hist_mean(const aubio_hist_t *s); 54 54 /** weight the histogram */ 55 55 void aubio_hist_weight(aubio_hist_t *s); … … 61 61 #endif 62 62 63 #endif /* _AUBIO_HIST_H */63 #endif /* AUBIO_HIST_H */ -
src/utils/parameter.c
r00d0275 r155cc10 19 19 */ 20 20 21 #include "config.h"22 21 #include "aubio_priv.h" 23 22 #include "parameter.h" … … 85 84 } 86 85 87 smpl_t aubio_parameter_get_current_value ( aubio_parameter_t * s )86 smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s ) 88 87 { 89 88 return s->current_value; … … 110 109 } 111 110 112 uint_t aubio_parameter_get_steps ( aubio_parameter_t * param )111 uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param ) 113 112 { 114 113 return param->steps; … … 121 120 } 122 121 123 smpl_t aubio_parameter_get_min_value ( aubio_parameter_t * param )122 smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param ) 124 123 { 125 124 return param->min_value; … … 132 131 } 133 132 134 smpl_t aubio_parameter_get_max_value ( aubio_parameter_t * param )133 smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param ) 135 134 { 136 135 return param->max_value; -
src/utils/parameter.h
r00d0275 r155cc10 19 19 */ 20 20 21 #ifndef _AUBIO_PARAMETER_H22 #define _AUBIO_PARAMETER_H21 #ifndef AUBIO_PARAMETER_H 22 #define AUBIO_PARAMETER_H 23 23 24 24 /** \file … … 77 77 78 78 */ 79 smpl_t aubio_parameter_get_current_value ( aubio_parameter_t * param );79 smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * param ); 80 80 81 81 /** set current parameter value, skipping interpolation … … 106 106 107 107 */ 108 uint_t aubio_parameter_get_steps ( aubio_parameter_t * param);108 uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param); 109 109 110 110 /** set minimum value of this parameter … … 125 125 126 126 */ 127 smpl_t aubio_parameter_get_min_value ( aubio_parameter_t * param );127 smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param ); 128 128 129 129 /** set maximum value of this parameter … … 144 144 145 145 */ 146 smpl_t aubio_parameter_get_max_value ( aubio_parameter_t * param );146 smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param ); 147 147 148 148 /** destroy ::aubio_parameter_t object … … 157 157 #endif 158 158 159 #endif /* _AUBIO_PARAMETER_H */159 #endif /* AUBIO_PARAMETER_H */ -
src/utils/scale.c
r00d0275 r155cc10 38 38 }; 39 39 40 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, 40 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, 41 41 smpl_t olow, smpl_t ohig) { 42 42 aubio_scale_t * s = AUBIO_NEW(aubio_scale_t); -
src/utils/scale.h
r00d0275 r155cc10 29 29 30 30 */ 31 #ifndef _AUBIO_SCALE_H32 #define _AUBIO_SCALE_H31 #ifndef AUBIO_SCALE_H 32 #define AUBIO_SCALE_H 33 33 34 34 #ifdef __cplusplus … … 78 78 #endif 79 79 80 #endif /* _AUBIO_SCALE_H */80 #endif /* AUBIO_SCALE_H */ -
src/vecutils.c
r00d0275 r155cc10 1 #include "config.h"2 1 #include "aubio_priv.h" 3 2 #include "types.h" -
src/vecutils.h
r00d0275 r155cc10 25 25 */ 26 26 27 #ifndef _AUBIO__VECUTILS_H28 #define _AUBIO__VECUTILS_H27 #ifndef AUBIO_VECUTILS_H 28 #define AUBIO_VECUTILS_H 29 29 30 30 #ifdef __cplusplus … … 114 114 #endif 115 115 116 #endif /* _AUBIO__VECUTILS_H */116 #endif /* AUBIO_VECUTILS_H */ -
src/wscript_build
r00d0275 r155cc10 2 2 3 3 uselib = [] 4 uselib += ['M'] 4 5 uselib += ['FFTW3', 'FFTW3F'] 5 6 uselib += ['SAMPLERATE'] … … 11 12 uselib += ['BLAS'] 12 13 13 # build each source files14 14 source = ctx.path.ant_glob('*.c **/*.c') 15 15 16 ctx(features = 'c', 16 17 source = source, 17 18 includes = ['.'], 18 uselib = uselib, 19 lib = 'm', 19 use = uselib, 20 20 target = 'lib_objects') 21 21 … … 24 24 build_features = ['cstlib', 'cshlib'] 25 25 elif ctx.env['DEST_OS'] in ['win32', 'win64']: 26 build_features = ['cshlib'] 27 else: #linux, darwin, android, mingw, ... 28 build_features = ['cshlib', 'cstlib'] 26 build_features = ['cstlib', 'cshlib'] 27 elif ctx.env['DEST_OS'] in ['emscripten']: 28 build_features = ['cstlib'] 29 elif '--static' in ctx.env['LDFLAGS'] or '--static' in ctx.env['LINKFLAGS']: 30 # static in cflags, ... 31 build_features = ['cstlib'] 32 else: 33 # linux, darwin, android, mingw, ... 34 build_features = ['cstlib', 'cshlib'] 35 36 # also install static lib 37 from waflib.Tools.c import cstlib 38 from waflib.Tools.fc import fcstlib 39 fcstlib.inst_to = cstlib.inst_to = '${LIBDIR}' 29 40 30 41 for target in build_features: 31 42 ctx(features = 'c ' + target, 32 use = ['lib_objects'], 33 uselib = uselib, 34 lib = 'm', 43 use = uselib + ['lib_objects'], 35 44 target = 'aubio', 36 45 vnum = ctx.env['LIB_VERSION']) 37 46 38 47 # install headers, except _priv.h ones 39 ctx.install_files('${ PREFIX}/include/aubio/',48 ctx.install_files('${INCLUDEDIR}/aubio/', 40 49 ctx.path.ant_glob('**/*.h', excl = ['**_priv.h', 'config.h']), 41 50 relative_trick=True)
Note: See TracChangeset
for help on using the changeset viewer.