Changeset 6bbdcff


Ignore:
Timestamp:
Mar 22, 2013, 11:54:48 PM (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:
987fb86, db120ac
Parents:
86cfdfa
Message:

src/io/source_apple_audio.c: add _open and _close

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    r86cfdfa r6bbdcff  
    5252extern CFURLRef getURLFromPath(const char * path);
    5353
     54uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path);
     55
    5456aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * path, uint_t samplerate, uint_t block_size)
    5557{
    5658  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
    5759
    58   s->path = path;
    5960  s->block_size = block_size;
    60 
     61  s->samplerate = samplerate;
     62
     63  if ( aubio_source_apple_audio_open ( s, path ) ) {
     64    goto beach;
     65  }
     66  return s;
     67
     68beach:
     69  AUBIO_FREE(s);
     70  return NULL;
     71}
     72
     73uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path)
     74{
    6175  OSStatus err = noErr;
    6276  UInt32 propSize;
     77  s->path = path;
    6378
    6479  // open the resource url
     
    7792  if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;}
    7893
    79   if (samplerate == 0) {
    80     samplerate = fileFormat.mSampleRate;
     94  if (s->samplerate == 0) {
     95    s->samplerate = fileFormat.mSampleRate;
    8196    //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    8297  }
    83   s->samplerate = samplerate;
     98
    8499  s->source_samplerate = fileFormat.mSampleRate;
    85100  s->channels = fileFormat.mChannelsPerFrame;
     
    124139
    125140  // compute the size of the segments needed to read the input file
    126   UInt32 samples = s->block_size * clientFormat.mChannelsPerFrame;
    127   Float64 rateRatio = clientFormat.mSampleRate / fileFormat.mSampleRate;
     141  UInt32 samples = s->block_size * s->channels;
     142  Float64 rateRatio = s->samplerate / s->source_samplerate;
    128143  uint_t segmentSize= (uint_t)(samples * rateRatio + .5);
    129144  if (rateRatio < 1.) {
    130145    segmentSize = (uint_t)(samples / rateRatio + .5);
    131146  } else if (rateRatio > 1.) {
    132     AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);
     147    AUBIO_WRN("up-sampling %s from %0dHz to %0dHz\n", s->path, s->source_samplerate, s->samplerate);
    133148  } else {
    134149    assert ( segmentSize == samples );
     
    137152
    138153  // allocate the AudioBufferList
    139   if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) err = -1;
    140 
    141   return s;
    142  
    143 beach:
    144   AUBIO_FREE(s);
    145   return NULL;
     154  if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) {
     155    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
     156    goto beach;
     157  }
     158
     159beach:
     160  return err;
    146161}
    147162
     
    205220}
    206221
    207 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
     222uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)
     223{
    208224  OSStatus err = noErr;
    209   if (!s || !s->audioFile) { return; }
     225  if (!s || !s->audioFile) { return 1; }
    210226  err = ExtAudioFileDispose(s->audioFile);
    211227  if (err) AUBIO_ERROR("error in ExtAudioFileDispose, %d\n", (int)err);
    212228  s->audioFile = NULL;
     229  return err;
     230}
     231
     232void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
     233  aubio_source_apple_audio_close (s);
    213234  freeAudioBufferList(&s->bufferList);
    214235  AUBIO_FREE(s);
Note: See TracChangeset for help on using the changeset viewer.