Esempio n. 1
0
        /* create a new oscillator effect generator */
        public static SynthErrorCodes NewOscEffectGenerator(
            EffectSpecListRec SpecList,
            ref AccentRec Accents,
            double HurryUp,
            double InitialFrequency,
            double FreqForMultisampling,
            out int PreOriginTimeOut,
            PlayTrackInfoRec TrackInfo,
            SynthParamRec SynthParams,
            out OscEffectGenRec GeneratorOut)
        {
            int OnePreOrigin;

            GeneratorOut     = null;
            PreOriginTimeOut = 0;

            OscEffectGenRec Generator = New(ref SynthParams.freelists.OscEffectGenRecFreeList);
            int             count     = Generator.count = GetEffectSpecListEnabledLength(SpecList);

            IOscillatorEffect[] List = Generator.List = New(ref SynthParams.freelists.IOscillatorEffectFreeList, count); // zeroed
            if (unchecked ((uint)count > (uint)List.Length))
            {
                Debug.Assert(false);
                throw new IndexOutOfRangeException();
            }

            int MaxPreOrigin = 0;

            /* build list of thingers */
            int j = 0;

            for (int i = 0; j < count; i++)
            {
                /* see if effect is enabled */
                if (!IsEffectFromEffectSpecListEnabled(SpecList, i))
                {
                    continue;
                }

                /* fill in fields */
                EffectTypes Type = GetEffectSpecListElementType(SpecList, i);
                switch (Type)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case EffectTypes.eDelayEffect:
                    List[j] = DelayUnifiedRec.NewOscUnifiedDelayLineProcessor(
                        GetDelayEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams);
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                    break;

                case EffectTypes.eNLProcEffect:
                    List[j] = NLProcUnifiedRec.NewOscNLProcProcessor(
                        GetNLProcEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams);
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                    break;

                case EffectTypes.eFilterEffect:
                    List[j] = FilterArrayRec.NewOscFilterArrayProcessor(
                        GetFilterEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams);
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                    break;

                case EffectTypes.eAnalyzerEffect:
                    List[j] = AnalyzerRec.NewAnalyzer(
                        GetAnalyzerEffectFromEffectSpecList(SpecList, i),
                        SynthParams);
                    break;

                case EffectTypes.eHistogramEffect:
                    List[j] = HistogramRec.NewHistogram(
                        GetHistogramEffectFromEffectSpecList(SpecList, i),
                        SynthParams);
                    break;

                case EffectTypes.eResamplerEffect:
                    List[j] = ResamplerRec.NewResampler(
                        GetResamplerEffectFromEffectSpecList(SpecList, i),
                        SynthParams);
                    break;

                case EffectTypes.eCompressorEffect:
                    List[j] = CompressorRec.NewOscCompressor(
                        GetCompressorEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams);
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                    break;

                case EffectTypes.eVocoderEffect:
                    List[j] = VocoderRec.NewOscVocoder(
                        GetVocoderEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams);
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                    break;

                case EffectTypes.eIdealLowpassEffect:
                    List[j] = IdealLPRec.NewIdealLP(
                        GetIdealLPEffectFromEffectSpecList(SpecList, i),
                        SynthParams);
                    break;

                case EffectTypes.eUserEffect:
                {
                    UserEffectProcRec userEffect;
                    SynthErrorCodes   error = UserEffectProcRec.NewOscUserEffectProc(
                        GetUserEffectFromEffectSpecList(SpecList, i),
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams,
                        out userEffect);
                    if (error != SynthErrorCodes.eSynthDone)
                    {
                        return(error);
                    }
                    List[j] = userEffect;
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                }
                break;

                case EffectTypes.ePluggableEffect:
                {
                    PluggableSpec Spec = GetPluggableEffectFromEffectSpecList(SpecList, i);
                    Debug.Assert(Spec is PluggableOscSpec);
                    PluggableOscEffectTemplate template = new PluggableOscEffectTemplate(
                        (PluggableOscSpec)Spec,
                        SynthParams);
                    IOscillatorEffect effect;
                    SynthErrorCodes   error = template.Create(
                        ref Accents,
                        HurryUp,
                        InitialFrequency,
                        FreqForMultisampling,
                        out OnePreOrigin,
                        TrackInfo,
                        SynthParams,
                        out effect);
                    if (error != SynthErrorCodes.eSynthDone)
                    {
                        return(error);
                    }
                    List[j] = effect;
                    if (OnePreOrigin > MaxPreOrigin)
                    {
                        MaxPreOrigin = OnePreOrigin;
                    }
                }
                break;
                }

                j++;
            }
            Debug.Assert(j == count);

            PreOriginTimeOut = MaxPreOrigin;

            GeneratorOut = Generator;
            return(SynthErrorCodes.eSynthDone);
        }
        /* create a new track effect generator */
        public static SynthErrorCodes NewTrackEffectGenerator(
            EffectSpecListRec SpecList,
            SynthParamRec SynthParams,
            out TrackEffectGenRec GeneratorOut)
        {
            GeneratorOut = null;

            TrackEffectGenRec Generator = new TrackEffectGenRec();

            Generator.Enable         = true;
            Generator.AutoQuiescence = EffectSpecListIsAutoQuiescenceEnabled(SpecList);
            if (Generator.AutoQuiescence)
            {
                Generator.Enable    = false; /* start with it off in this case */
                Generator.GateLevel = (float)(Math.Pow(
                                                  2,
                                                  EffectSpecListGetAutoQuiescenceDecibels(SpecList) * (1 / -6.0205999132796239))
                                              / SynthParams.fOverallVolumeScaling);
                Generator.WindowDuration = (int)(SynthParams.dEnvelopeRate
                                                 * EffectSpecListGetAutoQuiescenceWindowDuration(SpecList));
                Generator.CurrentWindowDuration = 0;
            }

            /* this is the current envelope update index for removing things from the */
            /* scanning gap list (i.e. the back edge of the scanning gap) */
            /* by setting this negative, we cause the scanning gap to open. */
            Generator.ExecutionIndex = -SynthParams.iScanningGapWidthInEnvelopeTicks;

            /* initialize accent trackers */
            InitAccentTracker(ref Generator.Accents0);
            InitAccentTracker(ref Generator.Accents1);
            InitAccentTracker(ref Generator.Accents2);
            InitAccentTracker(ref Generator.Accents3);
            InitAccentTracker(ref Generator.Accents4);
            InitAccentTracker(ref Generator.Accents5);
            InitAccentTracker(ref Generator.Accents6);
            InitAccentTracker(ref Generator.Accents7);

            /* build list of thingers */
            OneEffectRec Appender = null;
            int          l        = GetEffectSpecListLength(SpecList);

            for (int i = 0; i < l; i += 1)
            {
                /* see if effect is enabled */
                if (IsEffectFromEffectSpecListEnabled(SpecList, i))
                {
                    OneEffectRec Effect = new OneEffectRec();

                    /* link */
                    Effect.Next = null;
                    if (Appender == null)
                    {
                        Generator.List = Effect;
                    }
                    else
                    {
                        Appender.Next = Effect;
                    }
                    Appender = Effect;

                    /* fill in fields */
                    EffectTypes Type = GetEffectSpecListElementType(SpecList, i);
                    switch (Type)
                    {
                    default:
                        Debug.Assert(false);
                        throw new ArgumentException();

                    case EffectTypes.eDelayEffect:
                        Effect.u = DelayUnifiedRec.NewTrackDelayLineProcessor(
                            GetDelayEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eNLProcEffect:
                        Effect.u = NLProcUnifiedRec.NewTrackNLProcProcessor(
                            GetNLProcEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eFilterEffect:
                        Effect.u = FilterArrayRec.NewTrackFilterArrayProcessor(
                            GetFilterEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eAnalyzerEffect:
                        Effect.u = AnalyzerRec.NewAnalyzer(
                            GetAnalyzerEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eHistogramEffect:
                        Effect.u = HistogramRec.NewHistogram(
                            GetHistogramEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eResamplerEffect:
                        Effect.u = ResamplerRec.NewResampler(
                            GetResamplerEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eCompressorEffect:
                        Effect.u = CompressorRec.NewTrackCompressor(
                            GetCompressorEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eVocoderEffect:
                        Effect.u = VocoderRec.NewTrackVocoder(
                            GetVocoderEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eIdealLowpassEffect:
                        Effect.u = IdealLPRec.NewIdealLP(
                            GetIdealLPEffectFromEffectSpecList(SpecList, i),
                            SynthParams);
                        break;

                    case EffectTypes.eConvolverEffect:
                    {
                        ConvolverRec    ConvolverEffect;
                        SynthErrorCodes Result = ConvolverRec.NewConvolver(
                            GetConvolverEffectFromEffectSpecList(SpecList, i),
                            SynthParams,
                            out ConvolverEffect);
                        if (Result != SynthErrorCodes.eSynthDone)
                        {
                            return(Result);
                        }
                        Effect.u = ConvolverEffect;
                    }
                    break;

                    case EffectTypes.eUserEffect:
                    {
                        UserEffectProcRec userEffect;
                        SynthErrorCodes   error = UserEffectProcRec.NewTrackUserEffectProc(
                            GetUserEffectFromEffectSpecList(SpecList, i),
                            SynthParams,
                            out userEffect);
                        if (error != SynthErrorCodes.eSynthDone)
                        {
                            return(error);
                        }
                        Effect.u = userEffect;
                    }
                    break;

                    case EffectTypes.ePluggableEffect:
                    {
                        PluggableSpec Spec = GetPluggableEffectFromEffectSpecList(SpecList, i);
                        Debug.Assert(Spec is PluggableTrackSpec);
                        PluggableTrackEffectTemplate Template = new PluggableTrackEffectTemplate(
                            (PluggableTrackSpec)Spec,
                            SynthParams);
                        ITrackEffect    effect;
                        SynthErrorCodes error = Template.Create(
                            SynthParams,
                            out effect);
                        if (error != SynthErrorCodes.eSynthDone)
                        {
                            return(error);
                        }
                        Effect.u = effect;
                    }
                    break;
                    }
                }
            }

            GeneratorOut = Generator;
            return(SynthErrorCodes.eSynthDone);
        }