📄 mix.c
字号:
} } return; }}static void mix_single_right_signal(resample_t *sp, int32 *lp, int v, int count){ Voice *vp = voice + v; final_volume_t left=vp->left_mix; int cc; resample_t s; if (!(cc = vp->control_counter)) { cc = control_ratio; if (update_signal(v)) return; /* Envelope ran out */ left = vp->left_mix; } while (count) if (cc < count) { count -= cc; while (cc--) { s = *sp++; if (num_ochannels == 2) { MIXSKIP; MIXATION(left); } if (num_ochannels >= 4) { MIXSKIP; MIXHALF(left); MIXSKIP; MIXATION(left); } if (num_ochannels == 6) { MIXSKIP; MIXATION(left); } } cc = control_ratio; if (update_signal(v)) return; /* Envelope ran out */ left = vp->left_mix; } else { vp->control_counter = cc - count; while (count--) { s = *sp++; if (num_ochannels == 2) { MIXSKIP; MIXATION(left); } if (num_ochannels >= 4) { MIXSKIP; MIXHALF(left); MIXSKIP; MIXATION(left); } if (num_ochannels == 6) { MIXSKIP; MIXATION(left); } } return; }}static void mix_mono_signal(resample_t *sp, int32 *lp, int v, int count){ Voice *vp = voice + v; final_volume_t left=vp->left_mix; int cc; resample_t s; if (!(cc = vp->control_counter)) { cc = control_ratio; if (update_signal(v)) return; /* Envelope ran out */ left = vp->left_mix; } while (count) if (cc < count) { count -= cc; while (cc--) { s = *sp++; MIXATION(left); } cc = control_ratio; if (update_signal(v)) return; /* Envelope ran out */ left = vp->left_mix; } else { vp->control_counter = cc - count; while (count--) { s = *sp++; MIXATION(left); } return; }}static void mix_mystery(resample_t *sp, int32 *lp, int v, int count){ final_volume_t left_rear=voice[v].lr_mix, left=voice[v].left_mix, center=voice[v].ce_mix, right=voice[v].right_mix, right_rear=voice[v].rr_mix, lfe=voice[v].lfe_mix; resample_t s; while (count--) { s = *sp++; MIXATION(left); MIXATION(right); if (num_ochannels >= 4) { MIXATION(left_rear); MIXATION(right_rear); } if (num_ochannels == 6) { MIXATION(center); MIXATION(lfe); } }}static void mix_center(resample_t *sp, int32 *lp, int v, int count){ final_volume_t left=voice[v].left_mix; resample_t s; while (count--) { s = *sp++; if (num_ochannels == 2) { MIXATION(left); MIXATION(left); } else if (num_ochannels == 4) { MIXATION(left); MIXATION(left); MIXSKIP; MIXSKIP; } else if (num_ochannels == 6) { MIXSKIP; MIXSKIP; MIXSKIP; MIXSKIP; MIXATION(left); MIXATION(left); } }}static void mix_single_left(resample_t *sp, int32 *lp, int v, int count){ final_volume_t left=voice[v].left_mix; resample_t s; while (count--) { s = *sp++; if (num_ochannels == 2) { MIXATION(left); MIXSKIP; } if (num_ochannels >= 4) { MIXHALF(left); MIXSKIP; MIXATION(left); MIXSKIP; } if (num_ochannels == 6) { MIXSKIP; MIXATION(left); } }}static void mix_single_right(resample_t *sp, int32 *lp, int v, int count){ final_volume_t left=voice[v].left_mix; resample_t s; while (count--) { s = *sp++; if (num_ochannels == 2) { MIXSKIP; MIXATION(left); } if (num_ochannels >= 4) { MIXSKIP; MIXHALF(left); MIXSKIP; MIXATION(left); } if (num_ochannels == 6) { MIXSKIP; MIXATION(left); } }}static void mix_mono(resample_t *sp, int32 *lp, int v, int count){ final_volume_t left=voice[v].left_mix; resample_t s; while (count--) { s = *sp++; MIXATION(left); }}/* Ramp a note out in c samples */static void ramp_out(resample_t *sp, int32 *lp, int v, int32 c){ /* should be final_volume_t, but uint8 gives trouble. */ int32 left_rear, left, center, right, right_rear, lfe, li, ri; resample_t s = 0; /* silly warning about uninitialized s */ /* Fix by James Caldwell */ if ( c == 0 ) c = 1; left = voice[v].left_mix; li = -(left/c); if (!li) li = -1; /* printf("Ramping out: left=%d, c=%d, li=%d\n", left, c, li); */ if (!(play_mode->encoding & PE_MONO)) { if (voice[v].panned==PANNED_MYSTERY) { left_rear = voice[v].lr_mix; center=voice[v].ce_mix; right=voice[v].right_mix; right_rear = voice[v].rr_mix; lfe = voice[v].lfe_mix; ri=-(right/c); while (c--) { left_rear += li; if (left_rear<0) left_rear=0; left += li; if (left<0) left=0; center += li; if (center<0) center=0; right += ri; if (right<0) right=0; right_rear += ri; if (right_rear<0) right_rear=0; lfe += li; if (lfe<0) lfe=0; s=*sp++; MIXATION(left); MIXATION(right); if (num_ochannels >= 4) { MIXATION(left_rear); MIXATION(right_rear); } if (num_ochannels == 6) { MIXATION(center); MIXATION(lfe); } } } else if (voice[v].panned==PANNED_CENTER) { while (c--) { left += li; if (left<0) return; s=*sp++; if (num_ochannels == 2) { MIXATION(left); MIXATION(left); } else if (num_ochannels == 4) { MIXATION(left); MIXATION(left); MIXSKIP; MIXSKIP; } else if (num_ochannels == 6) { MIXSKIP; MIXSKIP; MIXSKIP; MIXSKIP; MIXATION(left); MIXATION(left); } } } else if (voice[v].panned==PANNED_LEFT) { while (c--) { left += li; if (left<0) return; s=*sp++; MIXATION(left); MIXSKIP; if (num_ochannels >= 4) { MIXATION(left); MIXSKIP; } if (num_ochannels == 6) { MIXATION(left); MIXATION(left); } } } else if (voice[v].panned==PANNED_RIGHT) { while (c--) { left += li; if (left<0) return; s=*sp++; MIXSKIP; MIXATION(left); if (num_ochannels >= 4) { MIXSKIP; MIXATION(left); } if (num_ochannels == 6) { MIXATION(left); MIXATION(left); } } } } else { /* Mono output. */ while (c--) { left += li; if (left<0) return; s=*sp++; MIXATION(left); } }}/**************** interface function ******************/void mix_voice(int32 *buf, int v, int32 c){ Voice *vp=voice+v; int32 count=c; resample_t *sp; if (c<0) return; if (vp->status==VOICE_DIE) { if (count>=MAX_DIE_TIME) count=MAX_DIE_TIME; sp=resample_voice(v, &count); ramp_out(sp, buf, v, count); vp->status=VOICE_FREE; } else { sp=resample_voice(v, &count); if (count<0) return; if (play_mode->encoding & PE_MONO) { /* Mono output. */ if (vp->envelope_increment || vp->tremolo_phase_increment) mix_mono_signal(sp, buf, v, count); else mix_mono(sp, buf, v, count); } else { if (vp->panned == PANNED_MYSTERY) { if (vp->envelope_increment || vp->tremolo_phase_increment) mix_mystery_signal(sp, buf, v, count); else mix_mystery(sp, buf, v, count); } else if (vp->panned == PANNED_CENTER) { if (vp->envelope_increment || vp->tremolo_phase_increment) mix_center_signal(sp, buf, v, count); else mix_center(sp, buf, v, count); } else { /* It's either full left or full right. In either case, every other sample is 0. Just get the offset right: */ if (vp->envelope_increment || vp->tremolo_phase_increment) { if (vp->panned == PANNED_RIGHT) mix_single_right_signal(sp, buf, v, count); else mix_single_left_signal(sp, buf, v, count); } else { if (vp->panned == PANNED_RIGHT) mix_single_right(sp, buf, v, count); else mix_single_left(sp, buf, v, count); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -