void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
  UInt32 c, v, loadedPackets = s->block_size;
  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
  if (err) { AUBIO_ERROR("source_apple_audio: error in ExtAudioFileRead, %d\n", (int)err); goto beach;}

  short *data = (short*)s->bufferList.mBuffers[0].mData;

  smpl_t **buf = read_to->data;

  for (v = 0; v < loadedPackets; v++) {
    for (c = 0; c < s->channels; c++) {
      buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
    }
  }
  // short read, fill with zeros
  if (loadedPackets < s->block_size) {
    for (v = loadedPackets; v < s->block_size; v++) {
      for (c = 0; c < s->channels; c++) {
        buf[c][v] = 0.;
      }
    }
  }
  *read = (uint_t)loadedPackets;
  return;
beach:
  *read = 0;
  return;
}
void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
  OSStatus err = noErr;
  if (!s || !s->audioFile) { return; }
  err = ExtAudioFileDispose(s->audioFile);
  if (err) AUBIO_ERROR("error in ExtAudioFileDispose, %d\n", (int)err);
  s->audioFile = NULL;
  freeAudioBufferList(&s->bufferList);
  AUBIO_FREE(s);
  return;
}
Example #3
0
aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
#ifdef HAVE_SINK_APPLE_AUDIO
  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
    return s;
  }
#endif /* HAVE_SINK_APPLE_AUDIO */
#ifdef HAVE_SNDFILE
  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
    return s;
  }
#endif /* HAVE_SNDFILE */
#ifdef HAVE_WAVWRITE
  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do);
    s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi);
    s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate);
    s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels);
    s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate);
    s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels);
    s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite);
    return s;
  }
#endif /* HAVE_WAVWRITE */
#if !defined(HAVE_WAVWRITE) && \
  !defined(HAVE_SNDFILE) && \
  !defined(HAVE_SINK_APPLE_AUDIO)
  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
#endif
  AUBIO_FREE(s);
  return NULL;
}
Example #4
0
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
#ifdef __APPLE__
  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
  if (s->source) return s;
#else /* __APPLE__ */
#if HAVE_SNDFILE
  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
  if (s->source) return s;
#endif /* HAVE_SNDFILE */
#endif /* __APPLE__ */
  AUBIO_ERROR("failed creating aubio source with %s\n", uri);
  AUBIO_FREE(s);
  return NULL;
}
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
  AUBIO_MSG("new aubio source");

#if HAVE_LIBAV
  AUBIO_MSG("libav");
  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
    return s;
  }
#endif /* HAVE_LIBAV */
#ifdef __APPLE__
  AUBIO_MSG("apple");
  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
    return s;
  }
#endif /* __APPLE__ */
#if HAVE_SNDFILE
  AUBIO_MSG("sndfile");
  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
    return s;
  }
#endif /* HAVE_SNDFILE */
  AUBIO_ERROR("failed creating aubio source with %s\n", uri);
  AUBIO_FREE(s);
  return NULL;
}
Example #6
0
uint_t
aubio_filter_set_biquad (aubio_filter_t * f, lsmp_t b0, lsmp_t b1, lsmp_t b2,
    lsmp_t a1, lsmp_t a2)
{
  uint_t order = aubio_filter_get_order (f);
  lvec_t *bs = aubio_filter_get_feedforward (f);
  lvec_t *as = aubio_filter_get_feedback (f);

  if (order != 3) {
    AUBIO_ERROR ("order of biquad filter must be 3, not %d\n", order);
    return AUBIO_FAIL;
  }
  bs->data[0] = b0;
  bs->data[1] = b1;
  bs->data[2] = b2;
  as->data[0] = 1.;
  as->data[1] = a1;
  as->data[1] = a2;
  return AUBIO_OK;
}
Example #7
0
File: sink.c Project: famulus/aubio
aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
#ifdef __APPLE__
  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
    return s;
  }
#endif /* __APPLE__ */
#if HAVE_SNDFILE
  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
  if (s->sink) {
    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
    return s;
  }
#endif /* HAVE_SNDFILE */
  AUBIO_ERROR("sink: failed creating aubio sink with %s\n", uri);
  AUBIO_FREE(s);
  return NULL;
}
Example #8
0
uint_t
aubio_filter_set_c_weighting (aubio_filter_t * f, uint_t samplerate)
{
  uint_t order; lsmp_t *a, *b; lvec_t *as, *bs;

  if ((sint_t)samplerate <= 0) {
    AUBIO_ERROR("aubio_filter: failed setting C-weighting with samplerate %d\n", samplerate);
    return AUBIO_FAIL;
  }
  if (f == NULL) {
    AUBIO_ERROR("aubio_filter: failed setting C-weighting with filter NULL\n");
    return AUBIO_FAIL;
  }

  order = aubio_filter_get_order (f);
  if ( order != 5 ) {
    AUBIO_ERROR ("aubio_filter: order of C-weighting filter must be 5, not %d\n", order);
    return 1;
  }

  aubio_filter_set_samplerate (f, samplerate);
  bs = aubio_filter_get_feedforward (f);
  as = aubio_filter_get_feedback (f);
  b = bs->data, a = as->data;

  /* select coefficients according to sampling frequency */
  switch (samplerate) {

    case 8000:
      b[0] =  6.782173932405135552414776611840352416038513183593750000e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -1.356434786481027110482955322368070483207702636718750000e+00;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  6.782173932405135552414776611840352416038513183593750000e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -6.589092811505605773447769024642184376716613769531250000e-01;
      a[2] = -1.179445664897062595599663836765103042125701904296875000e+00;
      a[3] =  4.243329729632123736848825501510873436927795410156250000e-01;
      a[4] =  4.147270002091348328754349950031610205769538879394531250e-01;
      break;

    case 11025:
      b[0] =  6.002357155402652244546857218665536493062973022460937500e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -1.200471431080530448909371443733107298612594604492187500e+00;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  6.002357155402652244546857218665536493062973022460937500e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -8.705602141280316397242700077185872942209243774414062500e-01;
      a[2] = -9.037199507150940336330791069485712796449661254882812500e-01;
      a[3] =  4.758433040929530011275971901341108605265617370605468750e-01;
      a[4] =  2.987653956523212417373258631414500996470451354980468750e-01;
      break;

    case 16000:
      b[0] =  4.971057193673903418229542694461997598409652709960937500e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -9.942114387347806836459085388923995196819305419921875000e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  4.971057193673903418229542694461997598409652709960937500e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -1.162322939286873690889478893950581550598144531250000000e+00;
      a[2] = -4.771961355734982701548574368644040077924728393554687500e-01;
      a[3] =  4.736145114694704227886745684372726827859878540039062500e-01;
      a[4] =  1.660337524309875301131711466950946487486362457275390625e-01;
      break;

    case 22050:
      b[0] =  4.033381299002754549754001800465630367398262023925781250e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -8.066762598005509099508003600931260734796524047851562500e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  4.033381299002754549754001800465630367398262023925781250e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -1.449545371157945350404361306573264300823211669921875000e+00;
      a[2] = -1.030104190885922088583015465701464563608169555664062500e-02;
      a[3] =  3.881857047554073680828423675848171114921569824218750000e-01;
      a[4] =  7.171589940116777917022972133054281584918498992919921875e-02;
      break;

    case 24000:
      b[0] =  3.786678621924967069745093795063439756631851196289062500e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -7.573357243849934139490187590126879513263702392578125000e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  3.786678621924967069745093795063439756631851196289062500e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -1.529945307555420797029910318087786436080932617187500000e+00;
      a[2] =  1.283553182116208835061854642844991758465766906738281250e-01;
      a[3] =  3.494608072385725350272878131363540887832641601562500000e-01;
      a[4] =  5.217291949300089520802359288609295617789030075073242188e-02;
      break;

    case 32000:
      b[0] =  2.977986488230693340462096330156782642006874084472656250e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -5.955972976461386680924192660313565284013748168945312500e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  2.977986488230693340462096330156782642006874084472656250e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -1.812455387128179218336754274787381291389465332031250000e+00;
      a[2] =  6.425013281155662614452239722595550119876861572265625000e-01;
      a[3] =  1.619857574578579817448087396769551560282707214355468750e-01;
      a[4] =  7.987649713547682189807019881300220731645822525024414062e-03;
      break;

    case 44100:
      b[0] =  2.170085619492190254220531642204150557518005371093750000e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -4.340171238984380508441063284408301115036010742187500000e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  2.170085619492190254220531642204150557518005371093750000e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -2.134674963687040794013682898366823792457580566406250000e+00;
      a[2] =  1.279333533236062692139967111870646476745605468750000000e+00;
      a[3] = -1.495598460893957093453821016737492755055427551269531250e-01;
      a[4] =  4.908700174624683852664386307651511742733418941497802734e-03;
      break;

    case 48000:
      b[0] =  1.978871200263932761398422144338837824761867523193359375e-01;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -3.957742400527865522796844288677675649523735046386718750e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  1.978871200263932761398422144338837824761867523193359375e-01;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -2.219172914052801814932536217384040355682373046875000000e+00;
      a[2] =  1.455135878947171557129536267893854528665542602539062500e+00;
      a[3] = -2.484960738877830532800317087094299495220184326171875000e-01;
      a[4] =  1.253882314727246607977129144728678511455655097961425781e-02;
      break;

    case 88200:
      b[0] =  9.221909851156021020734954163344809785485267639160156250e-02;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -1.844381970231204204146990832668961957097053527832031250e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  9.221909851156021020734954163344809785485267639160156250e-02;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -2.785795902923448696952846148633398115634918212890625000e+00;
      a[2] =  2.727736758747444145711824603495188057422637939453125000e+00;
      a[3] = -1.097007502819661528548067508381791412830352783203125000e+00;
      a[4] =  1.550674356752141103132913713125162757933139801025390625e-01;
      break;

    case 96000:
      b[0] =  8.182864044979756834585771230194950476288795471191406250e-02;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -1.636572808995951366917154246038990095257759094238281250e-01;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  8.182864044979756834585771230194950476288795471191406250e-02;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -2.856378516857566829401093855267390608787536621093750000e+00;
      a[2] =  2.897640237559524045707348705036565661430358886718750000e+00;
      a[3] = -1.225265958339703198376469117647502571344375610351562500e+00;
      a[4] =  1.840048283551226071530493300087982788681983947753906250e-01;
      break;

    case 192000:
      b[0] =  2.784755468532278815940728122768632601946592330932617188e-02;
      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[2] = -5.569510937064557631881456245537265203893184661865234375e-02;
      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
      b[4] =  2.784755468532278815940728122768632601946592330932617188e-02;
      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
      a[1] = -3.333298856144166322224009491037577390670776367187500000e+00;
      a[2] =  4.111467536240339448738723149290308356285095214843750000e+00;
      a[3] = -2.222889041651291641699117462849244475364685058593750000e+00;
      a[4] =  4.447204118126878991112960193277103826403617858886718750e-01;
      break;

    default:
      AUBIO_ERROR ( "sampling rate of C-weighting filter is %d, should be one of\
 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 192000.\n", 
 samplerate );
      return 1;

  }

  return 0;
}
aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * path, uint_t samplerate, uint_t block_size)
{
  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);

  s->path = path;
  s->block_size = block_size;

  OSStatus err = noErr;
  UInt32 propSize;

  // open the resource url
  CFURLRef fileURL = getURLFromPath(path);
  err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
  if (err) { AUBIO_ERR("error when trying to access %s, in ExtAudioFileOpenURL, %d\n", s->path, (int)err); goto beach;}

  // create an empty AudioStreamBasicDescription
  AudioStreamBasicDescription fileFormat;
  propSize = sizeof(fileFormat);
  memset(&fileFormat, 0, sizeof(AudioStreamBasicDescription));

  // fill it with the file description
  err = ExtAudioFileGetProperty(s->audioFile,
      kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);
  if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;}

  if (samplerate == 0) {
    samplerate = fileFormat.mSampleRate;
    //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
  }
  s->samplerate = samplerate;
  s->source_samplerate = fileFormat.mSampleRate;
  s->channels = fileFormat.mChannelsPerFrame;

  AudioStreamBasicDescription clientFormat;
  propSize = sizeof(clientFormat);
  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
  clientFormat.mFormatID         = kAudioFormatLinearPCM;
  clientFormat.mSampleRate       = (Float64)(s->samplerate);
  clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
  clientFormat.mChannelsPerFrame = s->channels;
  clientFormat.mBitsPerChannel   = sizeof(short) * 8;
  clientFormat.mFramesPerPacket  = 1;
  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
  clientFormat.mReserved         = 0;

  // set the client format description
  err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
      propSize, &clientFormat);
  if (err) {
      AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err);
#if 1
  // print client and format descriptions
  AUBIO_DBG("Opened %s\n", s->path);
  AUBIO_DBG("file/client Format.mFormatID:        : %3c%c%c%c / %c%c%c%c\n",
      (int)RT_BYTE4(fileFormat.mFormatID),   (int)RT_BYTE3(fileFormat.mFormatID),   (int)RT_BYTE2(fileFormat.mFormatID),   (int)RT_BYTE1(fileFormat.mFormatID),
      (int)RT_BYTE4(clientFormat.mFormatID), (int)RT_BYTE3(clientFormat.mFormatID), (int)RT_BYTE2(clientFormat.mFormatID), (int)RT_BYTE1(clientFormat.mFormatID)
      );

  AUBIO_DBG("file/client Format.mSampleRate       : %6.0f / %.0f\n",     fileFormat.mSampleRate      ,      clientFormat.mSampleRate);
  AUBIO_DBG("file/client Format.mFormatFlags      : %6d / %d\n",    (int)fileFormat.mFormatFlags     , (int)clientFormat.mFormatFlags);
  AUBIO_DBG("file/client Format.mChannelsPerFrame : %6d / %d\n",    (int)fileFormat.mChannelsPerFrame, (int)clientFormat.mChannelsPerFrame);
  AUBIO_DBG("file/client Format.mBitsPerChannel   : %6d / %d\n",    (int)fileFormat.mBitsPerChannel  , (int)clientFormat.mBitsPerChannel);
  AUBIO_DBG("file/client Format.mFramesPerPacket  : %6d / %d\n",    (int)fileFormat.mFramesPerPacket , (int)clientFormat.mFramesPerPacket);
  AUBIO_DBG("file/client Format.mBytesPerFrame    : %6d / %d\n",    (int)fileFormat.mBytesPerFrame   , (int)clientFormat.mBytesPerFrame);
  AUBIO_DBG("file/client Format.mBytesPerPacket   : %6d / %d\n",    (int)fileFormat.mBytesPerPacket  , (int)clientFormat.mBytesPerPacket);
  AUBIO_DBG("file/client Format.mReserved         : %6d / %d\n",    (int)fileFormat.mReserved        , (int)clientFormat.mReserved);
#endif
      goto beach;
  }

  // compute the size of the segments needed to read the input file
  UInt32 samples = s->block_size * clientFormat.mChannelsPerFrame;
  Float64 rateRatio = clientFormat.mSampleRate / fileFormat.mSampleRate;
  uint_t segmentSize= (uint_t)(samples * rateRatio + .5);
  if (rateRatio < 1.) {
    segmentSize = (uint_t)(samples / rateRatio + .5);
  } else if (rateRatio > 1.) {
    AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);
  } else {
    assert ( segmentSize == samples );
    //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size);
  }

  // allocate the AudioBufferList
  if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) err = -1;

  return s;
 
beach:
  AUBIO_FREE(s);
  return NULL;
}
uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
  SInt64 resampled_pos = (SInt64)ROUND( pos * s->source_samplerate * 1. / s->samplerate );
  OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
  if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
  return err;
}
Example #11
0
File: source.c Project: hgneng/ekho
aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
#ifdef HAVE_LIBAV
  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
    return s;
  }
#endif /* HAVE_LIBAV */
#ifdef HAVE_SOURCE_APPLE_AUDIO
  s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
    return s;
  }
#endif /* HAVE_SOURCE_APPLE_AUDIO */
#ifdef HAVE_SNDFILE
  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
    return s;
  }
#endif /* HAVE_SNDFILE */
#ifdef HAVE_WAVREAD
  s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
  if (s->source) {
    s->s_do = (aubio_source_do_t)(aubio_source_wavread_do);
    s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi);
    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
    s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
    return s;
  }
#else /* failover message */
#if !(defined(HAVE_LIBAV) || defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SNDFILE))
  AUBIO_ERROR("source: failed creating aubio source with %s"
     " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
#endif /* failover */
#endif /* HAVE_WAVREAD */
  AUBIO_FREE(s);
  return NULL;
}