/* processed gain factor */ public static void ConvolverSpecSetProcessedGainAccent( ConvolverSpecRec Spec, double Value, int AccentNum) { SetAccentMemberValue(ref Spec.ProcessedGainAccent, AccentNum, Value); }
/* set latency */ public static void ConvolverSpecSetLatency( ConvolverSpecRec Spec, double Latency) { Spec.Latency = Latency; Spec.LatencySpecified = true; }
/* add a convolver to the spec list */ public static void AddConvolverToEffectSpecList( EffectSpecListRec EffectSpecList, ConvolverSpecRec ConvolverSpec, bool EnabledFlag) { AddGenericToEffectSpecList(EffectSpecList, EffectTypes.eConvolverEffect, ConvolverSpec, EnabledFlag); }
/* create new convolver spec */ public static ConvolverSpecRec NewConvolverSpec() { ConvolverSpecRec Spec = new ConvolverSpecRec(); Spec.Source = ConvolveSrcType.eConvolveMono; return(Spec); }
/* processed gain factor */ public static void ConvolverSpecGetProcessedGain( ConvolverSpecRec Spec, out ScalarParamEvalRec ParamsOut) { InitScalarParamEval( Spec.ProcessedGain, ref Spec.ProcessedGainAccent, Spec.ProcessedGainFormula, out ParamsOut); }
/* impulse response name, for bistereo right into right */ public static string ConvolverSpecGetImpulseResponseBiStereoRightIntoRight(ConvolverSpecRec Spec) { #if DEBUG if (Spec.ImpulseResponseNameBiStereoRightIntoRight == null) { Debug.Assert(false); throw new ArgumentException(); } #endif return(Spec.ImpulseResponseNameBiStereoRightIntoRight); }
/* impulse response name, for mono */ public static string ConvolverSpecGetImpulseResponseMono(ConvolverSpecRec Spec) { #if DEBUG if (Spec.ImpulseResponseNameMono == null) { Debug.Assert(false); throw new ArgumentException(); } #endif return(Spec.ImpulseResponseNameMono); }
/* impulse response name, for bistereo right into right */ public static void ConvolverSpecSetImpulseResponseBiStereoRightIntoRight( ConvolverSpecRec Spec, string Name) { #if DEBUG if (Spec.ImpulseResponseNameBiStereoRightIntoRight != null) { Debug.Assert(false); throw new ArgumentException(); } #endif Spec.ImpulseResponseNameBiStereoRightIntoRight = Name; }
/* set source channel */ public static void ConvolverSpecSetSourceType( ConvolverSpecRec Spec, ConvolveSrcType Source) { #if DEBUG if ((Source != ConvolveSrcType.eConvolveMono) && (Source != ConvolveSrcType.eConvolveStereo) && (Source != ConvolveSrcType.eConvolveBiStereo)) { Debug.Assert(false); throw new ArgumentException(); } #endif Spec.Source = Source; }
/* 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; }
public static SynthErrorCodes CheckConvolverEffectForUnreferencedSamples( ConvolverSpecRec ConvolverEffect, CheckUnrefParamRec Param) { ConvolverCheckRec[] RuleArray; switch (ConvolverSpecGetSourceType(ConvolverEffect)) { default: Debug.Assert(false); throw new ArgumentException(); case ConvolveSrcType.eConvolveMono: RuleArray = ConvolverCheckMono; break; case ConvolveSrcType.eConvolveStereo: RuleArray = ConvolverCheckStereo; break; case ConvolveSrcType.eConvolveBiStereo: RuleArray = ConvolverCheckBiStereo; break; } for (int i = 0; i < RuleArray.Length; i += 1) { string ImpulseResponse = RuleArray[i].ConvolverSpecGetImpulseResponse(ConvolverEffect); if (!WaveSampDictDoesSampleExist( Param.Dictionary, ImpulseResponse)) { Param.ErrorInfo.ErrorEx = SynthErrorSubCodes.eSynthErrorExUndefinedSample; Param.ErrorInfo.SampleName = ImpulseResponse; return(SynthErrorCodes.eSynthErrorEx); } } return(SynthErrorCodes.eSynthDone); }
/* get source channel */ public static ConvolveSrcType ConvolverSpecGetSourceType(ConvolverSpecRec Spec) { return(Spec.Source); }
/* get latency */ public static double ConvolverSpecGetLatency(ConvolverSpecRec Spec) { Debug.Assert(Spec.LatencySpecified); return(Spec.Latency); }
public static bool ConvolverSpecGetLatencySpecified(ConvolverSpecRec Spec) { return(Spec.LatencySpecified); }
/* create a new convolver */ public static SynthErrorCodes NewConvolver( ConvolverSpecRec Template, SynthParamRec SynthParams, out ConvolverRec ConvolverOut) { ConvolverOut = null; ConvolverRec Convolver = new ConvolverRec(); Convolver.Type = ConvolverSpecGetSourceType(Template); ConvRuleRec[] RuleArray; switch (Convolver.Type) { default: Debug.Assert(false); throw new ArgumentException(); case ConvolveSrcType.eConvolveMono: RuleArray = ConvMonoRule; break; case ConvolveSrcType.eConvolveStereo: RuleArray = ConvStereoRule; break; case ConvolveSrcType.eConvolveBiStereo: RuleArray = ConvBiStereoRule; break; } int?Latency = null; if (ConvolverSpecGetLatencySpecified(Template)) { Latency = (int)(ConvolverSpecGetLatency(Template) * SynthParams.dSamplingRate); if (Latency.Value < 0) { Latency = 0; } } // validation pass int maximumImpulseResponseLength = 0; float[][] Data = new float[RuleArray.Length][]; int[] Frames = new int[RuleArray.Length]; for (int i = 0; i < RuleArray.Length; i += 1) { NumChannelsType NumChannels; int SamplingRate; int unusedInt; double unusedDouble; bool unusedBool; string ImpulseResponseName = RuleArray[i].ConvolverSpecGetImpulseResponse(Template); if (!WaveSampDictGetSampleInfo( SynthParams.Dictionary, ImpulseResponseName, out Data[i], out Frames[i], out NumChannels, out unusedInt, out unusedInt, out unusedInt, out unusedInt, out unusedInt, out unusedInt, out unusedInt, out unusedDouble, out SamplingRate, out unusedBool, out unusedBool, out unusedBool)) { // should never be provided with name of non-existent sample data Debug.Assert(false); throw new ArgumentException(); } if (SamplingRate * SynthParams.iOversampling != SynthParams.iSamplingRate) { SynthParams.ErrorInfo.ErrorEx = SynthErrorSubCodes.eSynthErrorExConvolverBadSamplingRate; SynthParams.ErrorInfo.SampleName = ImpulseResponseName; return(SynthErrorCodes.eSynthErrorEx); } if (NumChannels != NumChannelsType.eSampleMono) { SynthParams.ErrorInfo.ErrorEx = SynthErrorSubCodes.eSynthErrorExConvolverBadNumChannels; SynthParams.ErrorInfo.SampleName = ImpulseResponseName; return(SynthErrorCodes.eSynthErrorEx); } maximumImpulseResponseLength = Math.Max(maximumImpulseResponseLength, Frames[i]); } if (!Latency.HasValue) { Latency = maximumImpulseResponseLength * SynthParams.iOversampling; } for (int i = 0; i < RuleArray.Length; i += 1) { IConvolution ConvStream; SynthErrorCodes result = ConvolveStreamFactory.NewConvStream( Data[i], Frames[i], ConvolverSpecGetLatencySpecified(Template), Latency.Value, SynthParams.iOversampling, SynthParams.ErrorInfo, out ConvStream); if (result != SynthErrorCodes.eSynthDone) { return(result); } switch (i) { default: Debug.Assert(false); throw new InvalidOperationException(); case 0: Convolver.ConvStream0 = ConvStream; break; case 1: Convolver.ConvStream1 = ConvStream; break; case 2: Convolver.ConvStream2 = ConvStream; break; case 3: Convolver.ConvStream3 = ConvStream; break; } } ConvolverSpecGetDirectGain( Template, out Convolver.DirectGain); ConvolverSpecGetProcessedGain( Template, out Convolver.ProcessedGain); /* done successfully */ ConvolverOut = Convolver; return(SynthErrorCodes.eSynthDone); }