Ignore:
Timestamp:
Mar 22, 2013, 6:15:46 PM (12 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:
dc798e1
Parents:
6ff6d18 (diff), 18a378e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'device' into develop

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    r6ff6d18 r5d16185  
    2323#include "aubio_priv.h"
    2424#include "fvec.h"
     25#include "fmat.h"
    2526#include "io/source_apple_audio.h"
    2627
     
    3738struct _aubio_source_apple_audio_t {
    3839  uint_t channels;
    39   uint_t samplerate;
     40  uint_t samplerate;          //< requested samplerate
     41  uint_t source_samplerate;   //< actual source samplerate
    4042  uint_t block_size;
    4143
     
    5658  s->path = path;
    5759  s->block_size = block_size;
    58   s->channels = 1;
    5960
    6061  OSStatus err = noErr;
     
    8182  }
    8283  s->samplerate = samplerate;
     84  s->source_samplerate = fileFormat.mSampleRate;
     85  s->channels = fileFormat.mChannelsPerFrame;
    8386
    8487  AudioStreamBasicDescription clientFormat;
     
    98101  err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
    99102      propSize, &clientFormat);
    100   if (err) { AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); goto beach;}
    101 
    102 #if 0
     103  if (err) {
     104      AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err);
     105#if 1
    103106  // print client and format descriptions
    104107  AUBIO_DBG("Opened %s\n", s->path);
     
    117120  AUBIO_DBG("file/client Format.mReserved         : %6d / %d\n",    (int)fileFormat.mReserved        , (int)clientFormat.mReserved);
    118121#endif
     122      goto beach;
     123  }
    119124
    120125  // compute the size of the segments needed to read the input file
     
    127132    AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);
    128133  } else {
    129     assert (segmentSize == samples );
     134    assert ( segmentSize == samples );
    130135    //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size);
    131136  }
     
    144149  UInt32 c, v, loadedPackets = s->block_size;
    145150  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    146   if (err) { AUBIO_ERROR("error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
     151  if (err) { AUBIO_ERROR("error in ExtAudioFileRead %s %d\n", s->path, (int)err); goto beach;}
    147152
    148153  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    164169  }
    165170
     171  *read = (uint_t)loadedPackets;
     172  return;
     173beach:
     174  *read = 0;
     175  return;
     176}
     177
     178void 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  }
    166200  *read = (uint_t)loadedPackets;
    167201  return;
     
    182216}
    183217
     218uint_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
    184225uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
    185226  return s->samplerate;
    186227}
    187228
     229uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
     230  return s->channels;
     231}
     232
    188233#endif /* __APPLE__ */
Note: See TracChangeset for help on using the changeset viewer.