コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="numberOfBytes"></param>
        /// <exception cref="Exception"></exception>
        public void MakeBytesAvailable(int numberOfBytes)
        {
            var bytesToRead = numberOfBytes - _buffer.ConsumeRemaining;

            if (bytesToRead > TempBuffer.Length)
            {
                throw (new Exception(
                           "Can't Peek More Bytes Than BufferSize. " + bytesToRead + " > " + TempBuffer.Length));
            }
            if (bytesToRead > 0)
            {
                _buffer.Produce(TempBuffer, 0, InputStream.Read(TempBuffer, 0, bytesToRead));
            }
        }
コード例 #2
0
        public void ProduceTest()
        {
            var Buffer = new ProduceConsumeBuffer <int>();

            Buffer.Produce(new int[] { 10, 20, -2, 3, 15 });
            Assert.AreEqual(Buffer.IndexOf(-2), 2);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Samples"></param>
        /// <param name="ActionCallbackOnReaded"></param>
        public void Write(short[] Samples, Action ActionCallbackOnReaded)
        {
            short[] StereoSamples;

            switch (Format)
            {
            case Audio.PspAudio.FormatEnum.Mono:
                StereoSamples = MonoToStereo(Samples);
                break;

            default:
            case Audio.PspAudio.FormatEnum.Stereo:
                StereoSamples = Samples;
                break;
            }

            lock (this)
            {
                if (Buffer.ConsumeRemaining < FillSamples)
                {
                    ActionCallbackOnReaded();
                }
                else
                {
                    BufferEvents.Add(new Tuple <long, Action>(Buffer.TotalConsumed + StereoSamples.Length, ActionCallbackOnReaded));
                }
                //Console.WriteLine(Format);
                Buffer.Produce(StereoSamples);
            }
        }
コード例 #4
0
		public void ConsumeTest()
		{
			var Buffer = new ProduceConsumeBuffer<int>();
			Buffer.Produce(new int[] { 10, 20, -2, 3, 15 });
			Assert.AreEqual(Buffer.IndexOf(-2), 2);
			CollectionAssert.AreEqual(Buffer.Consume(2), new int[] { 10, 20 });
			Assert.AreEqual(Buffer.IndexOf(-2), 0);
			CollectionAssert.AreEqual(Buffer.Consume(1), new int[] { -2 });
			Assert.AreEqual(Buffer.IndexOf(-2), -1);
			Buffer.Produce(new int[] { 4, 2 });
			CollectionAssert.AreEqual(Buffer.Items, new int[] { 3, 15, 4, 2 });

			Assert.AreEqual(-1, Buffer.IndexOf(new int[] { 3, 15, 4, 1 }));
			Assert.AreEqual(0, Buffer.IndexOf(new int[] { 3, 15, 4 }));
			Assert.AreEqual(1, Buffer.IndexOf(new int[] { 15, 4 }));
			Assert.AreEqual(2, Buffer.IndexOf(new int[] { 4, 2 }));
		}
コード例 #5
0
        public void ConsumeTest()
        {
            var Buffer = new ProduceConsumeBuffer <int>();

            Buffer.Produce(new int[] { 10, 20, -2, 3, 15 });
            Assert.AreEqual(Buffer.IndexOf(-2), 2);
            CollectionAssert.AreEqual(Buffer.Consume(2), new int[] { 10, 20 });
            Assert.AreEqual(Buffer.IndexOf(-2), 0);
            CollectionAssert.AreEqual(Buffer.Consume(1), new int[] { -2 });
            Assert.AreEqual(Buffer.IndexOf(-2), -1);
            Buffer.Produce(new int[] { 4, 2 });
            CollectionAssert.AreEqual(Buffer.Items, new int[] { 3, 15, 4, 2 });

            Assert.AreEqual(-1, Buffer.IndexOf(new int[] { 3, 15, 4, 1 }));
            Assert.AreEqual(0, Buffer.IndexOf(new int[] { 3, 15, 4 }));
            Assert.AreEqual(1, Buffer.IndexOf(new int[] { 15, 4 }));
            Assert.AreEqual(2, Buffer.IndexOf(new int[] { 4, 2 }));
        }
コード例 #6
0
        async protected Task EnsureDataAsync(int MinimumBytes = 1)
        {
            while (Buffer.ConsumeRemaining < MinimumBytes)
            {
                var Data   = new byte[1024];
                var Readed = await BaseStream.ReadAsync(Data, 0, 1024);

                Buffer.Produce(Data, 0, Readed);
            }
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Samples"></param>
        /// <param name="ActionCallbackOnReaded"></param>
        public void Write(short[] Samples, Action ActionCallbackOnReaded)
        {
            if (Samples == null)
            {
                throw (new InvalidOperationException("short[] Samples is null"));
            }

            short[] StereoSamples;

            switch (Format)
            {
            case Audio.FormatEnum.Mono:
                StereoSamples = MonoToStereo(Samples);
                break;

            default:
            case Audio.FormatEnum.Stereo:
                StereoSamples = Samples;
                break;
            }

            lock (this)
            {
                if (Buffer.ConsumeRemaining < FillSamples)
                {
                    Task.Run(() =>
                    {
                        Thread.Sleep(1);
                        ActionCallbackOnReaded();
                    });
                }
                else
                {
                    BufferEvents.Add(new Tuple <long, Action>(Buffer.TotalConsumed + StereoSamples.Length,
                                                              ActionCallbackOnReaded));
                }
                //Console.WriteLine(Format);
                Buffer.Produce(StereoSamples);
            }
        }
コード例 #8
0
		public void ProduceTest()
		{
			var Buffer = new ProduceConsumeBuffer<int>();
			Buffer.Produce(new int[] { 10, 20, -2, 3, 15});
			Assert.AreEqual(Buffer.IndexOf(-2), 2);
		}