Changeset eadd8d5 for src/io/source_avcodec.c
- Timestamp:
- Dec 6, 2013, 3:13:04 AM (11 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:
- af27265
- Parents:
- 7760b40
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
r7760b40 readd8d5 59 59 uint_t read_index; 60 60 sint_t selected_stream; 61 uint_t eof; 61 62 }; 62 63 … … 76 77 // register all formats and codecs 77 78 av_register_all(); 79 80 // if path[0] != '/' 81 //avformat_network_init(); 78 82 79 83 // try opening the file and get some info about it … … 125 129 goto beach; 126 130 } 127 AUBIO_DBG("Taking stream %d in file %s\n", selected_stream, s->path);131 //AUBIO_DBG("Taking stream %d in file %s\n", selected_stream, s->path); 128 132 s->selected_stream = selected_stream; 129 133 … … 198 202 s->avr = avr; 199 203 204 s->eof = 0; 205 200 206 //av_log_set_level(AV_LOG_QUIET); 201 207 … … 222 228 int err = av_read_frame (avFormatCtx, &avPacket); 223 229 if (err != 0) { 230 if (err == AVERROR_EOF) { 231 s->eof = 1; 232 *read_samples = 0; 233 return; 234 } 224 235 uint8_t errorstr_len = 128; 225 236 char errorstr[errorstr_len]; … … 238 249 239 250 if (len < 0) { 251 av_free_packet(&avPacket); 240 252 AUBIO_ERR("Error while decoding %s\n", s->path); 241 253 return; 242 254 } 243 255 if (got_frame == 0) { 244 AUBIO_ERR("Could not get frame for (%s)\n", s->path); 256 av_free_packet(&avPacket); 257 //AUBIO_ERR("Could not get frame for (%s)\n", s->path); 258 *read_samples = 0; 259 return; 245 260 } /* else { 246 261 int data_size = … … 267 282 // max_out_samples, AUBIO_AVCODEC_MIN_BUFFER_SIZE); 268 283 269 //AUBIO_WRN(" Converted %d to %d samples\n", in_samples, out_samples);284 //AUBIO_WRN("aubio_source_avcodec_readframe converted %d to %d samples\n", in_samples, out_samples); 270 285 //for (i = 0; i < out_samples; i ++) { 271 286 // AUBIO_DBG("%f\n", SHORT_TO_FLOAT(output[i])); … … 284 299 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){ 285 300 uint_t i; 286 //AUBIO_DBG("entering 'do' with %d, %d\n", s->read_samples, s->read_index); 287 if (s->read_samples < s->hop_size) { 288 // write the end of the buffer to the beginning of read_data 289 uint_t partial = s->read_samples; 290 for (i = 0; i < partial; i++) { 291 read_data->data[i] = SHORT_TO_FLOAT(s->output[i + s->read_index]); 292 } 293 // get more data 294 uint_t avcodec_read = 0; 295 aubio_source_avcodec_readframe(s, &avcodec_read); 296 s->read_samples = avcodec_read; 297 s->read_index = 0; 298 // write the beginning of the buffer to the end of read_data 299 uint_t end = MIN(s->hop_size, s->read_samples); 300 if (avcodec_read == 0) { 301 end = partial; 302 } 303 for (i = partial; i < end; i++) { 304 read_data->data[i] = SHORT_TO_FLOAT(s->output[i - partial + s->read_index]); 305 } 306 if (end < s->hop_size) { 307 for (i = end; i < s->hop_size; i++) { 308 read_data->data[i] = 0.; 301 uint_t end = 0; 302 uint_t total_wrote = 0; 303 while (total_wrote < s->hop_size) { 304 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); 305 for (i = 0; i < end; i++) { 306 read_data->data[i + total_wrote] = SHORT_TO_FLOAT(s->output[i + s->read_index]); 307 } 308 total_wrote += end; 309 if (total_wrote < s->hop_size) { 310 uint_t avcodec_read = 0; 311 aubio_source_avcodec_readframe(s, &avcodec_read); 312 s->read_samples = avcodec_read; 313 s->read_index = 0; 314 if (s->eof) { 315 break; 309 316 } 310 } 311 s->read_index += end - partial; 312 s->read_samples -= end - partial; 313 *read = end; 314 } else { 315 for (i = 0; i < s->hop_size; i++) { 316 read_data->data[i] = SHORT_TO_FLOAT(s->output[i + s->read_index]); 317 } 318 s->read_index += s->hop_size; 319 s->read_samples -= s->hop_size; 320 *read = s->hop_size; 321 } 317 } else { 318 s->read_index += end; 319 } 320 } 321 if (total_wrote < s->hop_size) { 322 for (i = end; i < s->hop_size; i++) { 323 read_data->data[i] = 0.; 324 } 325 } 326 *read = total_wrote; 322 327 } 323 328
Note: See TracChangeset
for help on using the changeset viewer.