Mercurial > hg > dmlib
diff jssmix.c @ 134:1ba202b448e0
Implement volume and panning ramps (interpolation between callbacks aka "frames")
in the mixer.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 02:47:36 +0300 |
parents | 2edda27f951c |
children | 111f3e4b57ad |
line wrap: on
line diff
--- a/jssmix.c Fri Oct 05 00:36:40 2012 +0300 +++ b/jssmix.c Fri Oct 05 02:47:36 2012 +0300 @@ -385,6 +385,12 @@ { if (mixer->cbCounter <= 0) { + for (i = 0; i < jsetNChannels; i++) + { + JSSChannel *chn = &(mixer->channels[i]); + if (chn->chPlaying && !chn->chMute) + chn->chDeltaV.dw = chn->chDeltaP.dw = 0; + } mixer->cbFunction(mixer, mixer->cbData); mixer->cbCounter = mixer->cbFreq; } @@ -459,13 +465,13 @@ { assert(mixer); - if ((cbFreq < 1) || (cbFreq >= mixer->outFreq)) + if (cbFreq < 1 || cbFreq >= mixer->outFreq) JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS, "Invalid callback frequency given (%i / %i)\n", cbFreq, mixer->outFreq); JSS_LOCK(mixer); - mixer->cbFreq = (mixer->outFreq / cbFreq); + mixer->cbFreq = mixer->outFreq / cbFreq; mixer->cbCounter = 0; //fprintf(stderr, "set(outFreq = %d, cbFreq = %d) = %d\n", mixer->outFreq, cbFreq, mixer->cbFreq); @@ -553,7 +559,22 @@ void jvmSetVolume(JSSMixer * mixer, const int channel, const int volume) { JSS_LOCK(mixer); - mixer->channels[channel].chVolume = volume; + FP_SETHL(mixer->channels[channel].chVolume, volume, 0); + mixer->channels[channel].chDeltaV.dw = 0; + JSS_UNLOCK(mixer); +} + + +void jvmSetVolumeRamp(JSSMixer * mixer, const int channel, const int start, const int end) +{ + DMFixedPoint a, b; + JSS_LOCK(mixer); + FP_SETHL(mixer->channels[channel].chVolume, start, 0); + + FP_SETHL(a, (end - start), 0); + FP_CONV(b, mixer->cbFreq); + FP_DIV_R(mixer->channels[channel].chDeltaV, a, b); + JSS_UNLOCK(mixer); } @@ -563,7 +584,7 @@ int tmp; JSS_LOCK(mixer); - tmp = mixer->channels[channel].chVolume; + tmp = FP_GETH(mixer->channels[channel].chVolume); JSS_UNLOCK(mixer); return tmp; @@ -573,8 +594,7 @@ void jvmSetPos(JSSMixer * mixer, const int channel, const Sint32 pos) { JSS_LOCK(mixer); - FP_SETH(mixer->channels[channel].chPos, pos); - FP_SETL(mixer->channels[channel].chPos, 0); + FP_SETHL(mixer->channels[channel].chPos, pos, 0); JSS_UNLOCK(mixer); } @@ -594,7 +614,20 @@ void jvmSetPan(JSSMixer * mixer, const int channel, const int panning) { JSS_LOCK(mixer); - mixer->channels[channel].chPanning = panning; + FP_SETHL(mixer->channels[channel].chPanning, panning, 0); + mixer->channels[channel].chDeltaP.dw = 0; + JSS_UNLOCK(mixer); +} + + +void jvmSetPanRamp(JSSMixer * mixer, const int channel, const int start, const int end) +{ + DMFixedPoint a, b; + JSS_LOCK(mixer); + FP_SETHL(mixer->channels[channel].chPanning, start, 0); + FP_SETHL(a, (end - start), 0); + FP_CONV(b, mixer->cbFreq); + FP_DIV_R(mixer->channels[channel].chDeltaP, a, b); JSS_UNLOCK(mixer); } @@ -604,7 +637,7 @@ int tmp; JSS_LOCK(mixer); - tmp = mixer->channels[channel].chPanning; + tmp = FP_GETH(mixer->channels[channel].chPanning); JSS_UNLOCK(mixer); return tmp;