[macstl-dev] Questions on valarray use

Glen Low glen.low at pixelglow.com
Tue Sep 20 18:51:20 WST 2005

  • Previous message: [macstl-dev] Questions on valarray use
  • Next message: [macstl-dev] Questions on valarray use : non-aligned buffers
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]


Stéphane:

On 20/09/2005, at 5:31 PM, Stéphane Letz wrote:

> Hi,
>
> I'm trying to use macstl to optimize audio mixing code, something  
> like the following function:
>
> void
> mix_buffers_with_gain (float*dst, float*src, int nframes, float gain)
> {
>     stdext::valarray <float> vf1 (src, nframes);
>     stdext::valarray <float> vf2 (dst, nframes);
>     vf2 += vf1 * gain;
> }
>
> But it seems that dst and src buffers content is actually copied in  
> vst1 and vst2.
> It is possible to use valarray with buffers already allocated so  
> that to do the computation on these arrays?
>
> Thanks

Yes, you may. As of 0.3.1 you can use the refarray class which  
doesn't make copies of the data and lets you be responsible for any  
cleanup e.g.

stdext::refarray <float> vf1 (src, nframes);
stdext::refarray <float> vf2 (dst, nframes);
vf2 += vf1 * gain;

You may also find the statarray class useful too, as it uses stack or  
inline memory rather than allocating from heap memory, but you have  
to fix the number of elements.

Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen




  • Previous message: [macstl-dev] Questions on valarray use
  • Next message: [macstl-dev] Questions on valarray use : non-aligned buffers
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

More information about the macstl-dev mailing list