Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    r4865e4b r8c43bf7  
    2323#include "aubio_priv.h"
    2424#include "fvec.h"
    25 #include "fmat.h"
    2625#include "io/source_apple_audio.h"
    2726
     
    3837struct _aubio_source_apple_audio_t {
    3938  uint_t channels;
    40   uint_t samplerate;          //< requested samplerate
    41   uint_t source_samplerate;   //< actual source samplerate
     39  uint_t samplerate;
    4240  uint_t block_size;
    4341
     
    5856  s->path = path;
    5957  s->block_size = block_size;
     58  s->channels = 1;
    6059
    6160  OSStatus err = noErr;
     
    8281  }
    8382  s->samplerate = samplerate;
    84   s->source_samplerate = fileFormat.mSampleRate;
    85   s->channels = fileFormat.mChannelsPerFrame;
    8683
    8784  AudioStreamBasicDescription clientFormat;
     
    10198  err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
    10299      propSize, &clientFormat);
    103   if (err) {
    104       AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err);
    105 #if 1
     100  if (err) { AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); goto beach;}
     101
     102#if 0
    106103  // print client and format descriptions
    107104  AUBIO_DBG("Opened %s\n", s->path);
     
    120117  AUBIO_DBG("file/client Format.mReserved         : %6d / %d\n",    (int)fileFormat.mReserved        , (int)clientFormat.mReserved);
    121118#endif
    122       goto beach;
    123   }
    124119
    125120  // compute the size of the segments needed to read the input file
     
    132127    AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);
    133128  } else {
    134     assert ( segmentSize == samples );
     129    assert (segmentSize == samples );
    135130    //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size);
    136131  }
     
    149144  UInt32 c, v, loadedPackets = s->block_size;
    150145  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    151   if (err) { AUBIO_ERROR("error in ExtAudioFileRead %s %d\n", s->path, (int)err); goto beach;}
     146  if (err) { AUBIO_ERROR("error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
    152147
    153148  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    176171}
    177172
    178 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    179   UInt32 c, v, loadedPackets = s->block_size;
    180   OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    181   if (err) { AUBIO_ERROR("source_apple_audio: error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
    182 
    183   short *data = (short*)s->bufferList.mBuffers[0].mData;
    184 
    185   smpl_t **buf = read_to->data;
    186 
    187   for (v = 0; v < loadedPackets; v++) {
    188     for (c = 0; c < s->channels; c++) {
    189       buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
    190     }
    191   }
    192   // short read, fill with zeros
    193   if (loadedPackets < s->block_size) {
    194     for (v = loadedPackets; v < s->block_size; v++) {
    195       for (c = 0; c < s->channels; c++) {
    196         buf[c][v] = 0.;
    197       }
    198     }
    199   }
    200   *read = (uint_t)loadedPackets;
    201   return;
    202 beach:
    203   *read = 0;
    204   return;
    205 }
    206 
    207173void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
    208174  OSStatus err = noErr;
     
    216182}
    217183
    218 uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
    219   SInt64 resampled_pos = (SInt64)ROUND( pos * s->source_samplerate * 1. / s->samplerate );
    220   OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
    221   if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
    222   return err;
    223 }
    224 
    225184uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
    226185  return s->samplerate;
    227186}
    228187
    229 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
    230   return s->channels;
    231 }
    232 
    233188#endif /* __APPLE__ */
Note: See TracChangeset for help on using the changeset viewer.