Changes in / [d327b6f:9630fa8]
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
.travis.yml
rd327b6f r9630fa8 19 19 os: linux 20 20 compiler: gcc 21 env: HAVE_AUBIO_DOUBLE=1 CFLAGS="-O3" WAFOPTS="--enable-fftw3 --disable-avcodec"21 env: HAVE_AUBIO_DOUBLE=1 CFLAGS="-O3" WAFOPTS="--enable-fftw3" 22 22 - python: 2.7 23 23 os: linux -
src/aubio_priv.h
rd327b6f r9630fa8 325 325 #endif 326 326 327 #if !defined(_MSC_VER)328 #define AUBIO_STRERROR(errno,buf,len) strerror_r(errno, buf, len)329 #else330 #define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)331 #endif332 333 327 /* handy shortcuts */ 334 328 #define DB2LIN(g) (POW(10.0,(g)*0.05f)) -
src/io/ioutils.c
rd327b6f r9630fa8 20 20 21 21 #include "aubio_priv.h" 22 #include "fmat.h"23 22 24 23 uint_t … … 52 51 } 53 52 return AUBIO_OK; 54 }55 56 uint_t57 aubio_source_validate_input_length(const char_t *kind, const char_t *path,58 uint_t hop_size, uint_t read_data_length)59 {60 uint_t length = hop_size;61 if (hop_size < read_data_length) {62 AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"63 " hop_size is %d\n", kind, path, read_data_length, hop_size);64 } else if (hop_size > read_data_length) {65 AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"66 " a buffer of length %d\n", kind, path, hop_size, read_data_length);67 length = read_data_length;68 }69 return length;70 }71 72 uint_t73 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,74 uint_t source_channels, uint_t read_data_height)75 {76 uint_t channels = source_channels;77 if (read_data_height < source_channels) {78 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"79 " but found output of height %d\n", kind, path, source_channels,80 read_data_height);81 channels = read_data_height;82 } else if (read_data_height > source_channels) {83 // do not show a warning when trying to read into more channels than84 // the input source.85 #if 086 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"87 " but found output of height %d\n", kind, path, source_channels,88 read_data_height);89 #endif90 channels = source_channels;91 }92 return channels;93 }94 95 void96 aubio_source_pad_output (fvec_t *read_data, uint_t source_read)97 {98 if (source_read < read_data->length) {99 AUBIO_MEMSET(read_data->data + source_read, 0,100 (read_data->length - source_read) * sizeof(smpl_t));101 }102 }103 104 void105 aubio_source_pad_multi_output (fmat_t *read_data,106 uint_t source_channels, uint_t source_read) {107 uint_t i;108 if (source_read < read_data->length) {109 for (i = 0; i < read_data->height; i++) {110 AUBIO_MEMSET(read_data->data[i] + source_read, 0,111 (read_data->length - source_read) * sizeof(smpl_t));112 }113 }114 115 // destination matrix has more channels than the file116 // copy channels from the source to extra output channels117 if (read_data->height > source_channels) {118 for (i = source_channels; i < read_data->height; i++) {119 AUBIO_MEMCPY(read_data->data[i], read_data->data[i % source_channels],120 sizeof(smpl_t) * read_data->length);121 }122 }123 53 } 124 54 -
src/io/ioutils.h
rd327b6f r9630fa8 54 54 uint_t channels); 55 55 56 /** validate length of source output 57 58 \param kind the object kind to report on 59 \param path the path to report on 60 \param hop_size number of frames to be read 61 \param read_data_length actual length of input 62 63 \return hop_size or the maximum number of frames that can be written 64 */ 65 uint_t 66 aubio_source_validate_input_length(const char_t *kind, const char_t *path, 67 uint_t hop_size, uint_t read_data_length); 68 69 /** validate height of source output 70 71 \param kind the object kind to report on 72 \param path the path to report on 73 \param source_channels maximum number of channels that can be written 74 \param read_data_height actual height of input 75 76 \return write_data_height or the maximum number of channels 77 */ 78 uint_t 79 aubio_source_validate_input_channels(const char_t *kind, const char_t *path, 80 uint_t source_channels, uint_t read_data_height); 81 82 /** pad end of source output vector with zeroes 83 84 \param read_data output vector to pad 85 \param source_read number of frames read 86 87 */ 88 void 89 aubio_source_pad_output (fvec_t *read_data, uint_t source_read); 90 91 /** pad end of source output matrix with zeroes 92 93 \param read_data output matrix to pad 94 \param source_channels number of channels in the source 95 \param source_read number of frames read 96 97 */ 98 void 99 aubio_source_pad_multi_output (fmat_t *read_data, uint_t source_channels, 100 uint_t source_read); 101 102 /** validate length of sink input 56 /** validate length of input 103 57 104 58 \param kind the object kind to report on 105 59 \param path the path to report on 106 60 \param max_size maximum number of frames that can be written 107 \param write_data_length actual length of input 61 \param write_data_length actual length of input vector/matrix 108 62 \param write number of samples asked 109 63 … … 114 68 uint_t max_size, uint_t write_data_length, uint_t write); 115 69 116 /** validate height of sinkinput70 /** validate height of input 117 71 118 72 \param kind the object kind to report on 119 73 \param path the path to report on 120 \param sink_channelsmaximum number of channels that can be written74 \param max_size maximum number of channels that can be written 121 75 \param write_data_height actual height of input matrix 122 76 -
src/io/sink_vorbis.c
rd327b6f r9630fa8 29 29 #ifdef HAVE_VORBISENC 30 30 31 #include "io/ioutils.h" 31 32 #include "fmat.h" 32 #include "io/ioutils.h"33 33 34 34 #include <vorbis/vorbisenc.h> … … 37 37 #include <time.h> // time 38 38 39 #define MAX_SIZE 409639 #define MAX_SIZE 2048 40 40 41 41 struct _aubio_sink_vorbis_t { … … 64 64 void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s); 65 65 66 static uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s);67 68 66 aubio_sink_vorbis_t * new_aubio_sink_vorbis (const char_t *uri, 69 67 uint_t samplerate) … … 120 118 s->fid = fopen((const char *)s->path, "wb"); 121 119 if (!s->fid) { 122 char errorstr[256]; 123 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 124 AUBIO_ERR("sink_vorbis: Error opening file \'%s\' (%s)\n", 125 s->path, errorstr); 120 AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n", 121 s->path, strerror(errno)); 126 122 return AUBIO_FAIL; 127 123 } … … 148 144 // write header 149 145 { 146 int ret = 0; 147 size_t wrote; 150 148 ogg_packet header; 151 149 ogg_packet header_comm; … … 162 160 while (1) 163 161 { 164 if (!ogg_stream_flush(&s->os, &s->og)) break; 165 if (aubio_sink_vorbis_write_page(s)) return AUBIO_FAIL; 162 ret = ogg_stream_flush(&s->os, &s->og); 163 if (ret==0) break; 164 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid); 165 ret = (wrote == (unsigned)s->og.header_len); 166 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid); 167 ret &= (wrote == (unsigned)s->og.body_len); 168 if (ret == 0) { 169 AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n", 170 s->path, strerror(errno)); 171 return AUBIO_FAIL; 172 } 166 173 } 167 174 } … … 205 212 } 206 213 207 static 208 uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s){214 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s) 215 { 209 216 int result; 210 217 size_t wrote; 211 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);212 result = (wrote == (unsigned)s->og.header_len);213 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid);214 result &= (wrote == (unsigned)s->og.body_len);215 if (result == 0) {216 char errorstr[256];217 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));218 AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n",219 s->path, errorstr);220 return AUBIO_FAIL;221 }222 return AUBIO_OK;223 }224 225 static226 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)227 {228 218 // pre-analysis 229 219 while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) { … … 237 227 238 228 while (1) { 239 if (!ogg_stream_pageout (&s->os, &s->og)) break; 240 aubio_sink_vorbis_write_page(s); 229 result = ogg_stream_pageout (&s->os, &s->og); 230 if (result == 0) break; 231 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid); 232 result = (wrote == (unsigned)s->og.header_len); 233 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid); 234 result &= (wrote == (unsigned)s->og.body_len); 235 if (result == 0) { 236 AUBIO_WRN("sink_vorbis: failed writing \'%s\' to disk (%s)\n", 237 s->path, strerror(errno)); 238 } 241 239 if (ogg_page_eos(&s->og)) break; 242 240 } … … 293 291 } 294 292 // tell vorbis how many frames were written 295 vorbis_analysis_wrote(&s->vd, (long) length);293 vorbis_analysis_wrote(&s->vd, (long)write); 296 294 } 297 295 … … 308 306 309 307 if (s->fid && fclose(s->fid)) { 310 char errorstr[256]; 311 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 312 AUBIO_ERR("sink_vorbis: Error closing file \'%s\' (%s)\n", 313 s->path, errorstr); 308 AUBIO_ERR("sink_vorbis: Error closing file %s (%s)\n", 309 s->path, strerror(errno)); 314 310 return AUBIO_FAIL; 315 311 } -
src/io/sink_wavwrite.c
rd327b6f r9630fa8 163 163 unsigned char buf[5]; 164 164 uint_t byterate, blockalign; 165 size_t written = 0;166 165 167 166 /* open output file */ 168 167 s->fid = fopen((const char *)s->path, "wb"); 169 168 if (!s->fid) { 170 char errorstr[256]; 171 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 172 AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr); 169 AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno)); 173 170 goto beach; 174 171 } 175 172 176 173 // ChunkID 177 written +=fwrite("RIFF", 4, 1, s->fid);174 fwrite("RIFF", 4, 1, s->fid); 178 175 179 176 // ChunkSize (0 for now, actual size will be written in _close) 180 written +=fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);177 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 181 178 182 179 // Format 183 written +=fwrite("WAVE", 4, 1, s->fid);180 fwrite("WAVE", 4, 1, s->fid); 184 181 185 182 // Subchunk1ID 186 written +=fwrite("fmt ", 4, 1, s->fid);183 fwrite("fmt ", 4, 1, s->fid); 187 184 188 185 // Subchunk1Size 189 written +=fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);186 fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid); 190 187 191 188 // AudioFormat 192 written +=fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);189 fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid); 193 190 194 191 // NumChannels 195 written +=fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);192 fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid); 196 193 197 194 // SampleRate 198 written +=fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);195 fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid); 199 196 200 197 // ByteRate 201 198 byterate = s->samplerate * s->channels * s->bitspersample / 8; 202 written +=fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);199 fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid); 203 200 204 201 // BlockAlign 205 202 blockalign = s->channels * s->bitspersample / 8; 206 written +=fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);203 fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid); 207 204 208 205 // BitsPerSample 209 written +=fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);206 fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid); 210 207 211 208 // Subchunk2ID 212 written +=fwrite("data", 4, 1, s->fid);209 fwrite("data", 4, 1, s->fid); 213 210 214 211 // Subchunk1Size (0 for now, actual size will be written in _close) 215 written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 216 217 // fwrite(*, *, 1, s->fid) was called 13 times, check success 218 if (written != 13) { 219 char errorstr[256]; 220 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 221 AUBIO_WRN("sink_wavwrite: writing header to %s failed, expected %d" 222 " write but got only %d (%s)\n", s->path, 13, written, errorstr); 223 return AUBIO_FAIL; 224 } 212 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 225 213 226 214 s->scratch_size = s->max_size * s->channels; … … 239 227 } 240 228 241 static242 void aubio_sink_wavwrite_write_frames(aubio_sink_wavwrite_t *s, uint_t write)243 {244 uint_t written_frames = 0;245 246 written_frames = fwrite(s->scratch_data, 2 * s->channels, write, s->fid);247 248 if (written_frames != write) {249 char errorstr[256];250 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));251 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, but only %d"252 " could be written (%s)\n", write, s->path, written_frames, errorstr);253 }254 s->total_frames_written += written_frames;255 }256 229 257 230 void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){ 258 uint_t c = 0, i = 0 ;231 uint_t c = 0, i = 0, written_frames = 0; 259 232 uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path, 260 233 s->max_size, write_data->length, write); … … 265 238 } 266 239 } 267 268 aubio_sink_wavwrite_write_frames(s, length); 240 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 241 242 if (written_frames != write) { 243 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 244 "but only %d could be written\n", write, s->path, written_frames); 245 } 246 s->total_frames_written += written_frames; 247 return; 269 248 } 270 249 271 250 void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){ 272 uint_t c = 0, i = 0 ;251 uint_t c = 0, i = 0, written_frames = 0; 273 252 274 253 uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path, … … 282 261 } 283 262 } 284 285 aubio_sink_wavwrite_write_frames(s, length); 263 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 264 265 if (written_frames != write * s->channels) { 266 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 267 "but only %d could be written\n", write, s->path, written_frames / s->channels); 268 } 269 s->total_frames_written += written_frames; 270 return; 286 271 } 287 272 … … 289 274 uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8; 290 275 unsigned char buf[5]; 291 size_t written = 0, err = 0;292 276 if (!s->fid) return AUBIO_FAIL; 293 277 // ChunkSize 294 err +=fseek(s->fid, 4, SEEK_SET);295 written +=fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);278 fseek(s->fid, 4, SEEK_SET); 279 fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid); 296 280 // Subchunk2Size 297 err += fseek(s->fid, 40, SEEK_SET); 298 written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid); 299 if (written != 2 || err != 0) { 300 char errorstr[256]; 301 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 302 AUBIO_WRN("sink_wavwrite: updating header of %s failed, expected %d" 303 " write but got only %d (%s)\n", s->path, 2, written, errorstr); 304 } 281 fseek(s->fid, 40, SEEK_SET); 282 fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid); 305 283 // close file 306 284 if (fclose(s->fid)) { 307 char errorstr[256]; 308 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 309 AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr); 285 AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno)); 310 286 } 311 287 s->fid = NULL; -
src/io/source_apple_audio.c
rd327b6f r9630fa8 25 25 #include "fvec.h" 26 26 #include "fmat.h" 27 #include "ioutils.h"28 27 #include "io/source_apple_audio.h" 29 28 … … 211 210 uint_t c, v; 212 211 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 213 uint_t length = aubio_source_validate_input_length("source_apple_audio",214 s->path, s->block_size, read_to->length);215 212 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 216 213 217 length = MIN(loadedPackets, length); 218 219 for (v = 0; v < length; v++) { 214 for (v = 0; v < loadedPackets; v++) { 220 215 read_to->data[v] = 0.; 221 216 for (c = 0; c < s->channels; c++) { … … 225 220 } 226 221 // short read, fill with zeros 227 aubio_source_pad_output(read_to, length); 228 229 *read = (uint_t)length; 222 if (loadedPackets < s->block_size) { 223 for (v = loadedPackets; v < s->block_size; v++) { 224 read_to->data[v] = 0.; 225 } 226 } 227 228 *read = (uint_t)loadedPackets; 229 return; 230 230 } 231 231 232 232 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) { 233 233 uint_t c, v; 234 uint_t length = aubio_source_validate_input_length("source_apple_audio",235 s->path, s->block_size, read_to->length);236 uint_t channels = aubio_source_validate_input_channels("source_apple_audio",237 s->path, s->channels, read_to->height);238 234 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 239 235 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 240 236 241 length = MIN(loadedPackets, length); 242 243 for (v = 0; v < length; v++) { 244 for (c = 0; c < channels; c++) { 237 for (v = 0; v < loadedPackets; v++) { 238 for (c = 0; c < read_to->height; c++) { 245 239 read_to->data[c][v] = data[ v * s->channels + c]; 246 240 } 247 241 } 248 249 aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length); 250 251 *read = (uint_t)length; 242 // if read_data has more channels than the file 243 if (read_to->height > s->channels) { 244 // copy last channel to all additional channels 245 for (v = 0; v < loadedPackets; v++) { 246 for (c = s->channels; c < read_to->height; c++) { 247 read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)]; 248 } 249 } 250 } 251 // short read, fill with zeros 252 if (loadedPackets < s->block_size) { 253 for (v = loadedPackets; v < s->block_size; v++) { 254 for (c = 0; c < read_to->height; c++) { 255 read_to->data[c][v] = 0.; 256 } 257 } 258 } 259 260 *read = (uint_t)loadedPackets; 261 return; 252 262 } 253 263 -
src/io/source_avcodec.c
rd327b6f r9630fa8 61 61 #include "fvec.h" 62 62 #include "fmat.h" 63 #include "ioutils.h"64 63 #include "source_avcodec.h" 65 64 … … 490 489 uint_t end = 0; 491 490 uint_t total_wrote = 0; 492 uint_t length = aubio_source_validate_input_length("source_avcodec", s->path, 493 s->hop_size, read_data->length); 494 while (total_wrote < length) { 495 end = MIN(s->read_samples - s->read_index, length - total_wrote); 491 while (total_wrote < s->hop_size) { 492 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 496 493 for (i = 0; i < end; i++) { 497 494 read_data->data[i + total_wrote] = 0.; … … 503 500 } 504 501 total_wrote += end; 505 if (total_wrote < length) {502 if (total_wrote < s->hop_size) { 506 503 uint_t avcodec_read = 0; 507 504 aubio_source_avcodec_readframe(s, &avcodec_read); … … 515 512 } 516 513 } 517 518 aubio_source_pad_output(read_data, total_wrote); 519 514 if (total_wrote < s->hop_size) { 515 for (i = total_wrote; i < s->hop_size; i++) { 516 read_data->data[i] = 0.; 517 } 518 } 520 519 *read = total_wrote; 521 520 } … … 526 525 uint_t end = 0; 527 526 uint_t total_wrote = 0; 528 uint_t length = aubio_source_validate_input_length("source_wavread", s->path, 529 s->hop_size, read_data->length); 530 uint_t channels = aubio_source_validate_input_channels("source_wavread", 531 s->path, s->input_channels, read_data->height); 532 while (total_wrote < length) { 533 end = MIN(s->read_samples - s->read_index, length - total_wrote); 534 for (j = 0; j < channels; j++) { 527 while (total_wrote < s->hop_size) { 528 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 529 for (j = 0; j < read_data->height; j++) { 535 530 for (i = 0; i < end; i++) { 536 531 read_data->data[j][i + total_wrote] = … … 539 534 } 540 535 total_wrote += end; 541 if (total_wrote < length) {536 if (total_wrote < s->hop_size) { 542 537 uint_t avcodec_read = 0; 543 538 aubio_source_avcodec_readframe(s, &avcodec_read); … … 551 546 } 552 547 } 553 554 aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote); 555 548 if (total_wrote < s->hop_size) { 549 for (j = 0; j < read_data->height; j++) { 550 for (i = total_wrote; i < s->hop_size; i++) { 551 read_data->data[j][i] = 0.; 552 } 553 } 554 } 556 555 *read = total_wrote; 557 556 } -
src/io/source_sndfile.c
rd327b6f r9630fa8 27 27 #include "fvec.h" 28 28 #include "fmat.h" 29 #include "ioutils.h"30 29 #include "source_sndfile.h" 31 30 … … 171 170 uint_t i,j, input_channels = s->input_channels; 172 171 /* read from file into scratch_data */ 173 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 174 s->hop_size, read_data->length); 175 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 176 s->input_channels * length); 177 178 length = MIN(read_samples / s->input_channels, length); 172 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 179 173 180 174 /* where to store de-interleaved data */ … … 190 184 191 185 /* de-interleaving and down-mixing data */ 192 for (j = 0; j < length; j++) {186 for (j = 0; j < read_samples / input_channels; j++) { 193 187 ptr_data[j] = 0; 194 188 for (i = 0; i < input_channels; i++) { … … 204 198 #endif /* HAVE_SAMPLERATE */ 205 199 206 *read = (int)FLOOR(s->ratio * length + .5); 207 208 aubio_source_pad_output (read_data, *read); 200 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 201 202 if (*read < s->hop_size) { 203 for (j = *read; j < s->hop_size; j++) { 204 read_data->data[j] = 0; 205 } 206 } 209 207 210 208 } … … 213 211 uint_t i,j, input_channels = s->input_channels; 214 212 /* do actual reading */ 215 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 216 s->hop_size, read_data->length); 217 uint_t channels = aubio_source_validate_input_channels("source_sndfile", 218 s->path, s->input_channels, read_data->height); 219 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 220 length * s->input_channels); 221 222 length = MIN(read_samples / s->input_channels, length); 213 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 223 214 224 215 /* where to store de-interleaved data */ … … 233 224 } 234 225 235 for (j = 0; j < length; j++) { 236 for (i = 0; i < channels; i++) { 237 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 226 if (read_data->height < input_channels) { 227 // destination matrix has less channels than the file; copy only first 228 // channels of the file, de-interleaving data 229 for (j = 0; j < read_samples / input_channels; j++) { 230 for (i = 0; i < read_data->height; i++) { 231 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 232 } 233 } 234 } else { 235 // destination matrix has as many or more channels than the file; copy each 236 // channel from the file to the destination matrix, de-interleaving data 237 for (j = 0; j < read_samples / input_channels; j++) { 238 for (i = 0; i < input_channels; i++) { 239 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 240 } 241 } 242 } 243 244 if (read_data->height > input_channels) { 245 // destination matrix has more channels than the file; copy last channel 246 // of the file to each additional channels, de-interleaving data 247 for (j = 0; j < read_samples / input_channels; j++) { 248 for (i = input_channels; i < read_data->height; i++) { 249 ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)]; 250 } 238 251 } 239 252 } … … 252 265 #endif /* HAVE_SAMPLERATE */ 253 266 254 *read = (int)FLOOR(s->ratio * length + .5); 255 256 aubio_source_pad_multi_output(read_data, input_channels, *read); 267 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 268 269 if (*read < s->hop_size) { 270 for (i = 0; i < read_data->height; i++) { 271 for (j = *read; j < s->hop_size; j++) { 272 read_data->data[i][j] = 0.; 273 } 274 } 275 } 276 257 277 } 258 278 -
src/io/source_wavread.c
rd327b6f r9630fa8 25 25 #include "fvec.h" 26 26 #include "fmat.h" 27 #include "ioutils.h"28 27 #include "source_wavread.h" 29 28 … … 349 348 uint_t end = 0; 350 349 uint_t total_wrote = 0; 351 uint_t length = aubio_source_validate_input_length("source_wavread", s->path,352 s->hop_size, read_data->length);353 350 if (s->fid == NULL) { 354 351 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 356 353 return; 357 354 } 358 while (total_wrote < length) {359 end = MIN(s->read_samples - s->read_index, length- total_wrote);355 while (total_wrote < s->hop_size) { 356 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 360 357 for (i = 0; i < end; i++) { 361 358 read_data->data[i + total_wrote] = 0; … … 366 363 } 367 364 total_wrote += end; 368 if (total_wrote < length) {365 if (total_wrote < s->hop_size) { 369 366 uint_t wavread_read = 0; 370 367 aubio_source_wavread_readframe(s, &wavread_read); … … 378 375 } 379 376 } 380 381 aubio_source_pad_output (read_data, total_wrote); 382 377 if (total_wrote < s->hop_size) { 378 for (i = end; i < s->hop_size; i++) { 379 read_data->data[i] = 0.; 380 } 381 } 383 382 *read = total_wrote; 384 383 } … … 388 387 uint_t end = 0; 389 388 uint_t total_wrote = 0; 390 uint_t length = aubio_source_validate_input_length("source_wavread", s->path,391 s->hop_size, read_data->length);392 uint_t channels = aubio_source_validate_input_channels("source_wavread",393 s->path, s->input_channels, read_data->height);394 389 if (s->fid == NULL) { 395 390 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 397 392 return; 398 393 } 399 while (total_wrote < length) {400 end = MIN(s->read_samples - s->read_index, length- total_wrote);401 for (j = 0; j < channels; j++) {394 while (total_wrote < s->hop_size) { 395 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 396 for (j = 0; j < read_data->height; j++) { 402 397 for (i = 0; i < end; i++) { 403 398 read_data->data[j][i + total_wrote] = s->output->data[j][i]; … … 405 400 } 406 401 total_wrote += end; 407 if (total_wrote < length) {402 if (total_wrote < s->hop_size) { 408 403 uint_t wavread_read = 0; 409 404 aubio_source_wavread_readframe(s, &wavread_read); … … 417 412 } 418 413 } 419 420 aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote); 421 414 if (total_wrote < s->hop_size) { 415 for (j = 0; j < read_data->height; j++) { 416 for (i = end; i < s->hop_size; i++) { 417 read_data->data[j][i] = 0.; 418 } 419 } 420 } 422 421 *read = total_wrote; 423 422 } -
tests/src/io/base-source_custom.h
rd327b6f r9630fa8 94 94 if (read != hop_size) return 1; 95 95 96 // read again in undersized vector97 del_fvec(vec);98 vec = new_fvec(hop_size - 1);99 aubio_source_custom_do(s, vec, &read);100 if (read != hop_size - 1) return 1;101 102 // read again in oversized vector103 del_fvec(vec);104 vec = new_fvec(hop_size + 1);105 aubio_source_custom_do(s, vec, &read);106 if (read != hop_size) return 1;107 108 96 // seek to 0 109 97 if(aubio_source_custom_seek(s, 0)) return 1; 110 98 111 99 // read again as multiple channels 112 aubio_source_custom_do_multi(s, mat, &read);113 if (read != hop_size) return 1;114 115 // read again as multiple channels in an undersized matrix116 del_fmat(mat);117 mat = new_fmat(channels - 1, hop_size);118 aubio_source_custom_do_multi(s, mat, &read);119 if (read != hop_size) return 1;120 121 // read again as multiple channels in an undersized matrix122 del_fmat(mat);123 mat = new_fmat(channels, hop_size - 1);124 aubio_source_custom_do_multi(s, mat, &read);125 if (read != hop_size - 1) return 1;126 127 // read again as multiple channels in an oversized matrix128 del_fmat(mat);129 mat = new_fmat(channels + 1, hop_size);130 aubio_source_custom_do_multi(s, mat, &read);131 if (read != hop_size) return 1;132 133 // read again as multiple channels in an oversized matrix134 del_fmat(mat);135 mat = new_fmat(channels, hop_size + 1);136 100 aubio_source_custom_do_multi(s, mat, &read); 137 101 if (read != hop_size) return 1; -
tests/src/io/test-source.c
rd327b6f r9630fa8 90 90 if (read != hop_size) return 1; 91 91 92 // read again in undersized vector93 del_fvec(vec);94 vec = new_fvec(hop_size - 1);95 aubio_source_do(s, vec, &read);96 if (read != hop_size - 1) return 1;97 98 // read again in oversized vector99 del_fvec(vec);100 vec = new_fvec(hop_size + 1);101 aubio_source_do(s, vec, &read);102 if (read != hop_size) return 1;103 104 92 // seek to 0 105 93 if(aubio_source_seek(s, 0)) return 1; 106 94 107 95 // read again as multiple channels 108 aubio_source_do_multi(s, mat, &read);109 if (read != hop_size) return 1;110 111 // read again as multiple channels in an undersized matrix112 del_fmat(mat);113 mat = new_fmat(channels - 1, hop_size);114 aubio_source_do_multi(s, mat, &read);115 if (read != hop_size) return 1;116 117 // read again as multiple channels in an undersized matrix118 del_fmat(mat);119 mat = new_fmat(channels, hop_size - 1);120 aubio_source_do_multi(s, mat, &read);121 if (read != hop_size - 1) return 1;122 123 // read again as multiple channels in an oversized matrix124 del_fmat(mat);125 mat = new_fmat(channels + 1, hop_size);126 aubio_source_do_multi(s, mat, &read);127 if (read != hop_size) return 1;128 129 // read again as multiple channels in an oversized matrix130 del_fmat(mat);131 mat = new_fmat(channels, hop_size + 1);132 96 aubio_source_do_multi(s, mat, &read); 133 97 if (read != hop_size) return 1;
Note: See TracChangeset
for help on using the changeset viewer.