Changeset 222b176 for src/io/sink_apple_audio.c
- Timestamp:
- Feb 23, 2014, 4:56:54 PM (10 years ago)
- 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:
- 870ad70
- Parents:
- af97786
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_apple_audio.c
raf97786 r222b176 1 1 /* 2 Copyright (C) 2012 Paul Brossier <piem@aubio.org>2 Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 25 25 #include "aubio_priv.h" 26 26 #include "fvec.h" 27 #include "fmat.h" 27 28 #include "io/sink_apple_audio.h" 28 29 … … 39 40 char_t *getPrintableOSStatusError(char_t *str, OSStatus error); 40 41 42 uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s); 43 41 44 #define MAX_SIZE 4096 // the maximum number of frames that can be written at a time 42 45 … … 55 58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) { 56 59 aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t); 57 s->samplerate = samplerate;58 s->channels = 1;59 60 s->path = uri; 60 61 s->max_frames = MAX_SIZE; 61 62 s->async = true; 63 64 s->samplerate = 0; 65 s->channels = 0; 66 67 // negative samplerate given, abort 68 if ((sint_t)samplerate < 0) goto beach; 69 // zero samplerate given. do not open yet 70 if ((sint_t)samplerate == 0) return s; 71 72 s->samplerate = samplerate; 73 s->channels = 1; 74 75 if (aubio_sink_apple_audio_open(s) != AUBIO_OK) { 76 // open failed, abort 77 goto beach; 78 } 79 80 return s; 81 beach: 82 AUBIO_FREE(s); 83 return NULL; 84 } 85 86 uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate) 87 { 88 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 89 s->samplerate = samplerate; 90 // automatically open when both samplerate and channels have been set 91 if (s->samplerate != 0 && s->channels != 0) { 92 return aubio_sink_apple_audio_open(s); 93 } 94 return AUBIO_OK; 95 } 96 97 uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels) 98 { 99 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 100 s->channels = channels; 101 // automatically open when both samplerate and channels have been set 102 if (s->samplerate != 0 && s->channels != 0) { 103 return aubio_sink_apple_audio_open(s); 104 } 105 return AUBIO_OK; 106 } 107 108 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s) 109 { 110 return s->samplerate; 111 } 112 113 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s) 114 { 115 return s->channels; 116 } 117 118 uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s) { 119 120 if (s->samplerate == 0 || s->channels == 0) return AUBIO_FAIL; 62 121 63 122 AudioStreamBasicDescription clientFormat; … … 74 133 75 134 AudioFileTypeID fileType = kAudioFileWAVEType; 76 CFURLRef fileURL = getURLFromPath( uri);135 CFURLRef fileURL = getURLFromPath(s->path); 77 136 bool overwrite = true; 78 137 OSStatus err = noErr; … … 91 150 goto beach; 92 151 } 93 return s;152 return AUBIO_OK; 94 153 95 154 beach: 96 AUBIO_FREE(s); 97 return NULL; 155 return AUBIO_FAIL; 98 156 } 99 157 … … 142 200 } 143 201 202 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) { 203 OSStatus err = noErr; 204 UInt32 c, v; 205 short *data = (short*)s->bufferList.mBuffers[0].mData; 206 if (write > s->max_frames) { 207 AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames); 208 write = s->max_frames; 209 } 210 smpl_t **buf = write_data->data; 211 212 if (buf) { 213 for (c = 0; c < s->channels; c++) { 214 for (v = 0; v < write; v++) { 215 data[v * s->channels + c] = 216 FLOAT_TO_SHORT(buf[c][v]); 217 } 218 } 219 } 220 if (s->async) { 221 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList); 222 223 if (err) { 224 char_t errorstr[20]; 225 AUBIO_ERROR("sink_apple_audio: error while writing %s " 226 "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path, 227 getPrintableOSStatusError(errorstr, err)); 228 s->async = false; 229 } else { 230 return; 231 } 232 233 } else { 234 err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList); 235 236 if (err) { 237 char_t errorstr[20]; 238 AUBIO_ERROR("sink_apple_audio: error while writing %s " 239 "in ExtAudioFileWrite (%s)\n", s->path, 240 getPrintableOSStatusError(errorstr, err)); 241 } 242 } 243 return; 244 } 245 144 246 uint_t aubio_sink_apple_audio_close(aubio_sink_apple_audio_t * s) { 145 247 OSStatus err = noErr;
Note: See TracChangeset
for help on using the changeset viewer.