Using vecLib/vDSP to create a sine tone generator with an envelope

788 views Asked by At

I want to create a sine tone generator with the Accelerate framework. I'd like my generator to have an attack/release setting (i.e., an amplitude envelope).

I understand how to create a vector full of sine values. What I don't know is how to apply an amplitude envelope to my vector data.

I know I could create a ramped vector using vDSP_vgen to create a linear volume envelope vector and multiply my sine vector by my envelope vector. This seems wasteful, though, because I'm dealing with many data points and creating an intermediate vector just to store the amplitude envelope is quite wasteful of memory in my environment.

What's the best way to work with an amplitude envelope with the Accelerate framework?

2

There are 2 answers

0
hotpaw2 On

You don't have to use only vector functions to create or operate on vectors. Vector functions are useful if they exist and are faster. I would benchmark the sequence of vector operations against creating your sine with envelope using calls to your envelope() * sinf() for each vector element, and see which is faster on your iOS test devices.

If you have enough memory to keep long intermediate vectors around and reuse them (for instance reuse envelopes), this may provide performance boosts to subsequent iterations. The is a typical memory use versus performance Ytrade-off.

0
justin On

for musical applications, a linear amp envelope is not very common/useful.

for a nonlinear ramp, your primary options are:

  1. create a buffer to multiply by, which is the length of the envelope -- then use vdsp's multiply.
  2. just multiply by an envelope values you generate on the fly.