Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Playing "silence" to an AudioQueue (with VBR format)




On Jan 22, 2008, at 6:51 PM, Neil Clayton wrote:

I've successfully got a playthru working between two AudioQueues, in PCM.

I've two callbacks. One for an input queue and the other for an output queue. The input callback receives data and copies it to an internal array, which the output callback can then use to feed the output queue.

For VBR - I've got it "kind of working" - I hear a little audio (perhaps 1-2 seconds), before it stops.

It appears to be because the output callback (to the speakers) is called more often than the input callback, and sometimes no data is available because the input callback is called perhaps only twice a second.

You should have a look through the CAPlayThrough example - it shows you how to varispeed so you can do playthrough between different devices (including different sample rates) - using queues the way you are is not going to work without adjusting for the drift between the two devices



(But as a matter of form - if you have nothing to play with a queue, just don't scheduled anything. If the AQ Object gets to a place where it has not data to play, it just plays silence. So, even with PCM you don't have to enqueue silent buffers just to play silence).


Bill

In this case (no data to present to the output queue), I attempt to queue an empty AudioQueueBuffer, but receive kAudioQueueErr_BufferEmpty as a result.

- (void) handleOutputBuffer:(AudioQueueRef)inAQ bufferRef: (AudioQueueBufferRef)inBuffer {
// Suck off the next element of our queue
OSStatus err = noErr;
if([packetBuffer count] > 0) {
Intermediate *packet = nil;
@synchronized(packetBuffer) {
packet = [packetBuffer objectAtIndex:0];
[packetBuffer removeObject:packet];
}
@try {
[packet copyBufferTo:inBuffer];
err = AudioQueueEnqueueBuffer(queue, inBuffer, numPackets, packet.packetDescriptions);
} @finally {
[packet release];
}
} else {
// Give the buffer back - we can't do anything (we have no data)
err = AudioQueueEnqueueBuffer(queue, inBuffer, 0, nil);
}
if(err) {
[self log:@"Error while enqueing, %ld", err];
}
}


What is the recommended (or any way would be nice) way to send silence and correctly enqueue the buffer if the output format isn't PCM?

I've tried setting the first byte of the buffer to zero, with a size of one (this works for the PCM case) - and while this doesn't return an error, after I do this the output proc for the queue is no longer called (I presume I've confused it's internal state somehow).

--
Regards,
Neil Clayton







_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/coreaudio-api/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/coreaudio-api/email@hidden

This email sent to email@hidden
References: 
 >Playing "silence" to an AudioQueue (with VBR format) (From: Neil Clayton <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.