Changes in / [b429b68:6d44595]


Ignore:
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/io/source.c

    rb429b68 r6d44595  
    2222#include "aubio_priv.h"
    2323#include "fvec.h"
     24#include "fmat.h"
    2425#include "io/source.h"
    2526#ifdef __APPLE__
     
    6061}
    6162
     63void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
     64#ifdef __APPLE__
     65  aubio_source_apple_audio_do_multi((aubio_source_apple_audio_t *)s->source, data, read);
     66#else /* __APPLE__ */
     67#if HAVE_SNDFILE
     68  aubio_source_sndfile_do_multi((aubio_source_sndfile_t *)s->source, data, read);
     69#endif /* HAVE_SNDFILE */
     70#endif /* __APPLE__ */
     71}
     72
    6273void del_aubio_source(aubio_source_t * s) {
    6374  if (!s) return;
     
    8293}
    8394
     95uint_t aubio_source_get_channels(aubio_source_t * s) {
     96#ifdef __APPLE__
     97  return aubio_source_apple_audio_get_channels((aubio_source_apple_audio_t *)s->source);
     98#else /* __APPLE__ */
     99#if HAVE_SNDFILE
     100  return aubio_source_sndfile_get_channels((aubio_source_sndfile_t *)s->source);
     101#endif /* HAVE_SNDFILE */
     102#endif /* __APPLE__ */
     103}
     104
     105uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
     106#ifdef __APPLE__
     107  return aubio_source_apple_audio_seek ((aubio_source_apple_audio_t *)s->source, seek);
     108#else /* __APPLE__ */
     109#if HAVE_SNDFILE
     110  return aubio_source_sndfile_seek ((aubio_source_sndfile_t *)s->source, seek);
     111#endif /* HAVE_SNDFILE */
     112#endif /* __APPLE__ */
     113}
  • src/io/source.h

    rb429b68 r6d44595  
    7070/**
    7171
     72  read polyphonic vector of length hop_size from source object
     73
     74  \param s source object, created with ::new_aubio_source
     75  \param read_to ::fmat_t of data to read to
     76  \param read upon returns, equals to number of frames actually read
     77
     78  Upon returns, `read` contains the number of frames actually read from the
     79  source. `hop_size` if enough frames could be read, less otherwise.
     80
     81*/
     82void aubio_source_do_multi(aubio_source_t * s, fmat_t * read_to, uint_t * read);
     83
     84/**
     85
    7286  get samplerate of source object
    7387
     
    7791*/
    7892uint_t aubio_source_get_samplerate(aubio_source_t * s);
     93
     94/**
     95
     96  get channels of source object
     97
     98  \param s source object, created with ::new_aubio_source
     99  \return channels
     100
     101*/
     102uint_t aubio_source_get_channels (aubio_source_t * s);
     103
     104/**
     105
     106  seek source object
     107
     108  \param s source object, created with ::new_aubio_source
     109  \param pos position to seek to, in frames
     110
     111  \return 0 if sucessful, non-zero on failure
     112
     113*/
     114uint_t aubio_source_seek (aubio_source_t * s, uint_t pos);
    79115
    80116/**
  • src/io/source_apple_audio.c

    rb429b68 r6d44595  
    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__ */
  • src/io/source_apple_audio.h

    rb429b68 r6d44595  
    7676/**
    7777
     78  read polyphonic vector of length hop_size from source object
     79
     80  \param s source object, created with ::new_aubio_source_apple_audio
     81  \param read_to ::fmat_t of data to read to
     82  \param read upon returns, equals to number of frames actually read
     83
     84  Upon returns, `read` contains the number of frames actually read from the
     85  source. `hop_size` if enough frames could be read, less otherwise.
     86
     87*/
     88void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t * s, fmat_t * read_to, uint_t * read);
     89
     90/**
     91
    7892  get samplerate of source object
    7993
     
    8397*/
    8498uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s);
     99
     100/**
     101
     102  get channels of source object
     103
     104  \param s source object, created with ::new_aubio_source_apple_audio
     105  \return number of channels
     106
     107*/
     108uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s);
     109
     110/**
     111
     112  seek source object
     113
     114  \param s source object, created with ::new_aubio_source
     115  \param pos position to seek to, in frames
     116
     117  \return 0 if sucessful, non-zero on failure
     118
     119*/
     120uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos);
    85121
    86122/**
  • src/io/source_sndfile.c

    rb429b68 r6d44595  
    2727
    2828#include "aubio_priv.h"
     29#include "fvec.h"
     30#include "fmat.h"
    2931#include "source_sndfile.h"
    30 #include "fvec.h"
    3132
    3233#include "temporal/resampler.h"
     
    159160    data[j] = 0;
    160161    for (i = 0; i < input_channels; i++) {
    161       data[j] += (smpl_t)s->scratch_data[input_channels*j+i];
     162      data[j] += s->scratch_data[input_channels*j+i];
    162163    }
    163164    data[j] /= (smpl_t)input_channels;
     
    171172
    172173  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     174
     175  if (*read < s->hop_size) {
     176    for (j = *read; j < s->hop_size; j++) {
     177      data[j] = 0;
     178    }
     179  }
     180
     181}
     182
     183void aubio_source_sndfile_do_multi(aubio_source_sndfile_t * s, fmat_t * read_data, uint_t * read){
     184  uint_t i,j, input_channels = s->input_channels;
     185  /* do actual reading */
     186  sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     187
     188  smpl_t **data;
     189
     190#ifdef HAVE_SAMPLERATE
     191  if (s->ratio != 1) {
     192    AUBIO_ERR("source_sndfile: no multi channel resampling yet");
     193    return;
     194    //data = s->input_data->data;
     195  } else
     196#endif /* HAVE_SAMPLERATE */
     197  {
     198    data = read_data->data;
     199  }
     200
     201  /* de-interleaving data */
     202  for (j = 0; j < read_samples / input_channels; j++) {
     203    for (i = 0; i < input_channels; i++) {
     204      data[i][j] = (smpl_t)s->scratch_data[input_channels*j+i];
     205    }
     206  }
     207
     208#ifdef HAVE_SAMPLERATE
     209  if (s->resampler) {
     210    //aubio_resampler_do(s->resampler, s->input_data, read_data);
     211  }
     212#endif /* HAVE_SAMPLERATE */
     213
     214  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     215
     216  if (*read < s->hop_size) {
     217    for (i = 0; i < input_channels; i++) {
     218      for (j = *read; j < s->hop_size; j++) {
     219        data[i][j] = 0.;
     220      }
     221    }
     222  }
     223
    173224}
    174225
    175226uint_t aubio_source_sndfile_get_samplerate(aubio_source_sndfile_t * s) {
    176227  return s->samplerate;
     228}
     229
     230uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {
     231  return s->input_channels;
     232}
     233
     234uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
     235  uint_t resampled_pos = (uint_t)ROUND(pos * s->input_samplerate * 1. / s->samplerate);
     236  return sf_seek (s->handle, resampled_pos, SEEK_SET);
    177237}
    178238
  • src/io/source_sndfile.h

    rb429b68 r6d44595  
    7575/**
    7676
     77  read polyphonic vector of length hop_size from source object
     78
     79  \param s source object, created with ::new_aubio_source_sndfile
     80  \param read_to ::fmat_t of data to read to
     81  \param read upon returns, equals to number of frames actually read
     82
     83  Upon returns, `read` contains the number of frames actually read from the
     84  source. `hop_size` if enough frames could be read, less otherwise.
     85
     86*/
     87void aubio_source_sndfile_do_multi(aubio_source_sndfile_t * s, fmat_t * read_to, uint_t * read);
     88
     89/**
     90
    7791  get samplerate of source object
    7892
     
    8296*/
    8397uint_t aubio_source_sndfile_get_samplerate(aubio_source_sndfile_t * s);
     98
     99/**
     100
     101  get number of channels of source object
     102
     103  \param s source object, created with ::new_aubio_source_sndfile
     104  \return number of channels
     105
     106*/
     107uint_t aubio_source_sndfile_get_channels (aubio_source_sndfile_t * s);
     108
     109/**
     110
     111  seek source object
     112
     113  \param s source object, created with ::new_aubio_source_sndfile
     114  \param pos position to seek to, in frames
     115
     116  \return 0 if sucessful, non-zero on failure
     117
     118*/
     119uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t *s, uint_t pos);
    84120
    85121/**
  • tests/src/io/test-source.c

    rb429b68 r6d44595  
    3737  do {
    3838    aubio_source_do(s, vec, &read);
    39     // fvec_print (vec);
     39    fvec_print (vec);
    4040    n_frames += read;
    4141  } while ( read == hop_size );
Note: See TracChangeset for help on using the changeset viewer.