Changeset eadd8d5


Ignore:
Timestamp:
Dec 6, 2013, 3:13:04 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
af27265
Parents:
7760b40
Message:

src/io/source_avcodec.c: rewrite _do, add eof, remove debug output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r7760b40 readd8d5  
    5959  uint_t read_index;
    6060  sint_t selected_stream;
     61  uint_t eof;
    6162};
    6263
     
    7677  // register all formats and codecs
    7778  av_register_all();
     79
     80  // if path[0] != '/'
     81  //avformat_network_init();
    7882
    7983  // try opening the file and get some info about it
     
    125129    goto beach;
    126130  }
    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);
    128132  s->selected_stream = selected_stream;
    129133
     
    198202  s->avr = avr;
    199203
     204  s->eof = 0;
     205
    200206  //av_log_set_level(AV_LOG_QUIET);
    201207
     
    222228    int err = av_read_frame (avFormatCtx, &avPacket);
    223229    if (err != 0) {
     230      if (err == AVERROR_EOF) {
     231        s->eof = 1;
     232        *read_samples = 0;
     233        return;
     234      }
    224235      uint8_t errorstr_len = 128;
    225236      char errorstr[errorstr_len];
     
    238249
    239250  if (len < 0) {
     251    av_free_packet(&avPacket);
    240252    AUBIO_ERR("Error while decoding %s\n", s->path);
    241253    return;
    242254  }
    243255  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;
    245260  } /* else {
    246261    int data_size =
     
    267282  //    max_out_samples, AUBIO_AVCODEC_MIN_BUFFER_SIZE);
    268283
    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);
    270285  //for (i = 0; i < out_samples; i ++) {
    271286  //  AUBIO_DBG("%f\n", SHORT_TO_FLOAT(output[i]));
     
    284299void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){
    285300  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;
    309316      }
    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;
    322327}
    323328
Note: See TracChangeset for help on using the changeset viewer.