Changes in src/io/source_apple_audio.c [8c43bf7:4865e4b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_apple_audio.c
r8c43bf7 r4865e4b 23 23 #include "aubio_priv.h" 24 24 #include "fvec.h" 25 #include "fmat.h" 25 26 #include "io/source_apple_audio.h" 26 27 … … 37 38 struct _aubio_source_apple_audio_t { 38 39 uint_t channels; 39 uint_t samplerate; 40 uint_t samplerate; //< requested samplerate 41 uint_t source_samplerate; //< actual source samplerate 40 42 uint_t block_size; 41 43 … … 56 58 s->path = path; 57 59 s->block_size = block_size; 58 s->channels = 1;59 60 60 61 OSStatus err = noErr; … … 81 82 } 82 83 s->samplerate = samplerate; 84 s->source_samplerate = fileFormat.mSampleRate; 85 s->channels = fileFormat.mChannelsPerFrame; 83 86 84 87 AudioStreamBasicDescription clientFormat; … … 98 101 err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat, 99 102 propSize, &clientFormat); 100 if (err) { AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); goto beach;}101 102 #if 0103 if (err) { 104 AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err); 105 #if 1 103 106 // print client and format descriptions 104 107 AUBIO_DBG("Opened %s\n", s->path); … … 117 120 AUBIO_DBG("file/client Format.mReserved : %6d / %d\n", (int)fileFormat.mReserved , (int)clientFormat.mReserved); 118 121 #endif 122 goto beach; 123 } 119 124 120 125 // compute the size of the segments needed to read the input file … … 127 132 AUBIO_WRN("up-sampling %s from %0.2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate); 128 133 } else { 129 assert ( segmentSize == samples );134 assert ( segmentSize == samples ); 130 135 //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size); 131 136 } … … 144 149 UInt32 c, v, loadedPackets = s->block_size; 145 150 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;} 147 152 148 153 short *data = (short*)s->bufferList.mBuffers[0].mData; … … 164 169 } 165 170 171 *read = (uint_t)loadedPackets; 172 return; 173 beach: 174 *read = 0; 175 return; 176 } 177 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 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 } 166 200 *read = (uint_t)loadedPackets; 167 201 return; … … 182 216 } 183 217 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 184 225 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) { 185 226 return s->samplerate; 186 227 } 187 228 229 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) { 230 return s->channels; 231 } 232 188 233 #endif /* __APPLE__ */
Note: See TracChangeset
for help on using the changeset viewer.