- Timestamp:
- Jun 22, 2016, 1:00:10 PM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 4b9443c4
- Parents:
- 60fc05b (diff), 6769586 (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/io
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/io/audio_unit.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/sink.c ¶
r60fc05b rf264b17 55 55 }; 56 56 57 aubio_sink_t * new_aubio_sink(c har_t * uri, uint_t samplerate) {57 aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) { 58 58 aubio_sink_t * s = AUBIO_NEW(aubio_sink_t); 59 59 #ifdef HAVE_SINK_APPLE_AUDIO … … 71 71 } 72 72 #endif /* HAVE_SINK_APPLE_AUDIO */ 73 #if HAVE_SNDFILE73 #ifdef HAVE_SNDFILE 74 74 s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate); 75 75 if (s->sink) { … … 85 85 } 86 86 #endif /* HAVE_SNDFILE */ 87 #if HAVE_WAVWRITE87 #ifdef HAVE_WAVWRITE 88 88 s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate); 89 89 if (s->sink) { … … 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 return s->s_get_samplerate((void *)s->sink); 125 125 } 126 126 127 uint_t aubio_sink_get_channels( aubio_sink_t * s) {127 uint_t aubio_sink_get_channels(const aubio_sink_t * s) { 128 128 return s->s_get_channels((void *)s->sink); 129 129 } -
TabularUnified src/io/sink.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/sink_apple_audio.c ¶
r60fc05b rf264b17 37 37 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); 38 38 extern void freeAudioBufferList(AudioBufferList *bufferList); 39 extern CFURLRef getURLFromPath(const char * path);39 extern CFURLRef createURLFromPath(const char * path); 40 40 char_t *getPrintableOSStatusError(char_t *str, OSStatus error); 41 41 … … 43 43 44 44 #define MAX_SIZE 4096 // the maximum number of frames that can be written at a time 45 46 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write); 45 47 46 48 struct _aubio_sink_apple_audio_t { … … 56 58 }; 57 59 58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(c har_t * uri, uint_t samplerate) {60 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) { 59 61 aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t); 60 s->path = uri;61 62 s->max_frames = MAX_SIZE; 62 s->async = true;63 s->async = false; 63 64 64 65 if (uri == NULL) { … … 66 67 goto beach; 67 68 } 69 if (s->path != NULL) AUBIO_FREE(s->path); 70 s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1); 71 strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1); 68 72 69 73 s->samplerate = 0; … … 111 115 } 112 116 113 uint_t aubio_sink_apple_audio_get_samplerate( aubio_sink_apple_audio_t *s)117 uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s) 114 118 { 115 119 return s->samplerate; 116 120 } 117 121 118 uint_t aubio_sink_apple_audio_get_channels( aubio_sink_apple_audio_t *s)122 uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s) 119 123 { 120 124 return s->channels; … … 138 142 139 143 AudioFileTypeID fileType = kAudioFileWAVEType; 140 CFURLRef fileURL = getURLFromPath(s->path);144 CFURLRef fileURL = createURLFromPath(s->path); 141 145 bool overwrite = true; 142 146 OSStatus err = noErr; 143 147 err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL, 144 148 overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile); 149 CFRelease(fileURL); 145 150 if (err) { 146 151 char_t errorstr[20]; … … 162 167 163 168 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) { 164 OSStatus err = noErr;165 169 UInt32 c, v; 166 170 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 179 183 } 180 184 } 181 if (s->async) { 182 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); 183 184 if (err) { 185 char_t errorstr[20]; 186 AUBIO_ERROR("sink_apple_audio: error while writing %s " 187 "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path, 188 getPrintableOSStatusError(errorstr, err)); 189 s->async = false; 190 } else { 191 return; 192 } 193 194 } else { 195 err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList); 196 197 if (err) { 198 char_t errorstr[20]; 199 AUBIO_ERROR("sink_apple_audio: error while writing %s " 200 "in ExtAudioFileWrite (%s)\n", s->path, 201 getPrintableOSStatusError(errorstr, err)); 202 } 203 } 204 return; 185 aubio_sink_apple_audio_write(s, write); 205 186 } 206 187 207 188 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) { 208 OSStatus err = noErr;209 189 UInt32 c, v; 210 190 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 223 203 } 224 204 } 205 aubio_sink_apple_audio_write(s, write); 206 } 207 208 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) { 209 OSStatus err = noErr; 225 210 if (s->async) { 226 211 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); 227 228 212 if (err) { 229 213 char_t errorstr[20]; 214 if (err == kExtAudioFileError_AsyncWriteBufferOverflow) { 215 sprintf(errorstr,"buffer overflow"); 216 } else if (err == kExtAudioFileError_AsyncWriteTooLarge) { 217 sprintf(errorstr,"write too large"); 218 } else { 219 // unknown error 220 getPrintableOSStatusError(errorstr, err); 221 } 230 222 AUBIO_ERROR("sink_apple_audio: error while writing %s " 231 "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path, 232 getPrintableOSStatusError(errorstr, err)); 233 s->async = false; 234 } else { 235 return; 223 "in ExtAudioFileWriteAsync (%s)\n", s->path, errorstr); 236 224 } 237 238 225 } else { 239 226 err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList); 240 241 227 if (err) { 242 228 char_t errorstr[20]; … … 246 232 } 247 233 } 248 return;249 234 } 250 235 … … 267 252 void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) { 268 253 if (s->audioFile) aubio_sink_apple_audio_close (s); 254 if (s->path) AUBIO_FREE(s->path); 269 255 freeAudioBufferList(&s->bufferList); 270 256 AUBIO_FREE(s); -
TabularUnified src/io/sink_apple_audio.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/sink_sndfile.c ¶
r60fc05b rf264b17 54 54 uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s); 55 55 56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(c har_t * path, uint_t samplerate) {56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) { 57 57 aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t); 58 58 s->max_size = MAX_SIZE; 59 s->path = path;60 59 61 60 if (path == NULL) { … … 63 62 return NULL; 64 63 } 64 65 if (s->path) AUBIO_FREE(s->path); 66 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 67 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 65 68 66 69 s->samplerate = 0; … … 107 110 } 108 111 109 uint_t aubio_sink_sndfile_get_samplerate( aubio_sink_sndfile_t *s)112 uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s) 110 113 { 111 114 return s->samplerate; 112 115 } 113 116 114 uint_t aubio_sink_sndfile_get_channels( aubio_sink_sndfile_t *s)117 uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s) 115 118 { 116 119 return s->channels; … … 220 223 void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){ 221 224 if (!s) return; 225 if (s->path) AUBIO_FREE(s->path); 222 226 aubio_sink_sndfile_close(s); 223 227 AUBIO_FREE(s->scratch_data); -
TabularUnified src/io/sink_sndfile.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/sink_wavwrite.c ¶
r60fc05b rf264b17 78 78 } 79 79 80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(c har_t * path, uint_t samplerate) {80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samplerate) { 81 81 aubio_sink_wavwrite_t * s = AUBIO_NEW(aubio_sink_wavwrite_t); 82 82 … … 90 90 } 91 91 92 s->path = path; 92 if (s->path) AUBIO_FREE(s->path); 93 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 94 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 95 93 96 s->max_size = MAX_SIZE; 94 97 s->bitspersample = 16; … … 143 146 } 144 147 145 uint_t aubio_sink_wavwrite_get_samplerate( aubio_sink_wavwrite_t *s)148 uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s) 146 149 { 147 150 return s->samplerate; 148 151 } 149 152 150 uint_t aubio_sink_wavwrite_get_channels( aubio_sink_wavwrite_t *s)153 uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s) 151 154 { 152 155 return s->channels; … … 288 291 if (!s) return; 289 292 aubio_sink_wavwrite_close(s); 293 if (s->path) AUBIO_FREE(s->path); 290 294 AUBIO_FREE(s->scratch_data); 291 295 AUBIO_FREE(s); -
TabularUnified src/io/sink_wavwrite.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/source.c ¶
r60fc05b rf264b17 41 41 typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s); 42 42 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s); 43 typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s); 43 44 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek); 44 45 typedef uint_t (*aubio_source_close_t)(aubio_source_t * s); … … 51 52 aubio_source_get_samplerate_t s_get_samplerate; 52 53 aubio_source_get_channels_t s_get_channels; 54 aubio_source_get_duration_t s_get_duration; 53 55 aubio_source_seek_t s_seek; 54 56 aubio_source_close_t s_close; … … 56 58 }; 57 59 58 aubio_source_t * new_aubio_source(c har_t * uri, uint_t samplerate, uint_t hop_size) {60 aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) { 59 61 aubio_source_t * s = AUBIO_NEW(aubio_source_t); 60 #if HAVE_LIBAV62 #ifdef HAVE_LIBAV 61 63 s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); 62 64 if (s->source) { … … 65 67 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels); 66 68 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate); 69 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration); 67 70 s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); 68 71 s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close); … … 78 81 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels); 79 82 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate); 83 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration); 80 84 s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); 81 85 s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close); … … 84 88 } 85 89 #endif /* HAVE_SOURCE_APPLE_AUDIO */ 86 #if HAVE_SNDFILE90 #ifdef HAVE_SNDFILE 87 91 s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); 88 92 if (s->source) { … … 91 95 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels); 92 96 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate); 97 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration); 93 98 s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); 94 99 s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close); … … 97 102 } 98 103 #endif /* HAVE_SNDFILE */ 99 #if HAVE_WAVREAD104 #ifdef HAVE_WAVREAD 100 105 s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size); 101 106 if (s->source) { … … 104 109 s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels); 105 110 s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate); 111 s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration); 106 112 s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek); 107 113 s->s_close = (aubio_source_close_t)(aubio_source_wavread_close); … … 142 148 } 143 149 150 uint_t aubio_source_get_duration(aubio_source_t *s) { 151 return s->s_get_duration((void *)s->source); 152 } 153 144 154 uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) { 145 155 return s->s_seek((void *)s->source, seek); -
TabularUnified src/io/source.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/source_apple_audio.c ¶
r60fc05b rf264b17 52 52 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples); 53 53 extern void freeAudioBufferList(AudioBufferList *bufferList); 54 extern CFURLRef getURLFromPath(const char * path);54 extern CFURLRef createURLFromPath(const char * path); 55 55 char_t *getPrintableOSStatusError(char_t *str, OSStatus error); 56 56 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)57 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path); 58 59 aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, uint_t samplerate, uint_t block_size) 60 60 { 61 61 aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t); … … 80 80 s->block_size = block_size; 81 81 s->samplerate = samplerate; 82 s->path = path;83 82 84 83 if ( aubio_source_apple_audio_open ( s, path ) ) { … … 92 91 } 93 92 94 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, c har_t * path)93 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path) 95 94 { 96 95 OSStatus err = noErr; 97 96 UInt32 propSize; 98 s->path = path; 97 98 if (s->path) AUBIO_FREE(s->path); 99 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 100 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 99 101 100 102 // open the resource url 101 CFURLRef fileURL = getURLFromPath(path);103 CFURLRef fileURL = createURLFromPath(s->path); 102 104 err = ExtAudioFileOpenURL(fileURL, &s->audioFile); 105 CFRelease(fileURL); 103 106 if (err == -43) { 104 107 AUBIO_ERR("source_apple_audio: Failed opening %s, " … … 293 296 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 294 297 aubio_source_apple_audio_close (s); 298 if (s->path) AUBIO_FREE(s->path); 295 299 freeAudioBufferList(&s->bufferList); 296 300 AUBIO_FREE(s); … … 308 312 } 309 313 // check if we are not seeking out of the file 310 SInt64 fileLengthFrames = 0; 311 UInt32 propSize = sizeof(fileLengthFrames); 312 ExtAudioFileGetProperty(s->audioFile, 313 kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames); 314 uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s); 314 315 // compute position in the source file, before resampling 315 316 smpl_t ratio = s->source_samplerate * 1. / s->samplerate; … … 352 353 } 353 354 354 uint_t aubio_source_apple_audio_get_samplerate( aubio_source_apple_audio_t * s) {355 uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s) { 355 356 return s->samplerate; 356 357 } 357 358 358 uint_t aubio_source_apple_audio_get_channels( aubio_source_apple_audio_t * s) {359 uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s) { 359 360 return s->channels; 360 361 } 361 362 363 uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) { 364 SInt64 fileLengthFrames = 0; 365 UInt32 propSize = sizeof(fileLengthFrames); 366 OSStatus err = ExtAudioFileGetProperty(s->audioFile, 367 kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames); 368 if (err) { 369 char_t errorstr[20]; 370 AUBIO_ERROR("source_apple_audio: Failed getting %s duration, " 371 "error in ExtAudioFileGetProperty (%s)\n", s->path, 372 getPrintableOSStatusError(errorstr, err)); 373 return err; 374 } 375 return (uint_t)fileLengthFrames; 376 } 377 362 378 #endif /* HAVE_SOURCE_APPLE_AUDIO */ -
TabularUnified src/io/source_apple_audio.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/source_avcodec.c ¶
r60fc05b rf264b17 24 24 #ifdef HAVE_LIBAV 25 25 26 // determine whether we use libavformat from ffmpe or libav 27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99) 26 // determine whether we use libavformat from ffmpeg or from libav 27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 ) 28 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100 29 #define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \ 30 (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \ 31 || (LIBAVFORMAT_VERSION_MAJOR == 56) \ 32 || (LIBAVFORMAT_VERSION_MAJOR == 57 && LIBAVFORMAT_VERSION_MINOR < 2) \ 33 ) 28 34 29 35 #include <libavcodec/avcodec.h> … … 67 73 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples); 68 74 69 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplerate, uint_t hop_size) { 75 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s); 76 77 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) { 78 char proto[20], authorization[256], hostname[128], uripath[256]; 79 int proto_size = 20, authorization_size = 256, hostname_size = 128, 80 *port_ptr = 0, path_size = 256; 81 av_url_split(proto, proto_size, authorization, authorization_size, hostname, 82 hostname_size, port_ptr, uripath, path_size, s->path); 83 if (strlen(proto)) { 84 return 1; 85 } 86 return 0; 87 } 88 89 90 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { 70 91 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 71 92 int err; … … 85 106 s->hop_size = hop_size; 86 107 s->channels = 1; 87 s->path = path; 108 109 if (s->path) AUBIO_FREE(s->path); 110 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 111 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 88 112 89 113 // register all formats and codecs 90 114 av_register_all(); 91 115 92 // if path[0] != '/' 93 //avformat_network_init(); 116 if (aubio_source_avcodec_has_network_url(s)) { 117 avformat_network_init(); 118 } 94 119 95 120 // try opening the file and get some info about it … … 104 129 105 130 // try to make sure max_analyze_duration is big enough for most songs 106 #if FFMPEG_LIBAVFORMAT 131 #if FFMPEG_LIBAVFORMAT_MAX_DUR2 107 132 avFormatCtx->max_analyze_duration2 *= 100; 108 133 #else … … 164 189 165 190 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;191 s->samplerate = s->input_samplerate; 192 } else { 193 s->samplerate = samplerate; 194 } 170 195 171 196 if (s->samplerate > s->input_samplerate) { … … 300 325 s->output = output; 301 326 302 av_ free_packet(&avPacket);327 av_packet_unref(&avPacket); 303 328 } 304 329 … … 370 395 } 371 396 372 uint_t aubio_source_avcodec_get_samplerate( aubio_source_avcodec_t * s) {397 uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s) { 373 398 return s->samplerate; 374 399 } 375 400 376 uint_t aubio_source_avcodec_get_channels( aubio_source_avcodec_t * s) {401 uint_t aubio_source_avcodec_get_channels(const aubio_source_avcodec_t * s) { 377 402 return s->input_channels; 378 403 } … … 398 423 } 399 424 425 uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) { 426 if (s && &(s->avFormatCtx) != NULL) { 427 int64_t duration = s->avFormatCtx->duration; 428 return s->samplerate * ((uint_t)duration / 1e6 ); 429 } 430 return 0; 431 } 432 400 433 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { 401 434 if (s->avr != NULL) { … … 425 458 av_frame_free( &(s->avFrame) ); 426 459 } 460 if (s->path) AUBIO_FREE(s->path); 427 461 s->avFrame = NULL; 428 462 AUBIO_FREE(s); -
TabularUnified src/io/source_avcodec.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/source_sndfile.c ¶
r60fc05b rf264b17 36 36 #define MAX_SIZE 4096 37 37 #define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE 38 39 #if !HAVE_AUBIO_DOUBLE 40 #define aubio_sf_read_smpl sf_read_float 41 #else /* HAVE_AUBIO_DOUBLE */ 42 #define aubio_sf_read_smpl sf_read_double 43 #endif /* HAVE_AUBIO_DOUBLE */ 38 44 39 45 struct _aubio_source_sndfile_t { … … 48 54 int input_channels; 49 55 int input_format; 56 int duration; 50 57 51 58 // resampling stuff … … 59 66 // some temporary memory for sndfile to write at 60 67 uint_t scratch_size; 61 float *scratch_data;68 smpl_t *scratch_data; 62 69 }; 63 70 64 aubio_source_sndfile_t * new_aubio_source_sndfile(c har_t * path, uint_t samplerate, uint_t hop_size) {71 aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t samplerate, uint_t hop_size) { 65 72 aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t); 66 73 SF_INFO sfinfo; … … 81 88 s->hop_size = hop_size; 82 89 s->channels = 1; 83 s->path = path; 90 91 if (s->path) AUBIO_FREE(s->path); 92 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 93 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 84 94 85 95 // try opening the file, getting the info in sfinfo … … 97 107 s->input_channels = sfinfo.channels; 98 108 s->input_format = sfinfo.format; 109 s->duration = sfinfo.frames; 99 110 100 111 if (samplerate == 0) { 101 s amplerate = s->input_samplerate;112 s->samplerate = s->input_samplerate; 102 113 //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate); 103 } 104 s->samplerate = samplerate; 114 } else { 115 s->samplerate = samplerate; 116 } 105 117 /* compute input block size required before resampling */ 106 s->ratio = s->samplerate/( float)s->input_samplerate;118 s->ratio = s->samplerate/(smpl_t)s->input_samplerate; 107 119 s->input_hop_size = (uint_t)FLOOR(s->hop_size / s->ratio + .5); 108 120 … … 129 141 s->input_samplerate, s->samplerate); 130 142 } 143 s->duration = (uint_t)FLOOR(s->duration * s->ratio); 131 144 } 132 145 #else … … 139 152 /* allocate data for de/interleaving reallocated when needed. */ 140 153 s->scratch_size = s->input_hop_size * s->input_channels; 141 s->scratch_data = AUBIO_ARRAY( float,s->scratch_size);154 s->scratch_data = AUBIO_ARRAY(smpl_t, s->scratch_size); 142 155 143 156 return s; … … 153 166 uint_t i,j, input_channels = s->input_channels; 154 167 /* read from file into scratch_data */ 155 sf_count_t read_samples = sf_read_float(s->handle, s->scratch_data, s->scratch_size);168 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 156 169 157 170 /* where to store de-interleaved data */ … … 194 207 uint_t i,j, input_channels = s->input_channels; 195 208 /* do actual reading */ 196 sf_count_t read_samples = sf_read_float(s->handle, s->scratch_data, s->scratch_size);209 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 197 210 198 211 /* where to store de-interleaved data */ … … 214 227 for (j = 0; j < read_samples / input_channels; j++) { 215 228 for (i = 0; i < read_data->height; i++) { 216 ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];229 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 217 230 } 218 231 } … … 222 235 for (j = 0; j < read_samples / input_channels; j++) { 223 236 for (i = 0; i < input_channels; i++) { 224 ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];237 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 225 238 } 226 239 } … … 232 245 for (j = 0; j < read_samples / input_channels; j++) { 233 246 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)];247 ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)]; 235 248 } 236 249 } … … 261 274 uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) { 262 275 return s->input_channels; 276 } 277 278 uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) { 279 if (s && s->duration) { 280 return s->duration; 281 } 282 return 0; 263 283 } 264 284 … … 300 320 } 301 321 #endif /* HAVE_SAMPLERATE */ 322 if (s->path) AUBIO_FREE(s->path); 302 323 AUBIO_FREE(s->scratch_data); 303 324 AUBIO_FREE(s); -
TabularUnified src/io/source_sndfile.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/source_wavread.c ¶
r60fc05b rf264b17 53 53 uint_t eof; 54 54 55 uint_t duration; 56 55 57 size_t seek_start; 56 58 … … 68 70 } 69 71 70 aubio_source_wavread_t * new_aubio_source_wavread(c har_t * path, uint_t samplerate, uint_t hop_size) {72 aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) { 71 73 aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t); 72 74 size_t bytes_read = 0, bytes_expected = 44; 73 75 unsigned char buf[5]; 74 unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size;76 unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size; 75 77 76 78 if (path == NULL) { … … 87 89 } 88 90 89 s->path = path; 91 if (s->path) AUBIO_FREE(s->path); 92 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 93 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); 94 90 95 s->samplerate = samplerate; 91 96 s->hop_size = hop_size; … … 213 218 // Subchunk2Size 214 219 bytes_read += fread(buf, 1, 4, s->fid); 220 duration = read_little_endian(buf, 4) / blockalign; 221 215 222 //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24); 216 223 //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path); … … 232 239 s->blockalign= blockalign; 233 240 s->bitspersample = bitspersample; 241 242 s->duration = duration; 234 243 235 244 s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE); … … 372 381 } 373 382 383 uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t * s) { 384 if (s && s->duration) { 385 return s->duration; 386 } 387 return 0; 388 } 389 374 390 uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) { 375 391 if (!s->fid) { … … 389 405 if (s->short_output) AUBIO_FREE(s->short_output); 390 406 if (s->output) del_fmat(s->output); 407 if (s->path) AUBIO_FREE(s->path); 391 408 AUBIO_FREE(s); 392 409 } -
TabularUnified src/io/source_wavread.h ¶
r60fc05b rf264b17 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 */ -
TabularUnified src/io/utils_apple_audio.c ¶
r60fc05b rf264b17 34 34 } 35 35 36 CFURLRef getURLFromPath(const char * path) {36 CFURLRef createURLFromPath(const char * path) { 37 37 CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault, 38 38 path, kCFStringEncodingUTF8); 39 39 40 returnCFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,40 CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath, 41 41 kCFURLPOSIXPathStyle, false); 42 CFRelease(cfTotalPath); 43 return url; 42 44 } 43 45
Note: See TracChangeset
for help on using the changeset viewer.