示例#1
0
        public void dx7_voice_update_mod_depths(hexter_instance instance)
        {
            byte  kp = instance.key_pressure[this.key];
            byte  cp = instance.channel_pressure;
            float pressure;
            float pdepth, adepth, mdepth, edepth;

            /* add the channel and key pressures together in a way that 'feels' good */
            if (kp > cp)
            {
                pressure  = (float)kp / 127.0f;
                pressure += (1.0f - pressure) * ((float)cp / 127.0f);
            }
            else
            {
                pressure  = (float)cp / 127.0f;
                pressure += (1.0f - pressure) * ((float)kp / 127.0f);
            }

            /* calculate modulation depths */
            pdepth = (float)this.lfo_pmd / 99.0f;
            this.pitch_mod_depth_pmd = (double)Data.dx7_voice_pms_to_semitones[this.lfo_pms] *
                                       (double)pdepth;
            // -FIX- this could be optimized:
            // -FIX- this just adds everything together -- maybe it should limit the result, or
            // combine the various mods like update_pressure() does
            pdepth = (((instance.mod_wheel_assign & 0x01) != 0) ?
                      // -FIX- this assumes that mod_wheel_sensitivity, etc. scale linearly => verify
                      (float)instance.mod_wheel_sensitivity / 15.0f * instance.mod_wheel :
                      0.0f) +
                     (((instance.foot_assign & 0x01) != 0) ?
                      (float)instance.foot_sensitivity / 15.0f * instance.foot :
                      0.0f) +
                     (((instance.pressure_assign & 0x01) != 0) ?
                      (float)instance.pressure_sensitivity / 15.0f * pressure :
                      0.0f) +
                     (((instance.breath_assign & 0x01) != 0) ?
                      (float)instance.breath_sensitivity / 15.0f * instance.breath :
                      0.0f);
            this.pitch_mod_depth_mods = (double)Data.dx7_voice_pms_to_semitones[this.lfo_pms] *
                                        (double)pdepth;

            // -FIX- these are total guesses at how to combine/limit the amp mods:
            adepth = Data.dx7_voice_amd_to_ol_adjustment[this.lfo_amd];
            // -FIX- this could be optimized:
            mdepth = (((instance.mod_wheel_assign & 0x02) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.mod_wheel_sensitivity] *
                      instance.mod_wheel :
                      0.0f) +
                     (((instance.foot_assign & 0x02) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.foot_sensitivity] *
                      instance.foot :
                      0.0f) +
                     (((instance.pressure_assign & 0x02) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.pressure_sensitivity] *
                      pressure :
                      0.0f) +
                     (((instance.breath_assign & 0x02) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.breath_sensitivity] *
                      instance.breath :
                      0.0f);
            edepth = // -FIX- this could be optimized:
                     (((instance.mod_wheel_assign & 0x04) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.mod_wheel_sensitivity] *
                      (1.0f - instance.mod_wheel) :
                      0.0f) +
                     (((instance.foot_assign & 0x04) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.foot_sensitivity] *
                      (1.0f - instance.foot) :
                      0.0f) +
                     (((instance.pressure_assign & 0x04) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.pressure_sensitivity] *
                      (1.0f - pressure) :
                      0.0f) +
                     (((instance.breath_assign & 0x04) != 0) ?
                      Data.dx7_voice_mss_to_ol_adjustment[instance.breath_sensitivity] *
                      (1.0f - instance.breath) :
                      0.0f);

            /* full-scale amp mod for adepth and edepth should be 52.75 and
             * their sum _must_ be limited to less than 128, or bad things will happen! */
            if (adepth > 127.5f)
            {
                adepth = 127.5f;
            }
            if (adepth + mdepth > 127.5f)
            {
                mdepth = 127.5f - adepth;
            }
            if (adepth + mdepth + edepth > 127.5f)
            {
                edepth = 127.5f - (adepth + mdepth);
            }

            this.amp_mod_lfo_amd_target = Inline.FLOAT_TO_FP(adepth);
            if (this.amp_mod_lfo_amd_value <= Inline.INT_TO_FP(-64))
            {
                this.amp_mod_lfo_amd_value     = this.amp_mod_lfo_amd_target;
                this.amp_mod_lfo_amd_increment = 0;
                this.amp_mod_lfo_amd_duration  = 0;
            }
            else
            {
                this.amp_mod_lfo_amd_duration  = instance.ramp_duration;
                this.amp_mod_lfo_amd_increment = (this.amp_mod_lfo_amd_target - this.amp_mod_lfo_amd_value) /
                                                 (Int32)this.amp_mod_lfo_amd_duration;
            }
            this.amp_mod_lfo_mods_target = Inline.FLOAT_TO_FP(mdepth);
            if (this.amp_mod_lfo_mods_value <= Inline.INT_TO_FP(-64))
            {
                this.amp_mod_lfo_mods_value     = this.amp_mod_lfo_mods_target;
                this.amp_mod_lfo_mods_increment = 0;
                this.amp_mod_lfo_mods_duration  = 0;
            }
            else
            {
                this.amp_mod_lfo_mods_duration  = instance.ramp_duration;
                this.amp_mod_lfo_mods_increment = (this.amp_mod_lfo_mods_target - this.amp_mod_lfo_mods_value) /
                                                  (Int32)this.amp_mod_lfo_mods_duration;
            }
            this.amp_mod_env_target = Inline.FLOAT_TO_FP(edepth);
            if (this.amp_mod_env_value <= Inline.INT_TO_FP(-64))
            {
                this.amp_mod_env_value     = this.amp_mod_env_target;
                this.amp_mod_env_increment = 0;
                this.amp_mod_env_duration  = 0;
            }
            else
            {
                this.amp_mod_env_duration  = instance.ramp_duration;
                this.amp_mod_env_increment = (this.amp_mod_env_target - this.amp_mod_env_value) /
                                             (Int32)this.amp_mod_env_duration;
            }
        }