Changeset b4e1438


Ignore:
Timestamp:
Apr 25, 2016, 4:45:22 PM (4 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:
691791e
Parents:
c6e7ba1
Message:

src/io/source_wavread.h: add _get_duration

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_wavread.c

    rc6e7ba1 rb4e1438  
    5353  uint_t eof;
    5454
     55  uint_t duration;
     56
    5557  size_t seek_start;
    5658
     
    7274  size_t bytes_read = 0, bytes_expected = 44;
    7375  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;
    7577
    7678  if (path == NULL) {
     
    216218  // Subchunk2Size
    217219  bytes_read += fread(buf, 1, 4, s->fid);
     220  duration = read_little_endian(buf, 4) / blockalign;
     221
    218222  //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24);
    219223  //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path);
     
    235239  s->blockalign= blockalign;
    236240  s->bitspersample = bitspersample;
     241
     242  s->duration = duration;
    237243
    238244  s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE);
     
    375381}
    376382
     383uint_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
    377390uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
    378391  if (!s->fid) {
  • src/io/source_wavread.h

    rc6e7ba1 rb4e1438  
    126126/**
    127127
     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*/
     134uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t *s);
     135
     136/**
     137
    128138  close source
    129139
  • tests/src/io/test-source_wavread.c

    rc6e7ba1 rb4e1438  
    3636  aubio_source_wavread_t * s =
    3737    new_aubio_source_wavread(source_path, samplerate, hop_size);
     38
    3839  if (!s) { err = 1; goto beach; }
    3940  fvec_t *vec = new_fvec(hop_size);
     41
     42  uint_t n_frames_expected = aubio_source_wavread_get_duration(s);
    4043
    4144  samplerate = aubio_source_wavread_get_samplerate(s);
     
    4750  } while ( read == hop_size );
    4851
    49   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate,
    50     n_frames / hop_size, source_path);
     52  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
     53            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
     54            source_path);
    5155
    5256  del_fvec (vec);
Note: See TracChangeset for help on using the changeset viewer.