Changeset 7982203


Ignore:
Timestamp:
Mar 22, 2013, 1:41:54 AM (8 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:
4865e4b
Parents:
2d3212a
Message:

add seek to src/io/source*

Location:
src/io
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/io/source.c

    r2d3212a r7982203  
    8282}
    8383
     84uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
     85#ifdef __APPLE__
     86  return aubio_source_apple_audio_seek ((aubio_source_apple_audio_t *)s->source, seek);
     87#else /* __APPLE__ */
     88#if HAVE_SNDFILE
     89  return aubio_source_sndfile_seek ((aubio_source_sndfile_t *)s->source, seek);
     90#endif /* HAVE_SNDFILE */
     91#endif /* __APPLE__ */
     92}
  • src/io/source.h

    r2d3212a r7982203  
    8080/**
    8181
     82  seek source object
     83
     84  \param s source object, created with ::new_aubio_source
     85  \param pos position to seek to, in frames
     86
     87  \return 0 if sucessful, non-zero on failure
     88
     89*/
     90uint_t aubio_source_seek (aubio_source_t * s, uint_t pos);
     91
     92/**
     93
    8294  close source and cleanup memory
    8395
  • src/io/source_apple_audio.c

    r2d3212a r7982203  
    3737struct _aubio_source_apple_audio_t {
    3838  uint_t channels;
    39   uint_t samplerate;
     39  uint_t samplerate;          //< requested samplerate
     40  uint_t source_samplerate;   //< actual source samplerate
    4041  uint_t block_size;
    4142
     
    8182  }
    8283  s->samplerate = samplerate;
     84  s->source_samplerate = fileFormat.mSampleRate;
    8385
    8486  AudioStreamBasicDescription clientFormat;
     
    144146  UInt32 c, v, loadedPackets = s->block_size;
    145147  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    146   if (err) { AUBIO_ERROR("error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
     148  if (err) { AUBIO_ERROR("error in ExtAudioFileRead %s %d\n", s->path, (int)err); goto beach;}
    147149
    148150  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    182184}
    183185
     186uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
     187  Float64 ratio = (Float64)(s->source_samplerate) / (Float64)(s->samplerate);
     188  OSStatus err = ExtAudioFileSeek(s->audioFile, pos);
     189  if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
     190  return err;
     191}
     192
    184193uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
    185194  return s->samplerate;
  • src/io/source_apple_audio.h

    r2d3212a r7982203  
    8686/**
    8787
     88  seek source object
     89
     90  \param s source object, created with ::new_aubio_source
     91  \param pos position to seek to, in frames
     92
     93  \return 0 if sucessful, non-zero on failure
     94
     95*/
     96uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos);
     97
     98/**
     99
    88100  close source and cleanup memory
    89101
  • src/io/source_sndfile.c

    r2d3212a r7982203  
    177177}
    178178
     179uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
     180  uint_t resampled_pos = (uint_t)ROUND(pos * s->input_samplerate * 1. / s->samplerate);
     181  return sf_seek (s->handle, resampled_pos, SEEK_SET);
     182}
     183
    179184void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
    180185  if (!s) return;
  • src/io/source_sndfile.h

    r2d3212a r7982203  
    8585/**
    8686
     87  seek source object
     88
     89  \param s source object, created with ::new_aubio_source_sndfile
     90  \param pos position to seek to, in frames
     91
     92  \return 0 if sucessful, non-zero on failure
     93
     94*/
     95uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t *s, uint_t pos);
     96
     97/**
     98
    8799  close source and cleanup memory
    88100
Note: See TracChangeset for help on using the changeset viewer.