Re: Asynchronous PlayAudioFile Sample
Re: Asynchronous PlayAudioFile Sample
- Subject: Re: Asynchronous PlayAudioFile Sample
- From: Philippe Wicker <email@hidden>
- Date: Mon, 29 Mar 2004 09:20:49 +0200
On Mar 28, 2004, at 6:09 AM, Roger Eastman wrote:
>
Has anyone adapted the sample code of "PlayAudioFile" from
>
CoreAudioSDK1.3.1 to play more than one sound at the same time? It
>
seems like such a simple thing, but I cannot find any documentation or
>
sample code anywhere on this. I'm looking for something short and to
>
the point, but anything will do.
I cannot tell you how to modify PlayAudioFile because I use my own code
to play audio files. The basic idea to play several files (sounds) from
the same RenderCallback is to build a list of files that are to be
played simultaneously, to call the method that reads data (and possibly
convert the format) from each file, and then mix these file individual
buffers (e.g. using a MatrixMixer) before returning from the
RenderCallback.
>
Also, if you know how to make the sounds loop, I would love to know!
>
Thanks in advance.
This is how I do: I use 3 buffers (chunks) for each file. First two
buffers are used for sequential reading based on a ping-pong algorithm
(same as FileAudioPlay). The third buffer caches the audio data
starting from the left locator. This buffer is there to help avoiding
glitches when jumping back from right to left locator. Access to file
data is handled at 2 levels: a 1st level - the body of the
RenderCallback - which manages loop locators and only knows about
rendered data (ie converted to the output stream format), and a 2nd
level which manages disk chunk accesses and conversion from file format
to stream format (using an AUConverter). Above mentioned buffers
contain data with the file format. Splitting the work into these 2
levels allows me to rely on the AUConverter to know the actual size to
fetch from disk.
When the "read head" is somewhere between the left and right locators,
the access to the file data is sequential and first 2 chunks are used.
The 1st level code calls FillComplexBuffer with the requested render
buffer frame size. The 2nd level code (actually the ACInputProc code)
gets the size needed by the AUConverter and fetches these data from the
chunks in memory, possibly issuing disk read command to the feeder
thread when a chunk boundary has been crossed.
When the buffer to render contains the right locator, the 1st level
code (the RenderCallback) split the requested size in two: a first part
corresponding to the frames between the current position and the right
locator, and a second part corresponding to the frames between the
**left** locator and the remaining requested size. It then calls
FillComplexBuffer twice with each size setting a flag (a class data
member) telling the 2nd level code (the ACInputProc) that the first
call is a "standard" sequential access, while the second call is a jump
back to the left locator. Using this flag, the ACInputProc code is able
to fetch disk data from the correct chunk.
A couple of month ago I published sources of a file reader implementing
looping. This code is an old code (and a bit buggy) which do not
reflect exactly the above technique (1st and 2nd levels are mixed in
the RenderCallback which makes the code somehow clumsy). I've just
began to rework it and will post an updated version (which includes a
demo of the AUVarispeed BTW) as soon it is available. In the meantime
you may have a look at it going to:
http://homepage.mac.com/pwicker/
Have a look at ATSingleFileReader::GetSequentialData (the
RenderCallback body) and ATAudioFileReaderBase::GetData methods (the
ACInputProc body).
Feel free to mail me if you need.
>
>
Roger Eastman
>
_______________________________________________
>
coreaudio-api mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
Do not post admin requests to the list. They will be ignored.
>
>
Philippe Wicker
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.