Changeset 222b176
- Timestamp:
- Feb 23, 2014, 4:56:54 PM (11 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
- Files:
-
- 1 added
- 2 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; -
src/io/sink_apple_audio.h
raf97786 r222b176 1 1 /* 2 Copyright (C) 2012-201 3Paul Brossier <piem@aubio.org>2 Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 40 40 #endif 41 41 42 /** sink_apple_audio object */ 42 43 typedef struct _aubio_sink_apple_audio_t aubio_sink_apple_audio_t; 43 44 … … 53 54 Creates a new sink object. 54 55 56 If samplerate is set to 0, the creation of the file will be delayed until 57 both ::aubio_sink_preset_samplerate and ::aubio_sink_preset_channels have 58 been called. 59 55 60 */ 56 61 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate); 62 63 /** 64 65 preset sink samplerate 66 67 \param s sink, created with ::new_aubio_sink_apple_audio 68 \param samplerate samplerate to preset the sink to, in Hz 69 70 \return 0 on success, 1 on error 71 72 Preset the samplerate of the sink. The file should have been created using a 73 samplerate of 0. 74 75 The file will be opened only when both samplerate and channels have been set. 76 77 */ 78 uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate); 79 80 /** 81 82 preset sink channels 83 84 \param s sink, created with ::new_aubio_sink_apple_audio 85 \param channels number of channels to preset the sink to 86 87 \return 0 on success, 1 on error 88 89 Preset the samplerate of the sink. The file should have been created using a 90 samplerate of 0. 91 92 The file will be opened only when both samplerate and channels have been set. 93 94 */ 95 uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels); 96 97 /** 98 99 get samplerate of sink object 100 101 \param s sink object, created with ::new_aubio_sink_apple_audio 102 \return samplerate, in Hz 103 104 */ 105 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s); 106 107 /** 108 109 get channels of sink object 110 111 \param s sink object, created with ::new_aubio_sink_apple_audio 112 \return number of channels 113 114 */ 115 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s); 57 116 58 117 /** … … 66 125 */ 67 126 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write); 127 128 /** 129 130 write polyphonic vector of length hop_size to sink 131 132 \param s sink, created with ::new_aubio_sink_apple_audio 133 \param write_data ::fmat_t samples to write to sink 134 \param write number of frames to write 135 136 */ 137 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write); 68 138 69 139 /**
Note: See TracChangeset
for help on using the changeset viewer.