public void ReadFromEmptyBufferReturnsNothing() { CircularBuffer circularBuffer = new CircularBuffer(1024); byte[] buffer = new byte[1024]; int read = circularBuffer.Read(buffer, 0, 1024); Assert.AreEqual(0, read); }
public void RejectsWhenExactlyFull() { CircularBuffer circularBuffer = new CircularBuffer(100); byte[] buffer = new byte[200]; circularBuffer.Write(buffer, 0, 100); int written = circularBuffer.Write(buffer, 0, 50); Assert.AreEqual(0, written, "Wrote the wrong amount"); }
public void RejectsTooMuchData() { CircularBuffer circularBuffer = new CircularBuffer(100); byte[] buffer = new byte[200]; int written = circularBuffer.Write(buffer, 0, 200); Assert.AreEqual(100, written, "Wrote the wrong amount"); }
public void CanWriteToBuffer() { CircularBuffer circularBuffer = new CircularBuffer(1024); byte[] buffer = new byte[100]; circularBuffer.Write(buffer, 0, 100); Assert.AreEqual(100, circularBuffer.Count); circularBuffer.Write(buffer, 0, 50); Assert.AreEqual(150, circularBuffer.Count); }
public PdProvider(Player player) { _buffer = new float[player.BufferSize]; _player = player; _player.BufferReady += PdBufferReady; _circularBuffer = new CircularBuffer(_player.SampleRate * 5); // 5 seconds should be enough for anybody _minBuffer = _player.SampleRate / 2; // 0.5 second RefillBuffer(); }
public void BufferReturnsAsMuchAsIsAvailable() { CircularBuffer circularBuffer = new CircularBuffer(1024); byte[] buffer = new byte[100]; circularBuffer.Write(buffer, 0, 100); Assert.AreEqual(100, circularBuffer.Count); byte[] readBuffer = new byte[1000]; int read = circularBuffer.Read(readBuffer, 0, 1000); Assert.AreEqual(100, read); }
public SynthWaveProvider(Synthesizer synth, MidiFileSequencer mseq) { this.synth = synth; this.mseq = mseq; waveFormat = new WaveFormat(synth.SampleRate, 16, synth.AudioChannels); int bufferSize = (int)Math.Ceiling((2.0 * waveFormat.AverageBytesPerSecond) / synth.RawBufferSize) * synth.RawBufferSize; circularBuffer = new CircularBuffer(bufferSize); sbuff = new byte[synth.RawBufferSize]; state = PlayerState.Stopped; }
public void RejectsWhenFull() { CircularBuffer circularBuffer = new CircularBuffer(100); byte[] buffer = new byte[200]; circularBuffer.Write(buffer, 0, 75); try { circularBuffer.Write(buffer, 0, 50); Assert.Fail("Should have thrown an argument exception"); } catch (ArgumentException) { // expected exception } }
public void CanWritePastEnd() { CircularBuffer circularBuffer = new CircularBuffer(100); byte[] buffer = new byte[200]; circularBuffer.Write(buffer, 0, 75); Assert.AreEqual(75, circularBuffer.Count, "Initial count"); int read = circularBuffer.Read(buffer, 0, 75); Assert.AreEqual(0, circularBuffer.Count, "Count after read"); Assert.AreEqual(75, read, "Bytes read"); // write wraps round circularBuffer.Write(buffer, 0, 50); Assert.AreEqual(50, circularBuffer.Count, "Count after wrap round"); // read wraps round read = circularBuffer.Read(buffer, 0, 75); Assert.AreEqual(50, read, "Bytes Read 2"); Assert.AreEqual(0, circularBuffer.Count, "Final Count"); }
public void DataIntegrityTest() { byte[] numbers = new byte[256]; byte[] readBuffer = new byte[256]; for (int n = 0; n < 256; n++) { numbers[n] = (byte)n; } CircularBuffer circularBuffer = new CircularBuffer(300); circularBuffer.Write(numbers, 0, 200); Array.Clear(readBuffer, 0, readBuffer.Length); int read = circularBuffer.Read(readBuffer, 0, 200); Assert.AreEqual(200, read); CheckBuffer(readBuffer, 0, read); // now write past the end circularBuffer.Write(numbers, 0, 200); Array.Clear(readBuffer, 0, readBuffer.Length); // now read past the end read = circularBuffer.Read(readBuffer, 0, 200); Assert.AreEqual(200, read); CheckBuffer(readBuffer, 0, read); }
public void CircularBufferHasMaxLengthAndCount() { CircularBuffer circularBuffer = new CircularBuffer(1024); Assert.AreEqual(1024, circularBuffer.MaxLength); Assert.AreEqual(0, circularBuffer.Count); }
/// <summary> /// Sets up CircularBuffer for storage and float[] for getting data from libPd. /// </summary> void SetUpBuffer() { _circularBuffer = new CircularBuffer(BlockSize * Ticks * Channels * 4); // make the circular buffer large enough _minBuffer = BlockSize * Ticks * Channels * 2; }
/// <summary> /// Adds samples. Takes a copy of buffer, so that buffer can be reused if necessary /// </summary> public void AddSamples(byte[] buffer, int offset, int count) { // create buffer here to allow user to customise buffer length if (circularBuffer == null) { circularBuffer = new CircularBuffer(BufferLength); } var written = circularBuffer.Write(buffer, offset, count); if (written < count && !DiscardOnBufferOverflow) { throw new InvalidOperationException("Buffer full"); } }
/// <summary> /// Creates a new BlockAlignReductionStream /// </summary> /// <param name="sourceStream">the input stream</param> public BlockAlignReductionStream(WaveStream sourceStream) { this.sourceStream = sourceStream; circularBuffer = new CircularBuffer(sourceStream.WaveFormat.AverageBytesPerSecond * 4); }