Пример #1
0
        private bool Compile(out PcodeRec FuncCode, out DataTypes ReturnType)
        {
            int LineNumber;

            Compiler.ASTExpression AST;
            CompileErrors          Error = Compiler.CompileSpecialFunction(
                document.CodeCenter,
                new FunctionParamRec[0] /*no arguments*/,
                out LineNumber,
                out ReturnType,
                textBox.SelectedTextStorage.GetText(Environment.NewLine),
                false /*suppressCILEmission*/,
                out FuncCode,
                out AST);

            if (Error != CompileErrors.eCompileNoError)
            {
                textBox.Focus();
                textBox.SetSelectionLine(textBox.SelectionStartLine + LineNumber - 1);
                textBox.ScrollToSelection();
                BuildErrorInfo error = new LiteralBuildErrorInfo(
                    Compiler.GetCompileErrorString(Error),
                    LineNumber);
                MessageBox.Show(error.CompositeErrorMessage, "Compile Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            return(true);
        }
Пример #2
0
        public WaveTableStorageRec WaveTableData; // null = needs to be built


        // Exposed separately to support Disassemble menu item
        public bool BuildCode(BuildFailedCallback failedCallback, out PcodeRec FuncCode)
        {
            int       ErrorLineNumberCompilation;
            DataTypes ReturnType;

            Compiler.ASTExpression AST;
            CompileErrors          CompileError = Compiler.CompileSpecialFunction(
                ((Document)Parent).CodeCenter,
                new FunctionParamRec[]
            {
                new FunctionParamRec("frames", DataTypes.eInteger),
                new FunctionParamRec("tables", DataTypes.eInteger),
                new FunctionParamRec("data", DataTypes.eArrayOfFloat),
            },
                out ErrorLineNumberCompilation,
                out ReturnType,
                AlgoWaveTableFormula,
                false /*suppressCILEmission*/,
                out FuncCode,
                out AST);

            if (CompileError != CompileErrors.eCompileNoError)
            {
                failedCallback(this, new LiteralBuildErrorInfo(Compiler.GetCompileErrorString(CompileError), ErrorLineNumberCompilation));
                return(false);
            }

            return(true);
        }
        /* this routine looks for indivisible dup/pop operations (with no interior */
        /* branches) and eliminates them.  *Flag is set if some change was made, and the */
        /* new length of Prog[] is returned. */
        private static void EliminateDupPop(List <OpcodeRec> Prog, List <int> LineNumberArray, out bool Flag)
        {
            Flag = false;
            int Scan = 0;

            while (Scan < Prog.Count)
            {
                /* look to see if this part can be dropped.  if it can, we don't increment */
                /* Scan so that we can look at the part that will be moved into where this */
                /* is as well.  otherwise, we do increment */
                if ((Prog[Scan].Opcode == Pcodes.epDuplicate) &&
                    (Prog[Scan + 1].Opcode == Pcodes.epStackPop) &&
                    NoBranchToInterior(Prog, Scan, 2))
                {
                    /* found one! */
                    DropCodeSegment(Prog, LineNumberArray, Scan, 2);
                    Flag = true;
                }
                else
                {
                    /* increment only if not found */
                    Scan += PcodeRec.GetInstructionLength(Prog[Scan].Opcode);
                }
            }
            Debug.Assert(Scan == Prog.Count); // internal instruction alignment error
        }
Пример #4
0
        public static void SetSingleFilterGain(
            OneFilterRec Spec,
            double Gain,
            PcodeRec Formula)
        {
#if DEBUG
            if ((Spec.FilterType != FilterTypes.eFilterParametricEQ) &&
                (Spec.FilterType != FilterTypes.eFilterParametricEQ2) &&
                (Spec.FilterType != FilterTypes.eFilterLowShelfEQ) &&
                (Spec.FilterType != FilterTypes.eFilterHighShelfEQ) &&
                (Spec.FilterType != FilterTypes.eFilterResonantLowpass) &&
                (Spec.FilterType != FilterTypes.eFilterResonantLowpass2))
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
            if (Spec.GainFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.GainFormula = Formula;
            Spec.Gain        = Gain;
        }
        /* this routine eliminates the specified segment of code from the program */
        /* and updates all branches pointing to areas beyond it.  The new length */
        /* is returned.  it also disposes of any additional storage used by the */
        /* instructions being deleted */
        private static void DropCodeSegment(List <OpcodeRec> Prog, List <int> LineNumberArray, int Start, int Extent)
        {
            /* sanity check */
            Debug.Assert(NoBranchToInterior(Prog, Start, Extent)); // branches to interior not permitted
            /* patch up branches */
            int Scan;

            for (Scan = 0; Scan < Prog.Count; Scan += PcodeRec.GetInstructionLength(Prog[Scan].Opcode))
            {
                /* looking for branch instructions */
                if ((Prog[Scan].Opcode == Pcodes.epBranchUnconditional) ||
                    (Prog[Scan].Opcode == Pcodes.epBranchIfZero) ||
                    (Prog[Scan].Opcode == Pcodes.epBranchIfNotZero))
                {
                    /* found a branch instruction.  does it need to be patched? */
                    if (Prog[Scan + 1].ImmediateInteger > Start)
                    {
                        /* branch is beyond segment being dropped, so decrement it's address */
                        /* by the length of the segment */
                        OpcodeRec opcode = Prog[Scan + 1];
                        opcode.ImmediateInteger -= Extent;
                        Prog[Scan + 1]           = opcode;
                    }
                }
            }
            Debug.Assert(Scan == Prog.Count); // internal instruction alignment error
            /* delete the code segment */
            Prog.RemoveRange(Start, Extent);
            LineNumberArray.RemoveRange(Start, Extent);
        }
Пример #6
0
        public FuncCodeRec(
            string FuncName,
            SymbolListRec Parameters,
            PcodeRec PcodeThing,
            DataTypes ReturnType,
            string Filename)
        {
            this.FunctionName = FuncName;

            this.NumParameters     = SymbolListRec.GetLength(Parameters);
            this.ParameterTypeList = new DataTypes[this.NumParameters];

            this.Filename = Filename;

            SymbolListRec FormalParameterScanner = Parameters;
            int           ParamIndex             = 0;

            while (FormalParameterScanner != null)
            {
                this.ParameterTypeList[ParamIndex] = FormalParameterScanner.First.VariableDataType;
                FormalParameterScanner             = FormalParameterScanner.Rest;
                ParamIndex++;
            }

            this.Code = PcodeThing;

            this.ReturnType = ReturnType;
        }
Пример #7
0
        public static void SetSingleFilterBandwidthOrSlope(
            OneFilterRec Spec,
            double BandwidthOrSlope,
            PcodeRec Formula)
        {
#if DEBUG
            if ((Spec.FilterType != FilterTypes.eFilterSecondOrderResonant) &&
                (Spec.FilterType != FilterTypes.eFilterSecondOrderZero) &&
                (Spec.FilterType != FilterTypes.eFilterButterworthBandpass) &&
                (Spec.FilterType != FilterTypes.eFilterButterworthBandreject) &&
                (Spec.FilterType != FilterTypes.eFilterParametricEQ) &&
                (Spec.FilterType != FilterTypes.eFilterParametricEQ2) &&
                (Spec.FilterType != FilterTypes.eFilterLowShelfEQ) &&
                (Spec.FilterType != FilterTypes.eFilterHighShelfEQ) &&
                (Spec.FilterType != FilterTypes.eFilterResonantLowpass))
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
            if (Spec.BandwidthOrSlopeFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.BandwidthOrSlopeFormula = Formula;
            Spec.BandwidthOrSlope        = BandwidthOrSlope;
        }
Пример #8
0
        /* do a scalar param evaluation */
        public static SynthErrorCodes StaticEval(
            double X,
            PcodeRec SpecifiedFormula,
            ref AccentRec CurrentParameters,
            SynthParamRec SynthParams,
            out double ResultOut)
        {
            ResultOut = 0;

            int initialCapacity = 1 /*retval*/ + 8 + 1 /*t*/ + 1 /*x*/ + 1 /*bpm*/;

            SynthParams.FormulaEvalContext.EmptyParamStackEnsureCapacity(initialCapacity);

            StackElement[] Stack;
            int            StackNumElements;

            SynthParams.FormulaEvalContext.GetRawStack(out Stack, out StackNumElements);

            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent0;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent1;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent2;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent3;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent4;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent5;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent6;
            Stack[StackNumElements++].Data.Double = CurrentParameters.Accent7;

            Stack[StackNumElements++].Data.Double = SynthParams.dElapsedTimeInSeconds;  /* t */

            Stack[StackNumElements++].Data.Double = X;                                  /* x */

            Stack[StackNumElements++].Data.Double = SynthParams.dCurrentBeatsPerMinute; /* bpm */

            StackNumElements++;                                                         /* return address placeholder */

            SynthParams.FormulaEvalContext.UpdateRawStack(Stack, StackNumElements);

            EvalErrInfoRec ErrorInfo;
            EvalErrors     Error = PcodeSystem.EvaluatePcode(
                SynthParams.FormulaEvalContext,
                SpecifiedFormula,
                SynthParams.CodeCenter,
                out ErrorInfo,
                PcodeExternsNull.Default,
                ref SynthParams.pcodeThreadContext);

            if (Error != EvalErrors.eEvalNoError)
            {
                SynthParams.ErrorInfo.ErrorEx           = SynthErrorSubCodes.eSynthErrorExUserParamFunctionEvalError;
                SynthParams.ErrorInfo.UserEvalErrorCode = Error;
                SynthParams.ErrorInfo.UserEvalErrorInfo = ErrorInfo;
                return(SynthErrorCodes.eSynthErrorEx);
            }
            Debug.Assert(SynthParams.FormulaEvalContext.GetStackNumElements() == initialCapacity); // args - retaddr + return value

            ResultOut = SynthParams.FormulaEvalContext.GetStackDouble(initialCapacity - 1);

            return(SynthErrorCodes.eSynthDone);
        }
Пример #9
0
 /* initialize the scalar parameter evaluator */
 public static void InitScalarParamEval(
     double SpecifiedValue,
     ref AccentRec SpecifiedAccentModifiers,
     PcodeRec SpecifiedFormula,
     out ScalarParamEvalRec EvalOut)
 {
     EvalOut = new ScalarParamEvalRec();
     EvalOut.SpecifiedValue           = SpecifiedValue;
     EvalOut.SpecifiedAccentModifiers = SpecifiedAccentModifiers;
     EvalOut.SpecifiedFormula         = SpecifiedFormula;
 }
Пример #10
0
 /* specify a formula for the envelope generator. */
 public static void EnvelopeSetFormula(
     EnvelopeRec Envelope,
     PcodeRec Formula)
 {
     if (Envelope.Formula != null)
     {
         // EnvelopeSetFormula: formula has already been specified
         Debug.Assert(false);
         throw new ArgumentException();
     }
     Envelope.Formula = Formula;
 }
Пример #11
0
        public SampleStorageActualRec SampleData; // null = needs to be built


        // Exposed separately to support Disassemble menu item
        public bool BuildCode(BuildFailedCallback failedCallback, out PcodeRec FuncCode)
        {
            int       ErrorLineNumberCompilation;
            DataTypes ReturnType;

            Compiler.ASTExpression AST;
            CompileErrors          CompileError = Compiler.CompileSpecialFunction(
                ((Document)Parent).CodeCenter,
                NumChannels == NumChannelsType.eSampleStereo
                ? new FunctionParamRec[]
            {
                new FunctionParamRec("loopstart1", DataTypes.eInteger),
                new FunctionParamRec("loopstart2", DataTypes.eInteger),
                new FunctionParamRec("loopstart3", DataTypes.eInteger),
                new FunctionParamRec("loopend1", DataTypes.eInteger),
                new FunctionParamRec("loopend2", DataTypes.eInteger),
                new FunctionParamRec("loopend3", DataTypes.eInteger),
                new FunctionParamRec("origin", DataTypes.eInteger),
                new FunctionParamRec("samplingrate", DataTypes.eInteger),
                new FunctionParamRec("naturalfrequency", DataTypes.eDouble),
                new FunctionParamRec("leftdata", DataTypes.eArrayOfFloat),
                new FunctionParamRec("rightdata", DataTypes.eArrayOfFloat),
            }
                : new FunctionParamRec[]
            {
                new FunctionParamRec("loopstart1", DataTypes.eInteger),
                new FunctionParamRec("loopstart2", DataTypes.eInteger),
                new FunctionParamRec("loopstart3", DataTypes.eInteger),
                new FunctionParamRec("loopend1", DataTypes.eInteger),
                new FunctionParamRec("loopend2", DataTypes.eInteger),
                new FunctionParamRec("loopend3", DataTypes.eInteger),
                new FunctionParamRec("origin", DataTypes.eInteger),
                new FunctionParamRec("samplingrate", DataTypes.eInteger),
                new FunctionParamRec("naturalfrequency", DataTypes.eDouble),
                new FunctionParamRec("data", DataTypes.eArrayOfFloat),
            },
                out ErrorLineNumberCompilation,
                out ReturnType,
                AlgoSampFormula,
                false /*suppressCILEmission*/,
                out FuncCode,
                out AST);

            if (CompileError != CompileErrors.eCompileNoError)
            {
                failedCallback(this, new LiteralBuildErrorInfo(Compiler.GetCompileErrorString(CompileError), ErrorLineNumberCompilation));
                return(false);
            }

            return(true);
        }
Пример #12
0
        public static void EnvelopeSetPhaseFinalValueFormula(
            EnvelopeRec Envelope,
            int Index,
            PcodeRec FinalValueFunction)
        {
#if DEBUG
            if ((Index < 0) || (Index > Envelope.NumPhases))
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Envelope.PhaseArray[Index].EndPointFunction = FinalValueFunction;
        }
Пример #13
0
        public static void PutVocoderSpecWaveTableIndex(
            VocoderSpecRec VocSpec,
            double WaveTableIndex,
            PcodeRec Formula)
        {
#if DEBUG
            if (VocSpec.WaveTableIndexFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            VocSpec.WaveTableIndexFormula = Formula;
            VocSpec.WaveTableIndex        = WaveTableIndex;
        }
Пример #14
0
        public static void PutVocoderSpecOutputGain(
            VocoderSpecRec VocSpec,
            double OutputGain,
            PcodeRec Formula)
        {
#if DEBUG
            if (VocSpec.OutputGainFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            VocSpec.OutputGainFormula = Formula;
            VocSpec.OutputGain        = OutputGain;
        }
Пример #15
0
        /* set threshhold power */
        public static void PutCompressorThreshPower(
            CompressorSpecRec Spec,
            double Power,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.ThreshPowerFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.ThreshPowerFormula = Formula;
            Spec.ThreshPower        = Power;
        }
Пример #16
0
        public static void PutNLProcWaveTableIndex(
            NonlinProcSpecRec NLProc,
            double WaveTableIndex,
            PcodeRec Formula)
        {
#if DEBUG
            if (NLProc.WaveTableIndexFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            NLProc.WaveTableIndexFormula = Formula;
            NLProc.WaveTableIndex        = WaveTableIndex;
        }
Пример #17
0
        /* set decreasing gain attack rate (seconds per doubling) */
        public static void PutCompressorAttackRate(
            CompressorSpecRec Spec,
            double Rate,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.AttackRateFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.AttackRateFormula = Formula;
            Spec.AttackRate        = Rate;
        }
Пример #18
0
        public static void SetDelayTapFilterCutoff(
            DelayTapRec Tap,
            double Cutoff,
            PcodeRec Formula)
        {
#if DEBUG
            if (Tap.FilterCutoffFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Tap.FilterCutoffFormula = Formula;
            Tap.FilterCutoff        = Cutoff;
        }
Пример #19
0
        public static void SetDelayTapScale(
            DelayTapRec Tap,
            double Scale,
            PcodeRec Formula)
        {
#if DEBUG
            if (Tap.ScaleFactorFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Tap.ScaleFactorFormula = Formula;
            Tap.ScaleFactor        = Scale;
        }
Пример #20
0
        public static void SetDelayTapTargetTime(
            DelayTapRec Tap,
            double Time,
            PcodeRec Formula)
        {
#if DEBUG
            if (Tap.TargetTimeFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Tap.TargetTimeFormula = Formula;
            Tap.TargetTime        = Time;
        }
Пример #21
0
        /* set limiting excess (above 1) for soft clipping */
        public static void PutCompressorLimitingExcess(
            CompressorSpecRec Spec,
            double Limit,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.LimitingExcessFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.LimitingExcessFormula = Formula;
            Spec.LimitingExcess        = Limit;
        }
Пример #22
0
        /* processed gain factor */
        public static void ConvolverSpecSetProcessedGain(
            ConvolverSpecRec Spec,
            double Gain,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.ProcessedGainFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.ProcessedGainFormula = Formula;
            Spec.ProcessedGain        = Gain;
        }
Пример #23
0
        public static void PutNLProcInputScaling(
            NonlinProcSpecRec NLProc,
            double InputScaling,
            PcodeRec Formula)
        {
#if DEBUG
            if (NLProc.InputScalingFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            NLProc.InputScalingFormula = Formula;
            NLProc.InputScaling        = InputScaling;
        }
Пример #24
0
        /* set power estimator filter cutoff frequency */
        public static void PutCompressorFilterFreq(
            CompressorSpecRec Spec,
            double Cutoff,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.FilterCutoffFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.FilterCutoffFormula = Formula;
            Spec.FilterCutoff        = Cutoff;
        }
Пример #25
0
        /* set output gain factor */
        public static void PutCompressorOutputGain(
            CompressorSpecRec Spec,
            double Gain,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.OutputGainFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.OutputGainFormula = Formula;
            Spec.OutputGain        = Gain;
        }
Пример #26
0
        public static void SetSingleFilterOutputMultiplier(
            OneFilterRec Spec,
            double Output,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.OutputMultiplierFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.OutputMultiplierFormula = Formula;
            Spec.OutputMultiplier        = Output;
        }
Пример #27
0
        public static void SetSingleFilterCutoff(
            OneFilterRec Spec,
            double Cutoff,
            PcodeRec Formula)
        {
#if DEBUG
            if (Spec.CutoffFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.CutoffFormula = Formula;
            Spec.Cutoff        = Cutoff;
        }
Пример #28
0
        /* set various attributes */
        public static void PutUserEffectSpecParam(
            UserEffectSpecRec Spec,
            int Index,
            double Param,
            PcodeRec ParamFormula)
        {
#if DEBUG
            if (Spec.Items[Index].ParamFormula != null)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif
            Spec.Items[Index].ParamFormula = ParamFormula;
            Spec.Items[Index].Param        = Param;
        }
Пример #29
0
        // The methods AppendExternRef() and ClearExternRef() can be called from multiple threads during
        // synthesis, so must be single-access.

        public int AppendExternRef(PcodeRec p)
        {
            lock (this)
            {
                while (externRefsLast < externRefs.Length)
                {
                    if (externRefs[externRefsLast] == null)
                    {
                        externRefs[externRefsLast] = p;
                        return(externRefsLast++);
                    }
                }
                Array.Resize(ref externRefs, externRefs.Length * 2 + 1);
                externRefs[externRefsLast] = p;
                return(externRefsLast++);
            }
        }
        /* this routine scans the entire code block to see if any branches are made */
        /* to any but the first instruction specified in the run of instructions. */
        /* Start points to the first instruction, Extent specifies the number of WORDS */
        /* (not instructions).  Branches MAY point to Prog[Start], however. */
        private static bool NoBranchToInterior(List <OpcodeRec> Prog, int Start, int Extent)
        {
            int i;

            for (i = 0; i < Prog.Count; i += PcodeRec.GetInstructionLength(Prog[i].Opcode))
            {
                if ((Prog[i].Opcode == Pcodes.epBranchUnconditional) ||
                    (Prog[i].Opcode == Pcodes.epBranchIfZero) ||
                    (Prog[i].Opcode == Pcodes.epBranchIfNotZero))
                {
                    /* branch operation detected, test index */
                    if ((Prog[i + 1].ImmediateInteger > Start) &&
                        (Prog[i + 1].ImmediateInteger < Start + Extent))
                    {
                        /* branch to interior found, so return false. */
                        return(false);
                    }
                }
            }
            Debug.Assert(i == Prog.Count); // internal instruction alignment error
            return(true);
        }