Example #1
0
        public StereoSample GetSample()
        {
            if (index >= (this.WaveData.Length - 200))
            {
                return(new StereoSample());
            }
            StereoSample sample = new StereoSample();

            byte[] left = new byte[2] {
                WaveData[index], WaveData[index + 1]
            };
            sample.LeftSample = BitConverter.ToInt16(left, 0);

            if (index + 2 < WaveData.Length && index + 3 < WaveData.Length)
            {
                byte[] right = new byte[2] {
                    WaveData[index + 2], WaveData[index + 3]
                };

                sample.RightSample = BitConverter.ToInt16(left, 0);
            }

            index = index + 4;
            if (this.Attenuation < 0)
            {
                return(this.Attenuate(sample));
            }
            else
            {
                return(sample);
            }
        }
Example #2
0
        public StereoSample ProcessSample(StereoSample sample)
        {
            if (!this.Active)
            {
                return(new StereoSample());
            }

            if (this.Releasing)
            {
                this.releaseCounter++;
                return(this.ProcessRelease(sample));
            }
            else
            {
                counter++;

                if (counter < this.Attack)
                {
                    return(this.ProcessAttack(sample));
                }
                else
                {
                    return(sample);
                }
            }


            //else if (counter > (this.Attack + this.Sustain))
            //{
            //    return this.ProcessRelease(sample);
            //}
            //return sample;
        }
Example #3
0
        public StereoSample GetSample()
        {
            StereoSample finalSample = new StereoSample();

            if (Inputs.Count > 0)
            {
                int multiplier = 1;
                if (!this.PassThrough)
                {
                    multiplier = 65536 / Inputs.Count;
                }
                else
                {
                    multiplier = 65536;
                }

                foreach (ISampleMaker input in Inputs)
                {
                    StereoSample sample = input.GetSample();
                    finalSample.LeftSample  += (short)((multiplier * sample.LeftSample) >> 16);
                    finalSample.RightSample += (short)((multiplier * sample.RightSample) >> 16);
                    finalSample              = this.Attenuate(finalSample);
                }
            }

            return(finalSample);
        }
Example #4
0
        public StereoSample ProcessSample(StereoSample sample)
        {
            if (!this.Enabled || this.Length == 0)
            {
                return(new StereoSample());
            }

            this.currentAddIndex++;
            if (this.currentAddIndex >= this.length)
            {
                this.currentAddIndex = 0;
                this.full            = true;
            }

            this.samples[currentAddIndex] = sample;

            if (this.full == true)
            {
                int sampleIndex = this.currentAddIndex == this.length - 1 ? 0 : this.currentAddIndex + 1;

                StereoSample delayedSample = samples[sampleIndex];
                delayedSample.LeftSample  = (short)(delayedSample.LeftSample / 3);
                delayedSample.RightSample = (short)(delayedSample.RightSample / 3);
                //StereoSample newSample = new StereoSample();

                //int newLeftSample = sample.LeftSample + delayedSample.LeftSample / 3;
                //int newRightSample = sample.RightSample + delayedSample.RightSample / 3;

                //newSample.LeftSample = (short)newLeftSample;
                //newSample.RightSample = (short)newRightSample;
                return(delayedSample);
            }

            return(sample);
        }
Example #5
0
        public StereoSample GetSample()
        {
            ushort wholePhaseAngle = (ushort)((phaseAngle >> 16));
            short  sample          = this.WaveForm.GetSample(wholePhaseAngle);

            phaseAngle = phaseAngle + phaseAngleIncrement + this.phaseShift;

            StereoSample stereoSample = new StereoSample()
            {
                LeftSample = sample, RightSample = sample
            };

            if (this.Pan > 0)
            {
                //right. decrease left
                //double percent = this.Pan / short.MaxValue / this.Pan;
                double percent = this.Pan / short.MaxValue;
                stereoSample.LeftSample = (short)(stereoSample.LeftSample - (short)((double)stereoSample.LeftSample * percent));
            }
            else if (this.Pan < 0)
            {
                //left. decrease right
                //double percent = short.MinValue / this.Pan;
                double percent = this.Pan / short.MinValue;
                stereoSample.RightSample = (short)(stereoSample.RightSample - (short)((double)stereoSample.RightSample * (percent)));
            }

            this.Bend();
            return(stereoSample);
        }
Example #6
0
        public StereoSample GetSample()
        {
            StereoSample finalSample = new StereoSample();

            if (this.Oscillators.Count > 0)
            {
                int multiplier = 65536 / Oscillators.Count;

                foreach (ISampleMaker input in Oscillators)
                {
                    StereoSample sample = input.GetSample();
                    finalSample.LeftSample  += (short)(((multiplier * sample.LeftSample) >> 16) / this.Oscillators.Count);
                    finalSample.RightSample += (short)(((multiplier * sample.RightSample) >> 16) / this.Oscillators.Count);
                }
                finalSample = this.Envelope.ProcessSample(finalSample);
            }

            if (this.Attenuation < 0)
            {
                return(this.Attenuate(finalSample));
            }
            else
            {
                return(finalSample);
            }
        }
        protected override void GetSampleAsync(MediaStreamType mediaStreamType)
        {
            int numSamples      = 512;
            int bufferByteCount = channelCount * BitsPerSample / 8 * numSamples;

            for (int i = 0; i < numSamples; i++)
            {
                StereoSample stereoSample = this.SampleMaker.GetSample();
                memoryStream.WriteByte((byte)(stereoSample.LeftSample & 0xFF));
                memoryStream.WriteByte((byte)(stereoSample.LeftSample >> 8));
                memoryStream.WriteByte((byte)(stereoSample.RightSample & 0xFF));
                memoryStream.WriteByte((byte)(stereoSample.RightSample >> 8));
            }

            // Send out the next sample
            MediaStreamSample mediaStreamSample =
                new MediaStreamSample(mediaStreamDescription, memoryStream, currentPosition,
                                      bufferByteCount, currentTimeStamp, emptySampleDict);

            // Move timestamp and position forward
            currentTimeStamp += bufferByteCount * 10000000L / byteRate;
            currentPosition  += bufferByteCount;

            ReportGetSampleCompleted(mediaStreamSample);
        }
Example #8
0
        public StereoSample GetSample()
        {
            this.ProcessPreSampleTick();

            if (this.stepChanged)
            {
                this.ProcessCurrentStep();
                this.stepChanged = false;
            }

            StereoSample sample        = new StereoSample();
            StereoSample delayedSample = new StereoSample();

            if (this.voicesInPlay.Count > 0)
            {
                int left  = 0;
                int right = 0;
                try
                {
                    foreach (VoiceNote item in this.voicesInPlay)
                    {
                        StereoSample voiceSample = item.Voice.GetSample();
                        left  += voiceSample.LeftSample;
                        right += voiceSample.RightSample;
                        if (item.Voice is WavPlayer == false)
                        {
                            delayedSample.LeftSample  += voiceSample.LeftSample;
                            delayedSample.RightSample += voiceSample.RightSample;
                        }
                    }
                }
                catch (Exception)
                {
                    // throw;
                }
                sample.LeftSample  = (short)left;
                sample.RightSample = (short)right;
            }

            delayedSample = this.Delay.ProcessSample(delayedSample);

            StereoSample final = new StereoSample()
            {
                LeftSample  = (short)(delayedSample.LeftSample + sample.LeftSample),
                RightSample = (short)(delayedSample.RightSample + sample.RightSample)
            };

            this.ProcessPostSampleTick();

            if (this.Attenuation < 0)
            {
                return(this.Attenuate(final));
            }
            else
            {
                return(final);
            }
        }
Example #9
0
 StereoSample ProcessRelease(StereoSample sample)
 {
     //y = mx + b
     this.Attenuation = (int)((double)this.releaseCounter * this.decaySlope);
     if (this.Attenuation < -50)
     {
         this.Active      = false;
         this.Attenuation = -100;
     }
     return(this.Attenuate(sample));
 }
Example #10
0
 StereoSample ProcessAttack(StereoSample sample)
 {
     //y = mx + b
     this.Attenuation = (int)((double)counter * this.attackSlope) - MinAttenuation;
     return(this.Attenuate(sample));
 }
Example #11
0
 protected StereoSample Attenuate(StereoSample sample)
 {
     sample.LeftSample  = (short)((sample.LeftSample * attenuationMultiplier) >> 16);
     sample.RightSample = (short)((sample.RightSample * attenuationMultiplier) >> 16);
     return(sample);
 }