Creating an envelope

edited February 2014

I'm hoping someone on here will be able to point me in the right direction with regards to creating an envelope.

My aim is to create an envelope for AEAudioFilePlayer with at the very least an attack and release. Where I'm at currently is that I've setup a timing callback within a subclassed version of AEAudioFilePlayer, and am successfully receiving calls to this function. From here I have been able to alter the 'volume' property in order to create a change in volume over time.

The problem that I foresee with this approach is that it incurs the objective-c messaging overhead as I'm altering it via the dot operator, which will cause things to slow down later as I create more instances. I'm also doubtful as too how often the volume property is accessed within the engine for the same reason, so I'm assuming that I can get finer control of the gain over time via a different approach.

Can anyone shed some light on how I would achieve this?

Thanks in advance!

Comments

  • Hey @SteveB - Yeah, changing the volume property's probably not the way to go. Instead, I'd be actually multiplying the samples in the callback function (you'll need to make a new callback function that calls the base class's one, I'd say - you'll probably also need an extern definition in your subclass file).

    I suggest using the Accelerate framework, which has very nice vDSP_vrampmul function that generates and applies a ramp to a vector and works very quickly. Then basically keep track of the current gain as an instance variable and use it with each callback run.

  • Does anyone have any working example code for an envelope? I will need one for my app as well.

Sign In or Register to comment.