예제 #1
0
        public IList <MusicSampleProvider> GetNextMixerInputs(int sampleCount)
        {
            List <MusicSampleProvider> mixerInputs = new List <MusicSampleProvider>();
            int samplePos = 0;

            while (samplePos < sampleCount)
            {
                for (int note = 0; note < drumPattern.Notes; note++)
                {
                    if (drumPattern[note, currentStep] != 0)
                    {
                        var sampleProvider = drumKit.GetSampleProvider(note);
                        Debug.WriteLine("beat at step {0}, patternPostion={1}", currentStep, patternPosition);
                        double offsetFromCurrent = (currentStep - patternPosition);
                        if (offsetFromCurrent < 0)
                        {
                            offsetFromCurrent += drumPattern.Steps;
                        }
                        sampleProvider.DelayBy = (int)(this.samplesPerStep * offsetFromCurrent);
                        mixerInputs.Add(sampleProvider);
                    }
                }

                samplePos += samplesPerStep;
                currentStep++;
                currentStep = currentStep % drumPattern.Steps;
            }
            this.patternPosition += ((double)sampleCount / samplesPerStep);
            if (this.patternPosition > drumPattern.Steps)
            {
                this.patternPosition -= drumPattern.Steps;
            }
            return(mixerInputs);
        }
예제 #2
0
        public IList <MusicSampleProvider> GetNextMixerInputs(int sampleCount)
        {
            List <MusicSampleProvider> mixerInputs = new List <MusicSampleProvider>();
            int samplePos = 0;

            if (newTempo)
            {
                int samplesPerBeat = (this.drumKit.WaveFormat.Channels * this.drumKit.WaveFormat.SampleRate * 60) / tempo;
                this.samplesPerStep = samplesPerBeat / 4;
                //patternPosition = 0;
                newTempo = false;
            }

            while (samplePos < sampleCount)
            {
                double offsetFromCurrent = (currentStep - patternPosition);
                if (offsetFromCurrent < 0)
                {
                    offsetFromCurrent += drumPattern.Steps;
                }
                int delayForThisStep = (int)(this.samplesPerStep * offsetFromCurrent);
                if (delayForThisStep >= sampleCount)
                {
                    // don't queue up any samples beyond the requested time range
                    break;
                }

                for (int note = 0; note < drumPattern.Notes; note++)
                {
                    if (drumPattern[note, currentStep] != 0)
                    {
                        var sampleProvider = drumKit.GetSampleProvider(note);
                        sampleProvider.DelayBy = delayForThisStep;
                        Debug.WriteLine("beat at step {0}, patternPostion={1}, delayBy {2}", currentStep, patternPosition, delayForThisStep);
                        mixerInputs.Add(sampleProvider);
                    }
                }

                samplePos += samplesPerStep;
                currentStep++;
                currentStep = currentStep % drumPattern.Steps;
            }
            this.patternPosition += ((double)sampleCount / samplesPerStep);
            if (this.patternPosition > drumPattern.Steps)
            {
                this.patternPosition -= drumPattern.Steps;
            }
            return(mixerInputs);
        }