ref: 15b780d08f2ee6f50a9843dc7479349f4deee5a7
parent: 8d87ab8b9ec398cf3831b87dc969a28e278f3105
author: Chris Moeller <kode54@gmail.com>
date: Sun Sep 2 08:56:38 EDT 2012
Fixed most effects applying to background voices
--- a/dumb/src/it/itrender.c
+++ b/dumb/src/it/itrender.c
@@ -1013,6 +1013,15 @@
}
+static void update_smooth_effects_playing(IT_PLAYING *playing)
+{
+ playing->vibrato_time += playing->vibrato_n *
+ (playing->vibrato_speed << 2);
+ playing->tremolo_time += playing->tremolo_speed << 2;
+ playing->panbrello_time += playing->panbrello_speed;
+ if (playing->panbrello_waveform == 3)
+ playing->panbrello_random = (rand() % 129) - 64;
+}
static void update_smooth_effects(DUMB_IT_SIGRENDERER *sigrenderer)
{
@@ -1023,14 +1032,17 @@
IT_PLAYING *playing = channel->playing;
if (playing) {
- playing->vibrato_time += playing->vibrato_n *
- (playing->vibrato_speed << 2);
- playing->tremolo_time += playing->tremolo_speed << 2;
- playing->panbrello_time += playing->panbrello_speed;
- if (playing->panbrello_waveform == 3)
- playing->panbrello_random = (rand() % 129) - 64;
+ update_smooth_effects_playing(playing);
}
}
+
+ for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ IT_PLAYING *playing = sigrenderer->playing[i];
+
+ if (playing) {
+ update_smooth_effects_playing(playing);
+ }
+ }
}
@@ -1064,7 +1076,7 @@
static void update_effects(DUMB_IT_SIGRENDERER *sigrenderer)
{
- int i;
+ int i, j;
if (sigrenderer->globalvolslide) {
sigrenderer->globalvolume += sigrenderer->globalvolslide;
@@ -1148,6 +1160,10 @@
}
if (channel->playing)
channel->playing->channel_volume = channel->channelvolume;
+ for (j = 0; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (sigrenderer->playing[j] && sigrenderer->playing[j]->channel == channel)
+ sigrenderer->playing[j]->channel_volume = channel->channelvolume;
+ }
}
update_tremor(channel);
@@ -1158,81 +1174,128 @@
if (channel->inv_loop_speed) update_invert_loop(channel, playing ? playing->sample : NULL);
- if (playing) {
- playing->slide += channel->portamento;
+ for (j = 0; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (sigrenderer->playing[j] && sigrenderer->playing[j]->channel == channel) break;
+ }
+ if (playing || j < DUMB_IT_N_NNA_CHANNELS) {
+ if (playing) playing->slide += channel->portamento;
+ for (j = 0; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (sigrenderer->playing[j] && sigrenderer->playing[j]->channel == channel)
+ sigrenderer->playing[j]->slide += channel->portamento;
+ }
+
if (channel->okt_toneslide) {
if (channel->okt_toneslide--) {
- playing->note += channel->toneslide;
- if (playing->note >= 120) {
- if (channel->toneslide < 0) playing->note = 0;
- else playing->note = 119;
+ if (playing) {
+ playing->note += channel->toneslide;
+ if (playing->note >= 120) {
+ if (channel->toneslide < 0) playing->note = 0;
+ else playing->note = 119;
+ }
}
+ for (j = 0; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (sigrenderer->playing[j] && sigrenderer->playing[j]->channel == channel) {
+ IT_PLAYING *playing = sigrenderer->playing[j];
+ playing->note += channel->toneslide;
+ if (playing->note >= 120) {
+ if (channel->toneslide < 0) playing->note = 0;
+ else playing->note = 119;
+ }
+ }
+ }
}
} else if (channel->ptm_toneslide) {
if (--channel->toneslide_tick == 0) {
channel->toneslide_tick = channel->ptm_toneslide;
- playing->note += channel->toneslide;
- if (playing->note >= 120) {
- if (channel->toneslide < 0) playing->note = 0;
- else playing->note = 119;
+ if (playing) {
+ playing->note += channel->toneslide;
+ if (playing->note >= 120) {
+ if (channel->toneslide < 0) playing->note = 0;
+ else playing->note = 119;
+ }
+ channel->note = channel->truenote = playing->note;
+ if (channel->toneslide_retrig) {
+ it_playing_reset_resamplers(playing, 0);
+#ifdef END_RAMPING
+ playing->declick_stage = 0;
+ playing->declick_volume = 1.f / 256.f;
+#endif
+ }
}
- channel->note = channel->truenote = playing->note;
- if (channel->toneslide_retrig) {
- it_playing_reset_resamplers(playing, 0);
+ for (j = 0; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (sigrenderer->playing[j] && sigrenderer->playing[j]->channel == channel) {
+ IT_PLAYING *playing = sigrenderer->playing[j];
+ playing->note += channel->toneslide;
+ if (playing->note >= 120) {
+ if (channel->toneslide < 0) playing->note = 0;
+ else playing->note = 119;
+ }
+ if (channel->toneslide_retrig) {
+ it_playing_reset_resamplers(playing, 0);
#ifdef END_RAMPING
- playing->declick_stage = 0;
- playing->declick_volume = 1.f / 256.f;
+ playing->declick_stage = 0;
+ playing->declick_volume = 1.f / 256.f;
#endif
+ }
+ }
}
}
}
- if (sigrenderer->sigdata->flags & IT_LINEAR_SLIDES) {
- if (channel->toneporta && channel->destnote < 120) {
- int currpitch = ((playing->note - 60) << 8) + playing->slide;
- int destpitch = (channel->destnote - 60) << 8;
- if (currpitch > destpitch) {
- currpitch -= channel->toneporta;
- if (currpitch < destpitch) {
- currpitch = destpitch;
- channel->destnote = IT_NOTE_OFF;
- }
- } else if (currpitch < destpitch) {
- currpitch += channel->toneporta;
- if (currpitch > destpitch) {
- currpitch = destpitch;
- channel->destnote = IT_NOTE_OFF;
- }
- }
- playing->slide = currpitch - ((playing->note - 60) << 8);
+ for (j = -1; j < DUMB_IT_N_NNA_CHANNELS; j++) {
+ if (j >= 0) {
+ playing = sigrenderer->playing[j];
+ if (!playing || playing->channel != channel) continue;
}
- } else {
- if (channel->toneporta && channel->destnote < 120) {
- float amiga_multiplier = playing->sample->C5_speed * (1.0f / AMIGA_DIVISOR);
+ if (playing) {
+ if (sigrenderer->sigdata->flags & IT_LINEAR_SLIDES) {
+ if (channel->toneporta && channel->destnote < 120) {
+ int currpitch = ((playing->note - 60) << 8) + playing->slide;
+ int destpitch = (channel->destnote - 60) << 8;
+ if (currpitch > destpitch) {
+ currpitch -= channel->toneporta;
+ if (currpitch < destpitch) {
+ currpitch = destpitch;
+ channel->destnote = IT_NOTE_OFF;
+ }
+ } else if (currpitch < destpitch) {
+ currpitch += channel->toneporta;
+ if (currpitch > destpitch) {
+ currpitch = destpitch;
+ channel->destnote = IT_NOTE_OFF;
+ }
+ }
+ playing->slide = currpitch - ((playing->note - 60) << 8);
+ }
+ } else {
+ if (channel->toneporta && channel->destnote < 120) {
+ float amiga_multiplier = playing->sample->C5_speed * (1.0f / AMIGA_DIVISOR);
- float deltanote = (float)pow(DUMB_SEMITONE_BASE, 60 - playing->note);
- /* deltanote is 1.0 for C-5, 0.5 for C-6, etc. */
+ float deltanote = (float)pow(DUMB_SEMITONE_BASE, 60 - playing->note);
+ /* deltanote is 1.0 for C-5, 0.5 for C-6, etc. */
- float deltaslid = deltanote - playing->slide * amiga_multiplier;
+ float deltaslid = deltanote - playing->slide * amiga_multiplier;
- float destdelta = (float)pow(DUMB_SEMITONE_BASE, 60 - channel->destnote);
- if (deltaslid < destdelta) {
- playing->slide -= channel->toneporta;
- deltaslid = deltanote - playing->slide * amiga_multiplier;
- if (deltaslid > destdelta) {
- playing->note = channel->destnote;
- playing->slide = 0;
- channel->destnote = IT_NOTE_OFF;
+ float destdelta = (float)pow(DUMB_SEMITONE_BASE, 60 - channel->destnote);
+ if (deltaslid < destdelta) {
+ playing->slide -= channel->toneporta;
+ deltaslid = deltanote - playing->slide * amiga_multiplier;
+ if (deltaslid > destdelta) {
+ playing->note = channel->destnote;
+ playing->slide = 0;
+ channel->destnote = IT_NOTE_OFF;
+ }
+ } else {
+ playing->slide += channel->toneporta;
+ deltaslid = deltanote - playing->slide * amiga_multiplier;
+ if (deltaslid < destdelta) {
+ playing->note = channel->destnote;
+ playing->slide = 0;
+ channel->destnote = IT_NOTE_OFF;
+ }
+ }
}
- } else {
- playing->slide += channel->toneporta;
- deltaslid = deltanote - playing->slide * amiga_multiplier;
- if (deltaslid < destdelta) {
- playing->note = channel->destnote;
- playing->slide = 0;
- channel->destnote = IT_NOTE_OFF;
- }
}
}
}
@@ -1967,6 +2030,8 @@
static int process_effects(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry, int ignore_cxx)
{
DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+ IT_PLAYING *playing;
+ int i;
IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
@@ -2023,10 +2088,17 @@
break;
case IT_VOLSLIDE_VIBRATO:
- if (channel->playing) {
- channel->playing->vibrato_speed = channel->lastHspeed;
- channel->playing->vibrato_depth = channel->lastHdepth;
- channel->playing->vibrato_n++;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing) {
+ playing->vibrato_speed = channel->lastHspeed;
+ playing->vibrato_depth = channel->lastHdepth;
+ playing->vibrato_n++;
+ }
}
/* Fall through and process volume slide. */
case IT_VOLUME_SLIDE:
@@ -2122,15 +2194,22 @@
v = channel->lastEF;
channel->lastEF = v;
}
- if (channel->playing) {
- if ((v & 0xF0) == 0xF0)
- channel->playing->slide -= (v & 15) << 4;
- else if ((v & 0xF0) == 0xE0)
- channel->playing->slide -= (v & 15) << 2;
- else if (sigdata->flags & IT_WAS_A_669)
- channel->portamento -= v << 3;
- else
- channel->portamento -= v << 4;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing) {
+ if ((v & 0xF0) == 0xF0)
+ playing->slide -= (v & 15) << 4;
+ else if ((v & 0xF0) == 0xE0)
+ playing->slide -= (v & 15) << 2;
+ else if (i < 0 && sigdata->flags & IT_WAS_A_669)
+ channel->portamento -= v << 3;
+ else if (i < 0)
+ channel->portamento -= v << 4;
+ }
}
}
break;
@@ -2157,15 +2236,22 @@
v = channel->lastEF;
channel->lastEF = v;
}
- if (channel->playing) {
- if ((v & 0xF0) == 0xF0)
- channel->playing->slide += (v & 15) << 4;
- else if ((v & 0xF0) == 0xE0)
- channel->playing->slide += (v & 15) << 2;
- else if (sigdata->flags & IT_WAS_A_669)
- channel->portamento += v << 3;
- else
- channel->portamento += v << 4;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (channel->playing) {
+ if ((v & 0xF0) == 0xF0)
+ channel->playing->slide += (v & 15) << 4;
+ else if ((v & 0xF0) == 0xE0)
+ channel->playing->slide += (v & 15) << 2;
+ else if (i < 0 && sigdata->flags & IT_WAS_A_669)
+ channel->portamento += v << 3;
+ else if (i < 0)
+ channel->portamento += v << 4;
+ }
}
}
break;
@@ -2214,10 +2300,17 @@
depth <<= 2;
channel->lastHdepth = depth;
}
- if (channel->playing) {
- channel->playing->vibrato_speed = speed;
- channel->playing->vibrato_depth = depth;
- channel->playing->vibrato_n++;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing) {
+ playing->vibrato_speed = speed;
+ playing->vibrato_depth = depth;
+ playing->vibrato_n++;
+ }
}
}
}
@@ -2273,8 +2366,15 @@
else
channel->channelvolume = 64;
#endif
- if (channel->playing)
- channel->playing->channel_volume = channel->channelvolume;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing)
+ playing->channel_volume = channel->channelvolume;
+ }
break;
case IT_CHANNEL_VOLUME_SLIDE:
{
@@ -2295,8 +2395,15 @@
if (channel->channelvolume > 64) channel->channelvolume = 0;
} else
break;
- if (channel->playing)
- channel->playing->channel_volume = channel->channelvolume;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing)
+ playing->channel_volume = channel->channelvolume;
+ }
}
}
break;
@@ -2449,9 +2556,16 @@
depth = channel->lastRdepth;
channel->lastRdepth = depth;
}
- if (channel->playing) {
- channel->playing->tremolo_speed = speed;
- channel->playing->tremolo_depth = depth;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing) {
+ playing->tremolo_speed = speed;
+ playing->tremolo_depth = depth;
+ }
}
}
break;
@@ -2672,10 +2786,17 @@
depth <<= 1;
channel->lastHdepth = depth;
}
- if (channel->playing) {
- channel->playing->vibrato_speed = speed;
- channel->playing->vibrato_depth = depth;
- channel->playing->vibrato_n++;
+ for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+ if (i < 0) playing = channel->playing;
+ else {
+ playing = sigrenderer->playing[i];
+ if (!playing || playing->channel != channel) continue;
+ }
+ if (playing) {
+ playing->vibrato_speed = speed;
+ playing->vibrato_depth = depth;
+ playing->vibrato_n++;
+ }
}
}
break;
@@ -3562,7 +3683,7 @@
/* Returns 1 when fading should be initiated for a volume envelope. */
static int update_it_envelope(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe, int flags)
{
- if (!(playing->enabled_envelopes & flags))
+ if (!(playing->enabled_envelopes & flags) || !envelope->n_nodes)
return 0;
ASSERT(envelope->n_nodes > 0);
@@ -4315,7 +4436,7 @@
volume *= 1.0f / ((64 << 5) * 64.0f * 64.0f * 128.0f * 128.0f);
if (volume && playing->instrument) {
- if (playing->enabled_envelopes & IT_ENV_VOLUME) {
+ if (playing->enabled_envelopes & IT_ENV_VOLUME && playing->env_instrument->volume_envelope.n_nodes) {
volume *= envelope_get_y(&playing->env_instrument->volume_envelope, &playing->volume_envelope);
volume *= 1.0f / (64 << IT_ENVELOPE_SHIFT);
}