示例#1
0
        protected override DiscreteSignal Render(NoteSegment segment)
        {
            DiscreteSignal mainSignal = null;

            if (segment is PercussionNoteSegment percussionNoteSegment)
            {
                mainSignal = GetPercussionSignal(percussionNoteSegment.PercussionType, percussionNoteSegment.DurationSamples);
            }
            else if (segment is MelodicNoteSegment melodicNoteSegment)
            {
                // Combine a Sine wave and a Square wave
                mainSignal = SignalHelper.GetSine(melodicNoteSegment.Frequency, melodicNoteSegment.DurationSamples);
                mainSignal.CombineAdd(SignalHelper.GetSquare(melodicNoteSegment.Frequency, melodicNoteSegment.DurationSamples));
            }

            float velocityMultiplier = segment.Velocity / 127f; // Velocity ranges from 0 - 127

            // A simple way of doing an equalizer
            float balanceMultiplier = BalanceProvider.GetMultiplier(segment);

            // Scale the signals based on their velocity and balance multipliers
            mainSignal.Amplify(velocityMultiplier * balanceMultiplier);
            mainSignal.ApplyAdsr(AdsrEnvelopeProvider.CreateEnvelope(segment));

            return(mainSignal);
        }