Mercurial > hg > dmlib
changeset 139:111f3e4b57ad
Improve volume ramping functionality to allow arbitrary length ramps.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 09:25:59 +0300 |
parents | 459a1be2bd0f |
children | 9894b63bb159 |
files | jmixtmpl_c.h jssmix.c jssmix.h |
diffstat | 3 files changed, 31 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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); }
--- 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);