예제 #1
0
        public override int Read(float[] data, int offset, int count)
        {
            int remainingSamples = count;

            while (remainingSamples > 0)
            {
                if (CurrentClipIndex >= streams.Count)
                {
                    //Hit the end
                    break;
                }

                IBGCEnvelopeStream stream = streams[CurrentClipIndex];

                int readSamples = stream.Read(data, offset, remainingSamples);

                remainingSamples -= readSamples;
                offset           += readSamples;
                Position         += readSamples;

                if (readSamples <= 0)
                {
                    CurrentClipIndex++;

                    if (CurrentClipIndex < streams.Count)
                    {
                        //Reset on advancing allows a concatenator to hold multiple
                        //copies of the same clip
                        streams[CurrentClipIndex].Reset();
                    }
                }
            }

            return(count - remainingSamples);
        }
예제 #2
0
        public override void Seek(int position)
        {
            Position         = position;
            CurrentClipIndex = streams.Count;

            for (int i = 0; i < streams.Count; i++)
            {
                IBGCEnvelopeStream clip = streams[i];
                if (position > 0)
                {
                    //Seek
                    if (position > clip.Samples)
                    {
                        clip.Seek(clip.Samples);
                        position -= clip.Samples;
                    }
                    else
                    {
                        clip.Seek(position);
                        position         = 0;
                        CurrentClipIndex = i;
                    }
                }
                else
                {
                    clip.Reset();
                }
            }
        }
예제 #3
0
        public override float ReadNextSample()
        {
            float value = 0f;

            while (CurrentClipIndex < streams.Count)
            {
                IBGCEnvelopeStream stream = streams[CurrentClipIndex];

                if (!stream.HasMoreSamples())
                {
                    CurrentClipIndex++;
                    if (CurrentClipIndex < streams.Count)
                    {
                        //Reset on advancing allows a concatenator to hold multiple
                        //copies of the same clip
                        streams[CurrentClipIndex].Reset();
                    }
                    continue;
                }

                value = stream.ReadNextSample();
                Position++;
                break;
            }

            //Hit the end
            return(value);
        }
예제 #4
0
        public ContinuousFilter(
            IBGCStream stream,
            IBGCEnvelopeStream filterEnvelope,
            FilterType filterType,
            double freqLB,
            double freqUB,
            double qFactor = double.NaN)
            : base(stream)
        {
            UnityEngine.Debug.Assert(stream.Channels == 1);

            this.filterType = filterType;

            if (double.IsNaN(qFactor))
            {
                Q = Math.Sqrt(0.5);
            }
            else
            {
                Q = qFactor;
            }

            this.filterEnvelope = filterEnvelope;

            this.freqLB = freqLB;
            this.freqUB = freqUB;
            freqMid     = Math.PI * (this.freqUB + this.freqLB) / (2.0 * stream.SamplingRate);
            freqFactor  = Math.PI * (this.freqUB - this.freqLB) / (2.0 * stream.SamplingRate);
        }
예제 #5
0
        public StreamEnveloper(
            IBGCStream stream,
            IBGCEnvelopeStream envelopeStream,
            bool recalculateRMS = false)
            : base(stream)
        {
            this.recalculateRMS = recalculateRMS;
            this.envelopeStream = envelopeStream;

            ChannelSamples = Math.Min(envelopeStream.Samples, stream.ChannelSamples);
        }
예제 #6
0
 public static IBGCStream ContinuousFilter(
     this IBGCStream stream,
     IBGCEnvelopeStream envelopeStream,
     ContinuousFilter.FilterType filterType,
     double freqLB,
     double freqUB,
     double qFactor = double.NaN)
 {
     return(new ContinuousFilter(
                stream: stream,
                filterEnvelope: envelopeStream,
                filterType: filterType,
                freqLB: freqLB,
                freqUB: freqUB,
                qFactor: qFactor));
 }
예제 #7
0
 public static IBGCStream ContinuousFilter(
     this IBGCStream stream,
     IBGCEnvelopeStream envelopeStream,
     ContinuousFilter.FilterType filterType,
     double freqLB,
     double freqUB,
     double qFactor = double.NaN,
     TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Recalculate)
 {
     return(new ContinuousFilter(
                stream: stream,
                filterEnvelope: envelopeStream,
                filterType: filterType,
                freqLB: freqLB,
                freqUB: freqUB,
                qFactor: qFactor,
                rmsBehavior: rmsBehavior));
 }
        public StreamEnveloper(
            IBGCStream stream,
            IBGCEnvelopeStream envelopeStream,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough)
            : base(stream)
        {
            this.rmsBehavior    = rmsBehavior;
            this.envelopeStream = envelopeStream;

            ChannelSamples = Math.Min(envelopeStream.Samples, stream.ChannelSamples);

            if (ChannelSamples == int.MaxValue)
            {
                TotalSamples = int.MaxValue;
            }
            else
            {
                TotalSamples = Channels * ChannelSamples;
            }
        }
        public ContinuousFilter(
            IBGCStream stream,
            IBGCEnvelopeStream filterEnvelope,
            FilterType filterType,
            double freqLB,
            double freqUB,
            double qFactor = double.NaN,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Recalculate)
            : base(stream)
        {
            if (stream.Channels != 1)
            {
                throw new StreamCompositionException(
                          $"ContinuousFilter expects a mono stream. " +
                          $"Received a stream with {stream.Channels} channels,");
            }

            this.filterType = filterType;

            if (double.IsNaN(qFactor))
            {
                Q = Math.Sqrt(0.5);
            }
            else
            {
                Q = qFactor;
            }

            this.filterEnvelope = filterEnvelope;

            this.freqLB = freqLB;
            this.freqUB = freqUB;
            freqMid     = Math.PI * (this.freqUB + this.freqLB) / (2.0 * stream.SamplingRate);
            freqFactor  = Math.PI * (this.freqUB - this.freqLB) / (2.0 * stream.SamplingRate);

            this.rmsBehavior = rmsBehavior;
        }
예제 #10
0
 public void AddStream(IBGCEnvelopeStream stream)
 {
     streams.Add(stream);
     UpdateStats();
 }