Example #1
0
        void StartEffect(EffectEnvelope env, byte[] data, int offset)
        {
            env.state = 1;
            env.currentLevel = 0;
            env.modWheelLast = 31;
            env.duration = (short)(data[offset + 0] * 63);

            env.stateTargetLevels[0] = data[offset + 1];
            env.stateTargetLevels[1] = data[offset + 3];
            env.stateTargetLevels[2] = data[offset + 5];
            env.stateTargetLevels[3] = data[offset + 6];

            env.stateModWheelLevels[0] = data[offset + 2];
            env.stateModWheelLevels[1] = data[offset + 4];
            env.stateModWheelLevels[2] = 0;
            env.stateModWheelLevels[3] = data[offset + 7];

            InitNextEnvelopeState(env);
        }
Example #2
0
        void InitNextEnvelopeState(EffectEnvelope env)
        {
            byte lastState = (byte)(env.state - 1);

            short stepCount = _effectEnvStepTable[GetEffectModifier((ushort)(((env.stateTargetLevels[lastState] & 0x7F) << 5) + env.modWheelSensitivity))];
            if ((env.stateTargetLevels[lastState] & 0x80) != 0)
                stepCount = GetRandScale(stepCount);
            if (stepCount == 0)
                stepCount = 1;

            env.stateNumSteps = env.stateStepCounter = stepCount;

            short totalChange = 0;
            if (lastState != 2)
            {
                totalChange = GetEffectModLevel(env.maxLevel, (sbyte)((env.stateModWheelLevels[lastState] & 0x7F) - 31));
                if ((env.stateModWheelLevels[lastState] & 0x80) != 0)
                    totalChange = GetRandScale(totalChange);

                if (totalChange + env.startLevel > env.maxLevel)
                    totalChange = (short)(env.maxLevel - env.startLevel);
                else if (totalChange + env.startLevel < 0)
                    totalChange = (short)-env.startLevel;

                totalChange -= env.currentLevel;
            }

            env.changePerStep = (short)(totalChange / stepCount);
            if (totalChange < 0)
            {
                totalChange = (short)-totalChange;
                env.dir = -1;
            }
            else
            {
                env.dir = 1;
            }
            env.changePerStepRem = (short)(totalChange % stepCount);
            env.changeCountRem = 0;
        }
Example #3
0
        void SetupEffects(MidiChannelPcSpk chan, EffectEnvelope env, EffectDefinition def, byte flags, byte[] data, int offset)
        {
            def.phase = 0;
            def.useModWheel = (byte)(flags & 0x40);
            env.loop = (byte)(flags & 0x20);
            def.type = (short)(flags & 0x1F);

            env.modWheelSensitivity = 31;
            if (def.useModWheel != 0)
                env.modWheelState = (byte)(MidiChannelPcSpk.ModWheel >> 2);
            else
                env.modWheelState = 31;

            switch (def.type)
            {
                case 0:
                    env.maxLevel = 767;
                    env.startLevel = 383;
                    break;

                case 1:
                    env.maxLevel = 31;
                    env.startLevel = 15;
                    break;

                case 2:
                    env.maxLevel = 63;
                    env.startLevel = chan._out.unkB;
                    break;

                case 3:
                    env.maxLevel = 63;
                    env.startLevel = chan._out.unkC;
                    break;

                case 4:
                    env.maxLevel = 3;
                    env.startLevel = chan._instrument[4];
                    break;

                case 5:
                    env.maxLevel = 62;
                    env.startLevel = 31;
                    env.modWheelState = 0;
                    break;

                case 6:
                    env.maxLevel = 31;
                    env.startLevel = 0;
                    env.modWheelSensitivity = 0;
                    break;
            }

            StartEffect(env, data, offset);
        }