Changeset 4865e4b for src/io


Ignore:
Timestamp:
Mar 22, 2013, 2:29:19 AM (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:
ae9fd90
Parents:
7982203
Message:

src/io/source*: add _do_multi and _get_channels, really downmix apple_audio

Location:
src/io
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/io/source.c

    r7982203 r4865e4b  
    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
    84105uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
    85106#ifdef __APPLE__
  • src/io/source.h

    r7982203 r4865e4b  
    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);
    79103
    80104/**
  • src/io/source_apple_audio.c

    r7982203 r4865e4b  
    2323#include "aubio_priv.h"
    2424#include "fvec.h"
     25#include "fmat.h"
    2526#include "io/source_apple_audio.h"
    2627
     
    5758  s->path = path;
    5859  s->block_size = block_size;
    59   s->channels = 1;
    6060
    6161  OSStatus err = noErr;
     
    8383  s->samplerate = samplerate;
    8484  s->source_samplerate = fileFormat.mSampleRate;
     85  s->channels = fileFormat.mChannelsPerFrame;
    8586
    8687  AudioStreamBasicDescription clientFormat;
     
    100101  err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
    101102      propSize, &clientFormat);
    102   if (err) { AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); goto beach;}
    103 
    104 #if 0
     103  if (err) {
     104      AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err);
     105#if 1
    105106  // print client and format descriptions
    106107  AUBIO_DBG("Opened %s\n", s->path);
     
    119120  AUBIO_DBG("file/client Format.mReserved         : %6d / %d\n",    (int)fileFormat.mReserved        , (int)clientFormat.mReserved);
    120121#endif
     122      goto beach;
     123  }
    121124
    122125  // compute the size of the segments needed to read the input file
     
    129132    AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);
    130133  } else {
    131     assert (segmentSize == samples );
     134    assert ( segmentSize == samples );
    132135    //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size);
    133136  }
     
    166169  }
    167170
     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  }
    168200  *read = (uint_t)loadedPackets;
    169201  return;
     
    185217
    186218uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
    187   Float64 ratio = (Float64)(s->source_samplerate) / (Float64)(s->samplerate);
    188   OSStatus err = ExtAudioFileSeek(s->audioFile, pos);
     219  SInt64 resampled_pos = (SInt64)ROUND( pos * s->source_samplerate * 1. / s->samplerate );
     220  OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
    189221  if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
    190222  return err;
     
    195227}
    196228
     229uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
     230  return s->channels;
     231}
     232
    197233#endif /* __APPLE__ */
  • src/io/source_apple_audio.h

    r7982203 r4865e4b  
    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);
    85109
    86110/**
  • src/io/source_sndfile.c

    r7982203 r4865e4b  
    159159    data[j] = 0;
    160160    for (i = 0; i < input_channels; i++) {
    161       data[j] += (smpl_t)s->scratch_data[input_channels*j+i];
     161      data[j] += s->scratch_data[input_channels*j+i];
    162162    }
    163163    data[j] /= (smpl_t)input_channels;
     
    173173}
    174174
     175void aubio_source_sndfile_do_multi(aubio_source_sndfile_t * s, fmat_t * read_data, uint_t * read){
     176  uint_t i,j, input_channels = s->input_channels;
     177  /* do actual reading */
     178  sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     179
     180  smpl_t **data;
     181
     182#ifdef HAVE_SAMPLERATE
     183  if (s->ratio != 1) {
     184    AUBIO_ERR("source_sndfile: no multi channel resampling yet");
     185    return;
     186    data = s->input_data->data;
     187  } else
     188#endif /* HAVE_SAMPLERATE */
     189  {
     190    data = read_data->data;
     191  }
     192
     193  /* de-interleaving data */
     194  for (j = 0; j < read_samples / input_channels; j++) {
     195    for (i = 0; i < input_channels; i++) {
     196      data[i][j] = (smpl_t)s->scratch_data[input_channels*j+i];
     197    }
     198  }
     199
     200#ifdef HAVE_SAMPLERATE
     201  if (s->resampler) {
     202    aubio_resampler_do(s->resampler, s->input_data, read_data);
     203  }
     204#endif /* HAVE_SAMPLERATE */
     205
     206  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     207}
     208
    175209uint_t aubio_source_sndfile_get_samplerate(aubio_source_sndfile_t * s) {
    176210  return s->samplerate;
     211}
     212
     213uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {
     214  return s->input_channels;
    177215}
    178216
  • src/io/source_sndfile.h

    r7982203 r4865e4b  
    8585/**
    8686
     87  get number of channels of source object
     88
     89  \param s source object, created with ::new_aubio_source_sndfile
     90  \return number of channels
     91
     92*/
     93uint_t aubio_source_sndfile_get_channels (aubio_source_sndfile_t * s);
     94
     95/**
     96
    8797  seek source object
    8898
Note: See TracChangeset for help on using the changeset viewer.