Open LearnCocos2D opened 12 years ago
This works for pitch, but breaks for gain. There's a fundamental flaw in my design here that will take some closer inspection to fix...
I thought so too with value ranges from 0 to 1 for pitch and -1 to +1 for pan. Not sure about gain but I would assume it goes from 0 to infinity (or until you lose hearing, whichever comes first).
I've reworked the action system. This should work now.
[musicChannel pitchTo:0.6f duration:3.0f target:self selector:@selector(clockMusicPitchDownEnded)];
This should pitch from 1.0f (the current pitch value) to 0.6f. I noticed that the music started playing faster when the pitch began, so I investigated. It turns out that the setPitch property setter's first value received is not 1.0f but 1.4f. So the actual pitch range goes from 1.4f to 1.0f, not from 1.0f to 0.6f.
The issue does not exist if you pitch back up. Ie this works as expected:
musicChannel.pitch = 0.6f [musicChannel pitchTo:1.0f duration:3.0f target:nil selector:nil];
The issue exists whether Cocos2D or ObjectAL actions are used. I'm not on the latest version but one from earlier this year, possibly January/February 2012. Definitely the ARC-enabled version.
Observations:
startValue = 1.0 realFunction returns 1.0 (1.0 minus inputValue, inputValue is 0) delta is 0.4 This sets the pitch to: 1.0 + 1.0 * 0.4 = 1.4 To be correct (at least for the first call) the realFunction valueForInput should have returned 0 and subsequent calls should return values slightly lower, ie -0.04f.
I believe that adding startValue is incorrect if the reverse function is used (or the reverse function returns incorrect values). The calculation would be correct if startValue were endValue (0.6) or if the reverse function returned values in the range 0.0f to -1.0f. Currently it returns values in the range 1.0f to 0.0f.
After I analyzed this, I found a solution that works for me. Instead of returning 1.0f - inputValue, the reverse function now simply returns the negated inputValue: