/* 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); }
private static EvalErrors TypeCheckSignature(object[] args, DataTypes[] argsTypes) { int argsLength = args != null ? args.Length : 0; if (argsLength != argsTypes.Length) { return(EvalErrors.eEvalFunctionSignatureMismatch); } for (int i = 0; i < argsLength; i++) { EvalErrors error = TypeCheckValue(args[i], argsTypes[i]); if (error != EvalErrors.eEvalNoError) { return(error); } } return(EvalErrors.eEvalNoError); }
public PcodeEvaluationErrorInfo(EvalErrors EvaluationError, EvalErrInfoRec ErrorInfo, PcodeRec AnonymousFunction, CodeCenterRec CodeCenter) { int ErrorLineNumberEvaluation; string Name; FuncCodeRec ErrorFunction = CodeCenter.GetFunctionFromOpcode(ErrorInfo.OffendingPcode); if (ErrorFunction != null) { Name = ErrorFunction.GetFunctionFilename(); ErrorLineNumberEvaluation = ErrorFunction.GetFunctionPcode().GetLineNumberForInstruction(ErrorInfo.OffendingInstruction); } else { Name = "<anonymous>"; ErrorLineNumberEvaluation = AnonymousFunction.GetLineNumberForInstruction(ErrorInfo.OffendingInstruction); } this.module = Name; this.errorText = PcodeSystem.GetPcodeErrorMessage(EvaluationError); this.lineNumber = ErrorLineNumberEvaluation; }
private void Eval() { if (!mainWindow.MakeUpToDate()) { return; } int ErrorLineNumberCompilation; DataTypes ReturnType; PcodeRec FuncCode; Compiler.ASTExpression AST; CompileErrors CompileError = Compiler.CompileSpecialFunction( mainWindow.Document.CodeCenter, new FunctionParamRec[] { new FunctionParamRec("frames", DataTypes.eInteger), new FunctionParamRec("tables", DataTypes.eInteger), new FunctionParamRec("data", DataTypes.eArrayOfFloat), }, out ErrorLineNumberCompilation, out ReturnType, textBoxFormula.Text, false/*suppressCILEmission*/, out FuncCode, out AST); if (CompileError != CompileErrors.eCompileNoError) { textBoxFormula.Focus(); textBoxFormula.SetSelectionLine(ErrorLineNumberCompilation - 1); textBoxFormula.ScrollToSelection(); LiteralBuildErrorInfo errorInfo = new LiteralBuildErrorInfo(Compiler.GetCompileErrorString(CompileError), ErrorLineNumberCompilation); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } using (ParamStackRec ParamList = new ParamStackRec()) { int numFrames = waveTableObject.WaveTableData.NumFrames; int numTables = waveTableObject.WaveTableData.NumTables; float[] vector = new float[numFrames * numTables]; ArrayHandleFloat dataHandle = new ArrayHandleFloat(vector); int initialCapacity = 1/*frames*/ + 1/*tables*/ + 1/*data*/ + 1/*retaddr*/; ParamList.EmptyParamStackEnsureCapacity(initialCapacity); ParamList.AddIntegerToStack(numFrames); ParamList.AddIntegerToStack(numTables); ParamList.AddArrayToStack(dataHandle); ParamList.AddIntegerToStack(0); /* return address placeholder */ for (int i = 0; i < numTables; i++) { WaveTableStorageRec.Table table = waveTableObject.WaveTableData.ListOfTables[i]; for (int j = 0; j < numFrames; j++) { vector[i * numFrames + j] = table[j]; } } CodeCenterRec CodeCenter = mainWindow.Document.CodeCenter; EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, CodeCenter, out ErrorInfo, new PcodeExterns(mainWindow)); if (EvaluationError != EvalErrors.eEvalNoError) { PcodeEvaluationErrorInfo errorInfo = new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, CodeCenter); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } Debug.Assert(ParamList.GetStackNumElements() == initialCapacity); // args - retaddr + return value #if DEBUG ParamList.Elements[2].AssertFloatArray(); #endif dataHandle = ParamList.Elements[2].reference.arrayHandleFloat; WaveTableStorageRec NewTable = new WaveTableStorageRec(numTables, numFrames, waveTableObject.WaveTableData.NumBits); float[] NewData = dataHandle.floats; if (NewData.Length != numTables * numFrames) { PcodeEvaluationErrorInfo errorInfo = new PcodeEvaluationErrorInfo( "<anonymous>", PcodeSystem.GetPcodeErrorMessage(EvalErrors.eEvalArrayWrongDimensions), 1); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } SampConv.QuantizeAndClampVector(NewData, NewTable.NumBits); for (int i = 0; i < numTables; i++) { WaveTableStorageRec.Table table = NewTable.ListOfTables[i]; for (int j = 0; j < numFrames; j++) { table[j] = NewData[i * numFrames + j]; } } undo.Push(waveTableObject.WaveTableData); redo.Clear(); waveTableObject.WaveTableData = NewTable; } }
public EvalErrorException(EvalErrors error) { this.error = error; }
/* shared initialization */ private static SynthErrorCodes UserEffectSharedInit( UserEffectProcRec Proc, UserEffectSpecRec Template, SynthParamRec SynthParams) { Proc.disableOversampling = GetUserEffectSpecNoOversampling(Template); double sr = SynthParams.dSamplingRate; if (!((SynthParams.iOversampling == 1) || !Proc.disableOversampling)) { sr /= SynthParams.iOversampling; } /* init func */ { string FuncName = GetUserEffectSpecInitFuncName(Template); if (FuncName != null) { FuncCodeRec FuncCode = SynthParams.CodeCenter.ObtainFunctionHandle(FuncName); if (FuncCode == null) { // Function missing; should have been found by CheckUnreferencedThings Debug.Assert(false); throw new ArgumentException(); } DataTypes[] argsTypes; DataTypes returnType; UserEffectGetInitSignature(Template, out argsTypes, out returnType); FunctionSignature expectedSignature = new FunctionSignature(argsTypes, returnType); FunctionSignature actualSignature = new FunctionSignature( FuncCode.GetFunctionParameterTypeList(), FuncCode.GetFunctionReturnType()); if (!FunctionSignature.Equals(expectedSignature, actualSignature)) { // Function type mismatch; should have been found by CheckUnreferencedThings Debug.Assert(false); throw new ArgumentException(); } Proc.InitFunc = FuncCode.GetFunctionPcode(); } } /* data func */ { DataTypes[] argsTypes; DataTypes returnType; UserEffectGetDataSignature(Template, out argsTypes, out returnType); FunctionSignature expectedSignature = new FunctionSignature(argsTypes, returnType); foreach (string FuncName in GetUserEffectSpecProcessDataFuncNames(Template)) { FuncCodeRec FuncCode = SynthParams.CodeCenter.ObtainFunctionHandle(FuncName); if (FuncCode == null) { // Function missing; should have been found by CheckUnreferencedThings Debug.Assert(false); throw new ArgumentException(); } FunctionSignature actualSignature = new FunctionSignature( FuncCode.GetFunctionParameterTypeList(), FuncCode.GetFunctionReturnType()); if (FunctionSignature.Equals(expectedSignature, actualSignature)) { Proc.DataFunc = FuncCode.GetFunctionPcode(); break; } } if (Proc.DataFunc == null) { // None matched -- should have been found by CheckUnreferencedThings Debug.Assert(false); throw new ArgumentException(); } } Proc.paramCount = GetUserEffectSpecParamCount(Template); Proc.paramResults = new double[Proc.paramCount]; Proc.paramResultsPrevious = new double[Proc.paramCount]; // create state objects DataTypes[] stateTypes = UserEffectGetWorkspaceTypes(Template); Proc.userState = new ArrayHandle[stateTypes.Length]; for (int i = 0; i < Proc.userState.Length; i++) { switch (stateTypes[i]) { default: Debug.Assert(false); throw new ArgumentException(); case DataTypes.eArrayOfInteger: Proc.userState[i] = new ArrayHandleInt32(new int[0]); break; case DataTypes.eArrayOfFloat: Proc.userState[i] = new ArrayHandleFloat(new float[0]); break; case DataTypes.eArrayOfDouble: Proc.userState[i] = new ArrayHandleDouble(new double[0]); break; } } Proc.smoothingBuffers = new SmoothingEntry[Template.Items.Length]; for (int i = 0; i < Template.Items.Length; i++) { if (Template.Items[i].Smoothed) { float[] vector = new float[SynthParams.nAllocatedPointsOneChannel]; Proc.smoothingBuffers[i].vector = vector; Proc.smoothingBuffers[i].arrayHandle = new ArrayHandleFloat(vector); } } /* initialize user state */ if (Proc.InitFunc != null) { int argCount = 1 /*retval*/ + 1 /*t*/ + 1 /*bpm*/ + 1 /*samplingRate*/ + 1 /*maxSampleCount*/ + Proc.userState.Length /*user state arrays*/ + 1 /*retaddr*/; SynthParams.FormulaEvalContext.EmptyParamStackEnsureCapacity(argCount); StackElement[] StackBase; int StackNumElements; SynthParams.FormulaEvalContext.GetRawStack(out StackBase, out StackNumElements); StackBase[StackNumElements++].Data.Double = SynthParams.dElapsedTimeInSeconds; /* t */ StackBase[StackNumElements++].Data.Double = SynthParams.dCurrentBeatsPerMinute; /* bpm */ StackBase[StackNumElements++].Data.Double = sr; /* samplingRate */ StackBase[StackNumElements++].Data.Integer = SynthParams.nAllocatedPointsOneChannel; /* maxSampleCount */ for (int i = 0; i < Proc.userState.Length; i++) { StackBase[StackNumElements++].reference.arrayHandleGeneric = Proc.userState[i]; // user state } StackNumElements++; /* return address placeholder */ SynthParams.FormulaEvalContext.UpdateRawStack(StackBase, StackNumElements); EvalErrInfoRec ErrorInfo; EvalErrors Error = PcodeSystem.EvaluatePcode( SynthParams.FormulaEvalContext, Proc.InitFunc, SynthParams.CodeCenter, out ErrorInfo, PcodeExternsNull.Default, ref SynthParams.pcodeThreadContext); if (Error != EvalErrors.eEvalNoError) { SynthParams.ErrorInfo.ErrorEx = SynthErrorSubCodes.eSynthErrorExUserEffectFunctionEvalError; SynthParams.ErrorInfo.UserEvalErrorCode = Error; SynthParams.ErrorInfo.UserEvalErrorInfo = ErrorInfo; return(SynthErrorCodes.eSynthErrorEx); } Debug.Assert(SynthParams.FormulaEvalContext.GetStackNumElements() == 1); // return value SynthParams.FormulaEvalContext.Clear(); } // initialize sample data in/out staging areas Proc.leftWorkspace = new float[SynthParams.nAllocatedPointsOneChannel]; Proc.leftWorkspaceHandle = new ArrayHandleFloat(null); Proc.rightWorkspace = new float[SynthParams.nAllocatedPointsOneChannel]; Proc.rightWorkspaceHandle = new ArrayHandleFloat(null); return(SynthErrorCodes.eSynthDone); }
/* apply user effect processing to some stuff */ public SynthErrorCodes Apply( float[] workspace, int lOffset, int rOffset, int nActualFrames, SynthParamRec SynthParams) { Debug.Assert(nActualFrames % SynthParams.iOversampling == 0); // reinit each cycle because user code can reallocate or remove them leftWorkspaceHandle.floats = leftWorkspace; rightWorkspaceHandle.floats = rightWorkspace; int c = nActualFrames; double sr = SynthParams.dSamplingRate; if ((SynthParams.iOversampling == 1) || !disableOversampling) { FloatVectorCopyUnaligned( workspace, lOffset, leftWorkspaceHandle.floats, // not vector-aligned 0, nActualFrames); FloatVectorCopyUnaligned( workspace, rOffset, rightWorkspaceHandle.floats, // not vector-aligned 0, nActualFrames); } else { // downsample c /= SynthParams.iOversampling; sr /= SynthParams.iOversampling; for (int i = 0, j = 0; i < nActualFrames; i += SynthParams.iOversampling, j++) { leftWorkspaceHandle.floats[j] = workspace[i + lOffset]; rightWorkspaceHandle.floats[j] = workspace[i + rOffset]; } } int argCount = 1 /*retval*/ + 1 /*t*/ + 1 /*bpm*/ + 1 /*samplingRate*/ + 1 /*leftdata*/ + 1 /*rightdata*/ + 1 /*count*/ + userState.Length /*user state*/ + paramCount /*user params*/ + 1 /*retaddr*/; SynthParams.FormulaEvalContext.EmptyParamStackEnsureCapacity(argCount); int StackNumElements; StackElement[] StackBase; SynthParams.FormulaEvalContext.GetRawStack(out StackBase, out StackNumElements); StackBase[StackNumElements++].Data.Double = SynthParams.dElapsedTimeInSeconds; /* t */ StackBase[StackNumElements++].Data.Double = SynthParams.dCurrentBeatsPerMinute; /* bpm */ StackBase[StackNumElements++].Data.Double = sr; /* samplingRate */ StackBase[StackNumElements++].reference.arrayHandleFloat = leftWorkspaceHandle; // leftdata StackBase[StackNumElements++].reference.arrayHandleFloat = rightWorkspaceHandle; // rightdata StackBase[StackNumElements++].Data.Integer = c; for (int i = 0; i < userState.Length; i++) { StackBase[StackNumElements++].reference.arrayHandleGeneric = userState[i]; // user state } for (int i = 0; i < paramCount; i += 1) { if (smoothingBuffers[i].arrayHandle == null) { StackBase[StackNumElements++].Data.Double = paramResults[i]; // user params } else { // re-initialize handle in case user code cleared it last time smoothingBuffers[i].arrayHandle.floats = smoothingBuffers[i].vector; // compute smoothed data #if DEBUG Debug.Assert(!SynthParams.ScratchWorkspace1InUse); #endif if (smoothingBuffers[i].degraded) { FloatVectorSet( SynthParams.workspace, SynthParams.ScratchWorkspace1LOffset, nActualFrames, (float)paramResults[i]); } else { if ((params_Osc == null) || !EnvelopeCurrentSegmentExponential(params_Osc[i].Envelope)) { // linear FloatVectorAdditiveRecurrence( SynthParams.workspace, SynthParams.ScratchWorkspace1LOffset, (float)paramResultsPrevious[i], (float)paramResults[i], nActualFrames); } else { // geometric FloatVectorMultiplicativeRecurrence( SynthParams.workspace, SynthParams.ScratchWorkspace1LOffset, (float)paramResultsPrevious[i], (float)paramResults[i], nActualFrames); } } FloatVectorCopyUnaligned( SynthParams.workspace, SynthParams.ScratchWorkspace1LOffset, smoothingBuffers[i].vector, // target not aligned 0, nActualFrames); StackBase[StackNumElements++].reference.arrayHandleFloat = smoothingBuffers[i].arrayHandle; // user params } } StackNumElements++; /* return address placeholder */ SynthParams.FormulaEvalContext.UpdateRawStack(StackBase, StackNumElements); EvalErrInfoRec ErrorInfo; EvalErrors Error = PcodeSystem.EvaluatePcode( SynthParams.FormulaEvalContext, this.DataFunc, SynthParams.CodeCenter, out ErrorInfo, PcodeExternsNull.Default, ref SynthParams.pcodeThreadContext); if (Error != EvalErrors.eEvalNoError) { SynthParams.ErrorInfo.ErrorEx = SynthErrorSubCodes.eSynthErrorExUserEffectFunctionEvalError; SynthParams.ErrorInfo.UserEvalErrorCode = Error; SynthParams.ErrorInfo.UserEvalErrorInfo = ErrorInfo; return(SynthErrorCodes.eSynthErrorEx); } Debug.Assert(SynthParams.FormulaEvalContext.GetStackNumElements() == 1); // return value SynthParams.FormulaEvalContext.Clear(); if ((leftWorkspaceHandle.floats != null) && (leftWorkspaceHandle.floats.Length >= c) && (rightWorkspaceHandle.floats != null) && (rightWorkspaceHandle.floats.Length >= c)) { if ((SynthParams.iOversampling == 1) || !disableOversampling) { // remove NaN/Infinity - prevent user effect misbehavior from taking rest of system down FloatVectorCopyReplaceNaNInf( leftWorkspaceHandle.floats, // unaligned permitted 0, workspace, lOffset, nActualFrames); FloatVectorCopyReplaceNaNInf( rightWorkspaceHandle.floats, // unaligned permitted 0, workspace, rOffset, nActualFrames); } else { // upsample Upsample( leftWorkspaceHandle.floats, 0, workspace, lOffset, c, SynthParams.iOversampling, ref lastLeft); Upsample( rightWorkspaceHandle.floats, 0, workspace, rOffset, c, SynthParams.iOversampling, ref lastRight); // remove NaN/Infinity - prevent user effect misbehavior from taking rest of system down FloatVectorCopyReplaceNaNInf( workspace, lOffset, workspace, lOffset, nActualFrames); FloatVectorCopyReplaceNaNInf( workspace, rOffset, workspace, rOffset, nActualFrames); } } return(SynthErrorCodes.eSynthDone); }
private void DoCalculation() { if (!mainWindow.MakeUpToDate()) { return; } SetUpSelection(); PcodeRec FuncCode; DataTypes ReturnType; if (!Compile(out FuncCode, out ReturnType)) { return; } /* try to evaluate the code */ StringBuilder Output = new StringBuilder(); using (ParamStackRec ParamList = new ParamStackRec()) { /* return address placeholder */ ParamList.AddIntegerToStack(0); /* executing the actual code */ EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, document.CodeCenter, out ErrorInfo, new PcodeExterns(mainWindow)); if (EvaluationError != EvalErrors.eEvalNoError) { PcodeEvaluationErrorInfo error = new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, document.CodeCenter); MessageBox.Show(error.CompositeErrorMessage, "Evaluation Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } Debug.Assert(ParamList.GetStackNumElements() == 1); // return value /* add new data to window */ Output.AppendLine(); switch (ReturnType) { default: Debug.Assert(false); throw new InvalidOperationException(); case DataTypes.eBoolean: Output.AppendLine( ParamList.GetStackInteger(0) != 0 ? "returns boolean: true" : "returns boolean: false"); break; case DataTypes.eInteger: Output.AppendFormat("returns integer: {0}", ParamList.GetStackInteger(0)); Output.AppendLine(); break; case DataTypes.eFloat: Output.AppendFormat("returns float: {0}", ParamList.GetStackFloat(0)); Output.AppendLine(); break; case DataTypes.eDouble: Output.AppendFormat("returns double: {0}", ParamList.GetStackDouble(0)); Output.AppendLine(); break; case DataTypes.eArrayOfBoolean: Output.AppendFormat("returns array of booleans:"); Output.AppendLine(); goto ArrayMakePoint; case DataTypes.eArrayOfByte: Output.AppendFormat("returns array of bytes:"); Output.AppendLine(); goto ArrayMakePoint; case DataTypes.eArrayOfInteger: Output.AppendFormat("returns array of integers:"); Output.AppendLine(); goto ArrayMakePoint; case DataTypes.eArrayOfFloat: Output.AppendFormat("returns array of floats:"); Output.AppendLine(); goto ArrayMakePoint; case DataTypes.eArrayOfDouble: Output.AppendFormat("returns array of doubles:"); Output.AppendLine(); ArrayMakePoint: if (ParamList.GetStackArray(0) == null) { Output.AppendFormat("NIL"); Output.AppendLine(); } else { switch (ReturnType) { default: Debug.Assert(false); throw new InvalidOperationException(); case DataTypes.eArrayOfBoolean: { byte[] a = (byte[])ParamList.GetStackArray(0); for (int i = 0; i < a.Length; i++) { int value = a[i]; Output.AppendFormat("{0,8}: {1}", i, value != 0 ? "true" : "false"); Output.AppendLine(); } } break; case DataTypes.eArrayOfByte: { byte[] a = (byte[])ParamList.GetStackArray(0); for (int i = 0; i < a.Length; i++) { int value = a[i]; Output.AppendFormat("{0,8}:{1,3}", i, value); Output.AppendLine(); } } break; case DataTypes.eArrayOfInteger: { int[] a = (int[])ParamList.GetStackArray(0); for (int i = 0; i < a.Length; i++) { int value = a[i]; Output.AppendFormat("{0,8}:{1,10}", i, value); Output.AppendLine(); } } break; case DataTypes.eArrayOfFloat: { float[] a = (float[])ParamList.GetStackArray(0); for (int i = 0; i < a.Length; i++) { float value = a[i]; Output.AppendFormat("{0,8}:{1,12}", i, value); Output.AppendLine(); } } break; case DataTypes.eArrayOfDouble: { double[] a = (double[])ParamList.GetStackArray(0); for (int i = 0; i < a.Length; i++) { double value = a[i]; Output.AppendFormat("{0,8}:{1,18}", i, value); Output.AppendLine(); } } break; } } break; } } Output.AppendLine(); textBox.ReplaceRangeAndSelect( textBox.End, textBox.End, Output.ToString(), 1); LastLine = textBox.Count - 1; }
public override bool EnsureBuilt( bool force, PcodeSystem.IEvaluationContext pcodeEnvironment, BuildFailedCallback failedCallback) { if (!force && (WaveTableData != null)) { return(true); } WaveTableData = null; PcodeRec FuncCode; if (!BuildCode(failedCallback, out FuncCode)) { return(false); } using (ParamStackRec ParamList = new ParamStackRec()) { ArrayHandleFloat dataHandle = new ArrayHandleFloat(new float[NumFrames * NumTables]); int initialCapacity = 1 /*frames*/ + 1 /*tables*/ + 1 /*data*/ + 1 /*retaddr*/; ParamList.EmptyParamStackEnsureCapacity(initialCapacity); ParamList.AddIntegerToStack(NumFrames); ParamList.AddIntegerToStack(NumTables); ParamList.AddArrayToStack(dataHandle); ParamList.AddIntegerToStack(0); /* return address placeholder */ CodeCenterRec CodeCenter = ((Document)Parent).CodeCenter; EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, CodeCenter, out ErrorInfo, pcodeEnvironment); if (EvaluationError != EvalErrors.eEvalNoError) { failedCallback( this, new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, CodeCenter)); return(false); } Debug.Assert(ParamList.GetStackNumElements() == initialCapacity); // args - retaddr + return value #if DEBUG ParamList.Elements[2].AssertFloatArray(); #endif dataHandle = ParamList.Elements[2].reference.arrayHandleFloat; WaveTableData = new WaveTableStorageRec(NumTables, NumFrames, NumBitsType.eSample24bit); float[] NewData = dataHandle.floats; if (NewData.Length != NumTables * NumFrames) { failedCallback( this, new PcodeEvaluationErrorInfo( "<anonymous>", PcodeSystem.GetPcodeErrorMessage(EvalErrors.eEvalArrayWrongDimensions), 1)); return(false); } for (int i = 0; i < NumTables; i++) { WaveTableStorageRec.Table table = WaveTableData.ListOfTables[i]; for (int j = 0; j < NumFrames; j++) { table[j] = NewData[i * NumFrames + j]; } } } return(true); }
public override bool EnsureBuilt( bool force, PcodeSystem.IEvaluationContext pcodeEnvironment, BuildFailedCallback failedCallback) { if (!force && (SampleData != null)) { return(true); } SampleData = null; PcodeRec FuncCode; if (!BuildCode(failedCallback, out FuncCode)) { return(false); } using (ParamStackRec ParamList = new ParamStackRec()) { ArrayHandleFloat dataHandleLeft = new ArrayHandleFloat(new float[0]); ArrayHandleFloat dataHandleRight = new ArrayHandleFloat(new float[0]); int initialCapacity = 1 /*loopstart1*/ + 1 /*loopstart2*/ + 1 /*loopstart3*/ + 1 /*loopend1*/ + 1 /*loopend2*/ + 1 /*loopend3*/ + 1 /*origin*/ + 1 /*samplingrate*/ + 1 /*naturalfrequency*/ + (NumChannels == NumChannelsType.eSampleStereo ? 2 : 1) /*data or leftdata/rightdata */ + 1 /*retaddr*/; ParamList.EmptyParamStackEnsureCapacity(initialCapacity); ParamList.AddIntegerToStack(LoopStart1); ParamList.AddIntegerToStack(LoopStart2); ParamList.AddIntegerToStack(LoopStart3); ParamList.AddIntegerToStack(LoopEnd1); ParamList.AddIntegerToStack(LoopEnd2); ParamList.AddIntegerToStack(LoopEnd3); ParamList.AddIntegerToStack(Origin); ParamList.AddIntegerToStack(SamplingRate); ParamList.AddDoubleToStack(NaturalFrequency); if (NumChannels == NumChannelsType.eSampleStereo) { ParamList.AddArrayToStack(dataHandleLeft); ParamList.AddArrayToStack(dataHandleRight); } else { ParamList.AddArrayToStack(dataHandleLeft); } ParamList.AddIntegerToStack(0); /* return address placeholder */ CodeCenterRec CodeCenter = ((Document)Parent).CodeCenter; EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, CodeCenter, out ErrorInfo, pcodeEnvironment); if (EvaluationError != EvalErrors.eEvalNoError) { failedCallback( this, new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, CodeCenter)); return(false); } Debug.Assert(ParamList.GetStackNumElements() == initialCapacity); // args - retaddr + return value #if DEBUG ParamList.Elements[9].AssertFloatArray(); #endif dataHandleLeft = ParamList.Elements[9].reference.arrayHandleFloat; if (NumChannels == NumChannelsType.eSampleStereo) { #if DEBUG ParamList.Elements[10].AssertFloatArray(); #endif dataHandleRight = ParamList.Elements[10].reference.arrayHandleFloat; } if (NumChannels == NumChannelsType.eSampleStereo) { float[] Left = dataHandleLeft.floats; float[] Right = dataHandleRight.floats; if (Left.Length != Right.Length) { failedCallback( this, new PcodeEvaluationErrorInfo( "<anonymous>", "Left and Right algorithmic sample arrays are not the same size.", 1)); return(false); } SampleData = new SampleStorageActualRec(Left.Length, NumBitsType.Max, NumChannels); for (int i = 0; i < Left.Length; i++) { SampleData[2 * i + 0] = Left[i]; SampleData[2 * i + 1] = Right[i]; } } else { float[] Mono = dataHandleLeft.floats; SampleData = new SampleStorageActualRec(Mono.Length, NumBitsType.Max, NumChannels); for (int i = 0; i < Mono.Length; i++) { SampleData[i] = Mono[i]; } } } return(true); }