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: Interleave / Deinterleave Arrays



On Nov 2, 2005, at 6:30 AM, Holger Bettag wrote:

On Wed, 2 Nov 2005, Olivier Tristan wrote:

Rustam Muginov wrote:

[...]
Here is an example

float src[] = { 13.f, 22.f, 45.f, 3.f, 6.f, 8.f, 7.f, 1.f, 2.f)
Let's say this is an audio data array with 3 channels
so I would like to deinterleave this array into 3 other C arrays.

Results:
float *dst1 which contains 13.f, 3.f and 7.f
float *dst2 which contains 22.f, 6.f and 1.f
float *dst3 which contains 45.f, 8.f and 2.f

For interleaving, it takes dst1, dst2 and dst3 and generate an array
equivalent to src given a number of "channels".

So it's not on a vector basis but on a whole array.

If the number of channels does not vary a whole lot, you could write
specific routines for each case. Some simple cases (e.g. two or four
channels) can use the predefined pack and unpack primitives, while other
cases need the more general vector permute. In case you only ever process
relatively short blocks of data that are known to reside in the cache, you
can further improve performance with creative use of vector select in
parallel with vector permute (only for certain values of number of
channels).


Programming would be simplified a lot if you could guarantee that all
participating arrays have sizes divisible by four, and are aligned in
memory.

Even if the number of channels varies widely, there might still be a
fairly small number of cases that cover most uses of the function. So it
would pay off to have special case routines for these most frequent
operations.

If you take Holger's suggestion of using separate functions for different numbers of channels then you could use the vDSP_ctoz() and vDSP_ztoc() functions to do 2-channel (de)interleaving. Their purpose is to convert complex arrays into split planar arrays but that is effectively the same thing as (de)interleaving for 2-channel data.


{ re0, im0 } { re1, im1 }, etc. --> { re0 re1 ... } { im0 im1 ... }

These functions have alignment restrictions in order to use the vectorized version so...

I would look into using the CoreAudio AudioConverter APIs [<AudioToolbox/AudioConverter.h>] to do arbitrary (de)interleaving since the AudioConverters have optimized routines for this operation.

http://developer.apple.com/documentation/MusicAudio/Reference/ CoreAudio/audio_toolbox/chapter_4_section_2.html

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

This email sent to email@hidden
References: 
 >Interleave / Deinterleave Arrays (From: Olivier Tristan <email@hidden>)
 >Re: Interleave / Deinterleave Arrays (From: Rustam Muginov <email@hidden>)
 >Re: Interleave / Deinterleave Arrays (From: Olivier Tristan <email@hidden>)
 >Re: Interleave / Deinterleave Arrays (From: Holger Bettag <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.