Re: [NOOB] Layering multiple AIFFs in PCM format?
Re: [NOOB] Layering multiple AIFFs in PCM format?
- Subject: Re: [NOOB] Layering multiple AIFFs in PCM format?
- From: Kurt Revis <email@hidden>
- Date: Fri, 12 Aug 2005 00:50:01 -0700
On Aug 11, 2005, at 10:36 PM, Quinn Taylor wrote:
Basically, I want to composite as many as 5 source sounds (for
various subdivisions) together in a repeating pattern. The user
will be able to control the volume/muting of each individual sound,
as well as the master volume. The interval between these sounds is
determined by the tempo selected.
My goals/guidelines include the following:
- Make the code processor-independent.
This should be trivial... there's absolutely no reason you'd need
assembly code to do any of this.
- Blend sound from source AIFFs overtop of one another (at quicker
tempos).
You should look into using the mixer audio unit to do this. You just
set it up to have 5 input streams, one for each of your source
sounds. You can then set the volume, mute, pan, etc. on each input
stream separately, as well as changing the master volume.
Then all you have to do is figure out how to compute each of the
input streams. You're just going to be reading from your source
sounds, but how you keep track of this is up to you.
- Cache the repeating pattern in PCM format, facilitating AIFF
export in the future.
- Cache the pattern in blocks of either 1 beat or 1 measure.
(Improve accuracy, reduce latency)
- Cause the pattern to be re-cached when the tempo or volumes are
changed while playing.
You're better off getting it to play via the mixer first, then see if
you really need this. I bet you don't, and it will add considerable
complexity. If you want to do AIFF export you can still just grab
data from the mixer output and write it out.
- Loop playback of this pattern while Play is enabled; halt
abruptly when playback is stopped.
This would be up to you (deciding what data you put in your input
streams), but it really shouldn't be difficult.
I also need guidance in creating a high-priority thread for Core
Audio I/O so I don't have latency in creating the pattern cache or
in playback.
Why do you think you need this? I bet you don't. If your source
sounds are loaded completely into memory (which they should be, if
they're short -- at least to start with), then you can just copy data
from them without worrying too much about blocking issues whatsoever.
So far I have looked at PlayBufferedSoundFile, which looks
moderately useful, but utilizes Mach calls for VM management.
1) This example is probably overkill for your needs. It's designed
for reading long sounds from a file on disk -- think iTunes. You can
probably start out by loading your sounds completely into memory,
which is much easier to deal with.
2) What's wrong with the Mach VM calls? Anyway, they are not all that
important. I'm using them to let the ring buffer class have a
slightly nicer API, since you don't have to worry about the point
when the buffer wraps around, but that's all. If you're not reading
from disk, you might not need a ring buffer at all. If you do need
it, it would be easy to make it work without the VM goofiness, or you
could use a different one (I think there's one in the CoreAudio
example code somewhere).
I'm not familiar enough with Core Audio to know if this is the type
of thing that should be an Audio Unit bundle, or just straight code
inside my Cocoa app.
You might use one or more AUs, but you don't need to write your own.
Also, although my code is in Objective-C, I have no aversion to
using C calls for Core Audio.
Well, good, because you don't exactly have a choice!
(I prefer to avoid anything in C++.)
That's too bad, because there's a lot of good working code in the
CoreAudio examples, written by the experts :) There's a lot to wrap
your head around, but it's worth getting familiar with.
If I didn't make it clear enough yet: START SIMPLE. Figure out how
to load one sound file into memory, and then how to play it. Start
with playing it once, then loop it. Then figure out how to hook up
the mixer AU, how to play multiple sounds, and so forth. By the time
you've done all this, you'll have a very good grounding in how it
works, and you'll understand far better how you want to organize the
whole working system. If you try to jump in and do it all at once,
especially when you don't understand all the issues involved, you'll
probably never get any of it to work.
--
Kurt Revis
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:
This email sent to email@hidden