On 07/01/2010, at 11:55 AM, Chunk 1978 wrote:

> i would *love* to find out how to fade the volume similar to how core
> animation animates, by simply supplying a target and a duration and
> allowing it to work out the details with precisely and automatically,
> but i'm doubtful that's possible.


Sure it's possible.

Just use a timer (set to repeat) which decrements the volume according to the 
rate schedule you've set. When it's got there, it can invalidate itself. The 
functionality could be encapsulated into a fader object associated with the 
audio player object, analogous to NSAnimation. In fact it could even use or 
subclass NSAnimation, since all that does is to perform a task piecemeal over a 
period of time - it is not restricted to visual operations.

You shouldn't need to worry about the overhead of the method call itself, 
especially with a repeating timer - that already takes into account its own 
latency. Just set the timer rate to some reasonable speed - say, every 16mS, 
and calculate what the volume level should be given the elapsed time and the 
target end point. That sort of calculation is totally proof against variations 
caused by arbitrary delays in the system - at any given point in time, the 
volume is set to what it should be at that time. If there are delays, the 
effect is to have fewer steps, not incorrect volume levels. This is equivalent 
to dropping frames for a visual animation - the positions of objects are where 
they should be no matter how many or few frames get actually displayed.

You might also give some attention to the fact that the human ear has a 
logarithmic response to volume, so you probably need a geometric change, not a 
linear one.

n.b. I have implemented something very similar to create an audio "ducking" 
effect where audio on one channel (DJ voice) fades the music on another channel 
then fades it back up smoothly. It definitely works.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to