Changes in / [5d16185:6ff6d18]
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source.c
r5d16185 r6ff6d18 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h"25 24 #include "io/source.h" 26 25 #ifdef __APPLE__ … … 61 60 } 62 61 63 void 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_SNDFILE68 aubio_source_sndfile_do_multi((aubio_source_sndfile_t *)s->source, data, read);69 #endif /* HAVE_SNDFILE */70 #endif /* __APPLE__ */71 }72 73 62 void del_aubio_source(aubio_source_t * s) { 74 63 if (!s) return; … … 93 82 } 94 83 95 uint_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_SNDFILE100 return aubio_source_sndfile_get_channels((aubio_source_sndfile_t *)s->source);101 #endif /* HAVE_SNDFILE */102 #endif /* __APPLE__ */103 }104 105 uint_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_SNDFILE110 return aubio_source_sndfile_seek ((aubio_source_sndfile_t *)s->source, seek);111 #endif /* HAVE_SNDFILE */112 #endif /* __APPLE__ */113 } -
src/io/source.h
r5d16185 r6ff6d18 70 70 /** 71 71 72 read polyphonic vector of length hop_size from source object73 74 \param s source object, created with ::new_aubio_source75 \param read_to ::fmat_t of data to read to76 \param read upon returns, equals to number of frames actually read77 78 Upon returns, `read` contains the number of frames actually read from the79 source. `hop_size` if enough frames could be read, less otherwise.80 81 */82 void aubio_source_do_multi(aubio_source_t * s, fmat_t * read_to, uint_t * read);83 84 /**85 86 72 get samplerate of source object 87 73 … … 91 77 */ 92 78 uint_t aubio_source_get_samplerate(aubio_source_t * s); 93 94 /**95 96 get channels of source object97 98 \param s source object, created with ::new_aubio_source99 \return channels100 101 */102 uint_t aubio_source_get_channels (aubio_source_t * s);103 104 /**105 106 seek source object107 108 \param s source object, created with ::new_aubio_source109 \param pos position to seek to, in frames110 111 \return 0 if sucessful, non-zero on failure112 113 */114 uint_t aubio_source_seek (aubio_source_t * s, uint_t pos);115 79 116 80 /** -
src/io/source_apple_audio.c
r5d16185 r6ff6d18 23 23 #include "aubio_priv.h" 24 24 #include "fvec.h" 25 #include "fmat.h"26 25 #include "io/source_apple_audio.h" 27 26 … … 38 37 struct _aubio_source_apple_audio_t { 39 38 uint_t channels; 40 uint_t samplerate; //< requested samplerate 41 uint_t source_samplerate; //< actual source samplerate 39 uint_t samplerate; 42 40 uint_t block_size; 43 41 … … 58 56 s->path = path; 59 57 s->block_size = block_size; 58 s->channels = 1; 60 59 61 60 OSStatus err = noErr; … … 82 81 } 83 82 s->samplerate = samplerate; 84 s->source_samplerate = fileFormat.mSampleRate;85 s->channels = fileFormat.mChannelsPerFrame;86 83 87 84 AudioStreamBasicDescription clientFormat; … … 101 98 err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat, 102 99 propSize, &clientFormat); 103 if (err) { 104 AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); 105 #if 1100 if (err) { AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); goto beach;} 101 102 #if 0 106 103 // print client and format descriptions 107 104 AUBIO_DBG("Opened %s\n", s->path); … … 120 117 AUBIO_DBG("file/client Format.mReserved : %6d / %d\n", (int)fileFormat.mReserved , (int)clientFormat.mReserved); 121 118 #endif 122 goto beach;123 }124 119 125 120 // compute the size of the segments needed to read the input file … … 132 127 AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate); 133 128 } else { 134 assert ( 129 assert (segmentSize == samples ); 135 130 //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size); 136 131 } … … 149 144 UInt32 c, v, loadedPackets = s->block_size; 150 145 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;} 152 147 153 148 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 176 171 } 177 172 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 zeros193 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 207 173 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 208 174 OSStatus err = noErr; … … 216 182 } 217 183 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 225 184 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) { 226 185 return s->samplerate; 227 186 } 228 187 229 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {230 return s->channels;231 }232 233 188 #endif /* __APPLE__ */ -
src/io/source_apple_audio.h
r5d16185 r6ff6d18 76 76 /** 77 77 78 read polyphonic vector of length hop_size from source object79 80 \param s source object, created with ::new_aubio_source_apple_audio81 \param read_to ::fmat_t of data to read to82 \param read upon returns, equals to number of frames actually read83 84 Upon returns, `read` contains the number of frames actually read from the85 source. `hop_size` if enough frames could be read, less otherwise.86 87 */88 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t * s, fmat_t * read_to, uint_t * read);89 90 /**91 92 78 get samplerate of source object 93 79 … … 97 83 */ 98 84 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s); 99 100 /**101 102 get channels of source object103 104 \param s source object, created with ::new_aubio_source_apple_audio105 \return number of channels106 107 */108 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s);109 110 /**111 112 seek source object113 114 \param s source object, created with ::new_aubio_source115 \param pos position to seek to, in frames116 117 \return 0 if sucessful, non-zero on failure118 119 */120 uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos);121 85 122 86 /** -
src/io/source_sndfile.c
r5d16185 r6ff6d18 27 27 28 28 #include "aubio_priv.h" 29 #include "source_sndfile.h" 29 30 #include "fvec.h" 30 #include "fmat.h"31 #include "source_sndfile.h"32 31 33 32 #include "temporal/resampler.h" … … 160 159 data[j] = 0; 161 160 for (i = 0; i < input_channels; i++) { 162 data[j] += s->scratch_data[input_channels*j+i];161 data[j] += (smpl_t)s->scratch_data[input_channels*j+i]; 163 162 } 164 163 data[j] /= (smpl_t)input_channels; … … 172 171 173 172 *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 183 void 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_SAMPLERATE191 if (s->ratio != 1) {192 AUBIO_ERR("source_sndfile: no multi channel resampling yet");193 return;194 //data = s->input_data->data;195 } else196 #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_SAMPLERATE209 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 224 173 } 225 174 226 175 uint_t aubio_source_sndfile_get_samplerate(aubio_source_sndfile_t * s) { 227 176 return s->samplerate; 228 }229 230 uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {231 return s->input_channels;232 }233 234 uint_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);237 177 } 238 178 -
src/io/source_sndfile.h
r5d16185 r6ff6d18 75 75 /** 76 76 77 read polyphonic vector of length hop_size from source object78 79 \param s source object, created with ::new_aubio_source_sndfile80 \param read_to ::fmat_t of data to read to81 \param read upon returns, equals to number of frames actually read82 83 Upon returns, `read` contains the number of frames actually read from the84 source. `hop_size` if enough frames could be read, less otherwise.85 86 */87 void aubio_source_sndfile_do_multi(aubio_source_sndfile_t * s, fmat_t * read_to, uint_t * read);88 89 /**90 91 77 get samplerate of source object 92 78 … … 96 82 */ 97 83 uint_t aubio_source_sndfile_get_samplerate(aubio_source_sndfile_t * s); 98 99 /**100 101 get number of channels of source object102 103 \param s source object, created with ::new_aubio_source_sndfile104 \return number of channels105 106 */107 uint_t aubio_source_sndfile_get_channels (aubio_source_sndfile_t * s);108 109 /**110 111 seek source object112 113 \param s source object, created with ::new_aubio_source_sndfile114 \param pos position to seek to, in frames115 116 \return 0 if sucessful, non-zero on failure117 118 */119 uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t *s, uint_t pos);120 84 121 85 /** -
tests/src/io/test-source.c
r5d16185 r6ff6d18 37 37 do { 38 38 aubio_source_do(s, vec, &read); 39 fvec_print (vec);39 // fvec_print (vec); 40 40 n_frames += read; 41 41 } while ( read == hop_size );
Note: See TracChangeset
for help on using the changeset viewer.