IOMemoryDescriptor: Jedai trick for the tortuous
IOMemoryDescriptor: Jedai trick for the tortuous
- Subject: IOMemoryDescriptor: Jedai trick for the tortuous
- From: Michel <email@hidden>
- Date: Sun, 6 Oct 2002 23:08:41 +0100
While playing with IOMemoryDescriptor, I've tried something tortuous that
happens not only to work, but turns out to be extremely useful for a sound
driver
The game is to allocate some memory, get a list of physical ranges it
occupies, and remap them *twice* end to end.
Say, imagine a buffer of 4096 bytes. I you want to copy 4096 bytes in it, but
at offset 50, you need to watch out for it, and 'fold' back to zero when you
reach the end of the buffer.
Now, with my folded mapping I get a memory range of 8192 bytes instead, where
the byte 4096 is ALSO the byte zero. So to copy my 4096 bytes at offset 50, I
just memcpy() them right there at offset 50, and the VM system will
automagically fold back to the beginning of the real memory for me.
To make one of those mapping, allocate a list of IOPhysicalRange that is
twice the number of physical ranges in your original IOMemoryDescriptor,
duplicate the original ranges in that array, then make a new descriptor with
withPhysicalRanges, and map() that. The address you get from
getVirtualAddress() points to twice your physical memory end to end.
Now for a practical use of this:
Imagine two IOAudioEngine that share the same DMA. Since those engine can
start at different time, you can't use a pointer to the beginning of your DMA
for both of them, since there is a time offset. The engine #2 would
potentialy write in audio that has already been played by #1 etc.
If, at performStart() you'd need a pointer to the current playing position in
the buffer, but if you do that, you are screwed because the Engine will write
over the end of it.
So if instead you pass it a pointer to the current playing position *in a
folded mapping* it works perfectly, because the audio that is written past
the technical end of the buffer is folded back to the beginning of it.
I rekon using this trick in the IOAudio*.* would simplify a hell of a lot the
mixer, for a start. One might be able to call clipOutput/convertInput with
whole buffer size all the time; this is BOUND to leverage the optimized loops
we have to write in there.
Michel
_______________________________________________
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.