Changeset 3d5cddf for src/io


Ignore:
Timestamp:
Dec 6, 2013, 5:12:11 AM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
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:
1fe3ac2
Parents:
0044b43
Message:

src/io/source_avcodec.c: let avresample do the conversion to float

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r0044b43 r3d5cddf  
    3838#define AUBIO_AVCODEC_MIN_BUFFER_SIZE FF_MIN_BUFFER_SIZE
    3939
    40 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    41 
    4240struct _aubio_source_avcodec_t {
    4341  uint_t hop_size;
     
    5553  AVFrame *avFrame;
    5654  AVAudioResampleContext *avr;
    57   int16_t *output;
     55  float *output;
    5856  uint_t read_samples;
    5957  uint_t read_index;
     
    173171  av_opt_set_int(avr, "out_sample_rate",    s->samplerate,          0);
    174172  av_opt_set_int(avr, "in_sample_fmt",      avCodecCtx->sample_fmt, 0);
    175   av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_S16,      0);
     173  av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,     0);
    176174  if ( ( err = avresample_open(avr) ) < 0) {
    177175    uint8_t errorstr_len = 128;
     
    192190
    193191  /* allocate output for avr */
    194   s->output = (int16_t *)av_malloc(AUBIO_AVCODEC_MIN_BUFFER_SIZE * sizeof(int16_t));
     192  s->output = (float *)av_malloc(AUBIO_AVCODEC_MIN_BUFFER_SIZE * sizeof(float));
    195193
    196194  s->read_samples = 0;
     
    222220  av_init_packet (&avPacket);
    223221  AVAudioResampleContext *avr = s->avr;
    224   int16_t *output = s->output;
     222  float *output = s->output;
    225223
    226224  do
     
    304302    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    305303    for (i = 0; i < end; i++) {
    306       read_data->data[i + total_wrote] = SHORT_TO_FLOAT(s->output[i + s->read_index]);
     304      read_data->data[i + total_wrote] = s->output[i + s->read_index];
    307305    }
    308306    total_wrote += end;
Note: See TracChangeset for help on using the changeset viewer.