# HG changeset patch # User Matti Hamalainen # Date 1349418359 -10800 # Node ID 111f3e4b57ad8084b3d04d309700374440e6cb85 # Parent 459a1be2bd0f8d83bf19442f1c51b05f4f56f7c4 Improve volume ramping functionality to allow arbitrary length ramps. diff -r 459a1be2bd0f -r 111f3e4b57ad jmixtmpl_c.h --- a/jmixtmpl_c.h Fri Oct 05 05:43:17 2012 +0300 +++ b/jmixtmpl_c.h Fri Oct 05 09:25:59 2012 +0300 @@ -15,7 +15,7 @@ *ap = addBuffer, *tr = chn->chPrevR, *tl = chn->chPrevL; - int strideLength = 0; + int strideLength = 0, tmpVolumeD = chn->chVolumeD;; JMIXER_SAMPLE_TYPE *sp = (JMIXER_SAMPLE_TYPE *) chn->chData; @@ -26,12 +26,17 @@ JMIXER_FUNC JMIXER_DEBUG JMIXER_NEXT - FP_ADD(tmpVolume, tmpDeltaV); + if (tmpVolumeD) + { + tmpVolumeD--; + FP_ADD(tmpVolume, tmpDeltaV); + } strideLength++; } chn->chPos = tmpPos; chn->chVolume = tmpVolume; + chn->chVolumeD = tmpVolumeD; return strideLength; } #endif diff -r 459a1be2bd0f -r 111f3e4b57ad jssmix.c --- a/jssmix.c Fri Oct 05 05:43:17 2012 +0300 +++ b/jssmix.c Fri Oct 05 09:25:59 2012 +0300 @@ -388,8 +388,8 @@ for (i = 0; i < jsetNChannels; i++) { JSSChannel *chn = &(mixer->channels[i]); - if (chn->chPlaying && !chn->chMute) - chn->chDeltaV.dw = chn->chDeltaP.dw = 0; + chn->chDeltaV.dw = chn->chDeltaP.dw = 0; + chn->chVolumeD = chn->chPanningD = 0; } mixer->cbFunction(mixer, mixer->cbData); mixer->cbCounter = mixer->cbFreq; @@ -560,19 +560,24 @@ { JSS_LOCK(mixer); FP_SETHL(mixer->channels[channel].chVolume, volume, 0); + mixer->channels[channel].chVolumeD = 0; mixer->channels[channel].chDeltaV.dw = 0; JSS_UNLOCK(mixer); } -void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end) +void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len) { + int tmp; DMFixedPoint a, b; JSS_LOCK(mixer); FP_SETHL(mixer->channels[channel].chVolume, start, 0); + tmp = mixer->channels[channel].chVolumeD = + len > 0 ? ((mixer->outFreq * len) / 1000) : mixer->cbFreq; + FP_SETHL(a, (end - start), 0); - FP_CONV(b, mixer->cbFreq); + FP_CONV(b, tmp); FP_DIV_R(mixer->channels[channel].chDeltaV, a, b); JSS_UNLOCK(mixer); @@ -615,19 +620,27 @@ { JSS_LOCK(mixer); FP_SETHL(mixer->channels[channel].chPanning, panning, 0); + mixer->channels[channel].chPanningD = 0; mixer->channels[channel].chDeltaP.dw = 0; JSS_UNLOCK(mixer); } -void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end) +void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len) { + int tmp; DMFixedPoint a, b; JSS_LOCK(mixer); + FP_SETHL(mixer->channels[channel].chPanning, start, 0); + + tmp = mixer->channels[channel].chPanningD = + len > 0 ? ((mixer->outFreq * len) / 1000) : mixer->cbFreq; + FP_SETHL(a, (end - start), 0); - FP_CONV(b, mixer->cbFreq); + FP_CONV(b, tmp); FP_DIV_R(mixer->channels[channel].chDeltaP, a, b); + JSS_UNLOCK(mixer); } diff -r 459a1be2bd0f -r 111f3e4b57ad jssmix.h --- a/jssmix.h Fri Oct 05 05:43:17 2012 +0300 +++ b/jssmix.h Fri Oct 05 09:25:59 2012 +0300 @@ -31,6 +31,9 @@ chPanning, // Panning chDeltaP; + int chVolumeD, + chPanningD; + int chFreq; // Frequency of sampel in Hz Sint32 chSize, // Length of sample in UNITS @@ -135,14 +138,14 @@ int jvmGetFreq(JSSMixer *mixer, const int channel); void jvmSetVolume(JSSMixer *mixer, const int channel, const int volume); -void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end); +void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); int jvmGetVolume(JSSMixer *mixer, const int channel); void jvmSetPos(JSSMixer *mixer, const int channel, const Sint32 pos); Sint32 jvmGetPos(JSSMixer *mixer, const int channel); void jvmSetPan(JSSMixer *mixer, const int channel, const int panning); -void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end); +void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end, const int len); int jvmGetPan(JSSMixer *mixer, const int channel); void jvmMute(JSSMixer *mixer, const int channel, const BOOL mute);