comparison libao2/ao_macosx.c @ 15722:b53c4b26dc96

removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
author nplourde
date Tue, 14 Jun 2005 12:41:42 +0000
parents f46eae5e271b
children 6e994905f77b
comparison
equal deleted inserted replaced
15721:eec6ace22741 15722:b53c4b26dc96
72 72
73 typedef struct ao_macosx_s 73 typedef struct ao_macosx_s
74 { 74 {
75 /* AudioUnit */ 75 /* AudioUnit */
76 AudioUnit theOutputUnit; 76 AudioUnit theOutputUnit;
77 AudioConverterRef theConverter;
78 int packetSize; 77 int packetSize;
79 78
80 /* Ring-buffer */ 79 /* Ring-buffer */
81 /* does not need explicit synchronization, but needs to allocate 80 /* does not need explicit synchronization, but needs to allocate
82 * (num_chunks + 1) * chunk_size memory to store num_chunks * chunk_size 81 * (num_chunks + 1) * chunk_size memory to store num_chunks * chunk_size
153 } 152 }
154 ao->buf_read_pos = (ao->buf_read_pos + len) % ao->buffer_len; 153 ao->buf_read_pos = (ao->buf_read_pos + len) % ao->buffer_len;
155 return len; 154 return len;
156 } 155 }
157 156
158 /* end ring buffer stuff */ 157 OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
159
160 OSStatus ACComplexInputProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
161 { 158 {
162 int amt=buf_used(); 159 int amt=buf_used();
163 int req=(*ioNumberDataPackets)*ao->packetSize; 160 int req=(inNumFrames)*ao->packetSize;
164 161
165 162
166 ioData->mBuffers[0].mData = ao->chunk; 163 ioData->mBuffers[0].mData = ao->chunk;
167 ioData->mBuffers[0].mDataByteSize = req;
168
169 // fprintf(stderr, "##### req=%d amt=%d #####\n", req, amt);
170 164
171 if(amt>req) 165 if(amt>req)
172 amt=req; 166 amt=req;
173 167
174 if(amt) 168 if(amt)
175 read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt); 169 read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt);
176 170
177 if(req-amt) 171 ioData->mBuffers[0].mDataByteSize = amt;
178 memset(ioData->mBuffers[0].mData+amt, 0, req-amt);
179 172
180 return noErr; 173 return noErr;
181 }
182
183 OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
184 {
185 OSStatus err = noErr;
186 void *inInputDataProcUserData = NULL;
187 AudioStreamPacketDescription *outPacketDescription = NULL;
188
189
190 err = AudioConverterFillComplexBuffer(ao->theConverter, ACComplexInputProc, inInputDataProcUserData, &inNumFrames, ioData, outPacketDescription);
191
192 /*Parameters for AudioConverterFillComplexBuffer()
193 converter - the converter being used
194 ACComplexInputProc() - input procedure to supply data to the Audio Converter
195 inInputDataProcUserData - Used to hold any data that needs to be passed on.
196 inNumFrames - The amount of requested data. On output, this number is the amount actually received.
197 ioData - Buffer of the converted data recieved on return
198 outPacketDescription - contains the format of the returned data.
199 */
200
201 if(err)
202 ao_msg(MSGT_AO, MSGL_WARN, "AudioConverterFillComplexBuffer failed status %-8d\n", err);
203
204 return err;
205 } 174 }
206 175
207 static int control(int cmd,void *arg){ 176 static int control(int cmd,void *arg){
208 switch (cmd) { 177 switch (cmd) {
209 case AOCONTROL_SET_DEVICE: 178 case AOCONTROL_SET_DEVICE:
331 ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component (err=%d)\n", err); 300 ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component (err=%d)\n", err);
332 return CONTROL_FALSE; 301 return CONTROL_FALSE;
333 } 302 }
334 303
335 size = sizeof(AudioStreamBasicDescription); 304 size = sizeof(AudioStreamBasicDescription);
336 err = AudioUnitGetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &outDesc, &size); 305 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
337 print_format("destination: ", &outDesc); 306
338 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outDesc, size);
339
340 err = AudioConverterNew(&inDesc, &outDesc, &(ao->theConverter));
341 if (err) { 307 if (err) {
342 ao_msg(MSGT_AO, MSGL_WARN, "Unable to create the AudioConverter component (err=%d)\n", err); 308 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format (err=%d)\n", err);
343 return CONTROL_FALSE; 309 return CONTROL_FALSE;
344 } 310 }
345 311
346 size=sizeof(UInt32); 312 size=sizeof(UInt32);
347 maxFrames=8192; // This was calculated empirically. On MY system almost everything works more or less the same... 313 maxFrames=8192; // This was calculated empirically. On MY system almost everything works more or less the same...
415 int i; 381 int i;
416 OSErr status; 382 OSErr status;
417 383
418 reset(); 384 reset();
419 385
420 AudioConverterDispose(ao->theConverter);
421 AudioOutputUnitStop(ao->theOutputUnit); 386 AudioOutputUnitStop(ao->theOutputUnit);
422 AudioUnitUninitialize(ao->theOutputUnit); 387 AudioUnitUninitialize(ao->theOutputUnit);
423 CloseComponent(ao->theOutputUnit); 388 CloseComponent(ao->theOutputUnit);
424 389
425 free(ao->chunk); 390 free(ao->chunk);