diff jssmix.c @ 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 1ba202b448e0
children 9894b63bb159
line wrap: on
line diff
--- 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);
 }