/// <summary>Reads a sequence of samples from the <see cref="T:CSCore.SampleAggregatorBase" /> and advances the position within the stream by /// the number of samples read.</summary> /// <param name="buffer"> /// An array of floats. When this method returns, the <paramref name="buffer" /> contains the specified /// float array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the floats read from the current source. /// </param> /// <param name="offset">The zero-based offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream.</param> /// <param name="count">The maximum number of samples to read from the current source.</param> /// <returns>The total number of samples read into the buffer.</returns> public unsafe override int Read(float[] buffer, int offset, int count) { stereoBuffer = stereoBuffer.CheckBuffer(count * 2); int read = BaseSource.Read(stereoBuffer, 0, count * 2); fixed(float *pbuffer = buffer) { float *ppbuffer = pbuffer + offset; switch (channel) { case ChannelMask.SpeakerFrontLeft: for (int i = 0; i < read - 1; i += 2) { *(ppbuffer++) = stereoBuffer[i]; } break; case ChannelMask.SpeakerFrontRight: for (int i = 0; i < read - 1; i += 2) { *(ppbuffer++) = stereoBuffer[i + 1]; } break; } } return(read / 2); }
/// <summary> /// Reads a sequence of bytes from the stream and applies the Dmo effect to them (only if the <see cref="IsEnabled"/> property is set to true). /// </summary> /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the read bytes.</param> /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the stream.</param> /// <param name="count">The maximum number of bytes to be read from the stream</param> /// <returns>The actual number of read bytes.</returns> public override int Read(byte[] buffer, int offset, int count) { if (IsEnabled) { return(base.Read(buffer, offset, count)); } return(BaseSource.Read(buffer, offset, count)); }
/// <summary> /// Reads a sequence of bytes from the <see cref="BaseSource"/> and advances the position within the stream by the /// number of bytes read. /// </summary> /// <param name="buffer"> /// An array of bytes. When this method returns, the <paramref name="buffer" /> contains the specified /// byte array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the bytes read from the current source. /// </param> /// <param name="offset"> /// The zero-based byte offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream. /// </param> /// <param name="count">The maximum number of bytes to read from the current source.</param> /// <returns>The total number of bytes read into the buffer.</returns> public virtual int Read(byte[] buffer, int offset, int count) { if (offset % WaveFormat.Channels != 0) { offset -= offset % WaveFormat.Channels; } if (count % WaveFormat.Channels != 0) { count -= count % WaveFormat.Channels; } return(BaseSource.Read(buffer, offset, count)); }
/// <summary> /// Reads a sequence of samples from the <see cref="SampleAggregatorBase" /> and advances the position within the stream by /// the number of samples read. /// </summary> /// <param name="buffer"> /// An array of floats. When this method returns, the <paramref name="buffer" /> contains the specified /// float array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the floats read from the current source. /// </param> /// <param name="offset"> /// The zero-based offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream. /// </param> /// <param name="count">The maximum number of samples to read from the current source.</param> /// <returns>The total number of samples read into the buffer.</returns> public virtual int Read(float[] buffer, int offset, int count) { if (offset % WaveFormat.Channels != 0) { throw new ArgumentOutOfRangeException("offset"); } if (count % WaveFormat.Channels != 0) { throw new ArgumentOutOfRangeException("count"); } return(BaseSource.Read(buffer, offset, count)); }
public override int Read(byte[] buffer, int offset, int count) // play BASE, then play append { int read = BaseSource.Read(buffer, offset, count); // want count, stored at offset //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString() + " Copy:Read " + count); if (read < count) { return(append.Read(buffer, read, count - read)); } else { return(read); } }
/// <summary> /// Reads a sequence of samples from the <see cref="StereoToMonoSource" /> and advances the position within the stream by /// the number of samples read. /// </summary> /// <param name="buffer"> /// An array of floats. When this method returns, the <paramref name="buffer" /> contains the specified /// float array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the floats read from the current source. /// </param> /// <param name="offset"> /// The zero-based offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream. /// </param> /// <param name="count">The maximum number of samples to read from the current source.</param> /// <returns>The total number of samples read into the buffer.</returns> public unsafe override int Read(float[] buffer, int offset, int count) { _buffer = _buffer.CheckBuffer(count * 2); int read = BaseSource.Read(_buffer, 0, count * 2); fixed(float *pbuffer = buffer) { float *ppbuffer = pbuffer + offset; for (int i = 0; i < read - 1; i += 2) { *(ppbuffer++) = (_buffer[i] + _buffer[i + 1]) / 2; } } return(read / 2); }
public override int Read(byte[] buffer, int offset, int count) { int read = BaseSource.Read(buffer, offset, count); if (read < count) { int diff = count - read; diff = Math.Min(diff, bytesToExtend); if (diff > 0) { Array.Clear(buffer, offset, diff); } bytesToExtend -= diff; return(diff); } return(read); }
public override int Read(byte[] buffer, int offset, int count) // PLAY base, until exausted, then play fill { int read = BaseSource.Read(buffer, offset, count); // want count, stored at offset //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString() + " Extend " + offset + " Read " + count); if (read < count) { int left = count - read; // what is left int totake = Math.Min(left, (int)extrabytes); //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString() + " ++read " + read + " left " + left + " extend " + totake + " left " + (extrabytes - totake)); if (totake > 0) { Array.Clear(buffer, offset + read, totake); // at offset+read, clear down to zero the extra bytes extrabytes -= totake; } return(read + totake); // returned this total } return(read); }
public override int Read(byte[] buffer, int offset, int count) { int readbase = BaseSource.Read(buffer, offset, count); // want count, stored at offset if (readbase > 0) // mix into data the mix source.. ensure the mix source never runs out. { byte[] buffer2 = new byte[readbase]; int storepos = 0; int left = readbase; while (left > 0) { //System.Diagnostics.Debug.WriteLine("Read mix at " + mix.Position + " for " + left); int readmix = mix.Read(buffer2, storepos, left); // and read in the readmix.. //System.Diagnostics.Debug.WriteLine(".. read " + readmix); left -= readmix; if (left > 0) // if we have any left, means we need to loop it { mix.Position = 0; storepos += readmix; } } if (BaseSource.WaveFormat.BytesPerSample == 2) // FOR NOW, presuming its PCM, cope with a few different formats. { for (int i = 0; i < readbase; i += 2) { short v1 = BitConverter.ToInt16(buffer, i + offset); short v2 = BitConverter.ToInt16(buffer2, i); v1 += v2; var bytes = BitConverter.GetBytes(v1); buffer[i + offset] = bytes[0]; buffer[i + offset + 1] = bytes[1]; } } else if (BaseSource.WaveFormat.BytesPerSample == 4) { for (int i = 0; i < readbase; i += 4) { long v1 = BitConverter.ToInt32(buffer, i + offset); long v2 = BitConverter.ToInt32(buffer2, i); v1 += v2; var bytes = BitConverter.GetBytes(v1); buffer[i + offset] = bytes[0]; buffer[i + offset + 1] = bytes[1]; buffer[i + offset + 2] = bytes[2]; buffer[i + offset + 3] = bytes[3]; } } else { for (int i = 0; i < readbase; i += 1) { buffer[i + offset] += buffer2[i]; } } } return(readbase); }
public override int Read(byte[] buffer, int offset, int count) { int readbase = BaseSource.Read(buffer, offset, count); // want count, stored at offset if (readbase > 0) // mix into data the mix source.. ensure the mix source never runs out. { if (BaseSource.WaveFormat.BytesPerSample == 2) // FOR NOW, presuming its PCM, cope with a few different formats. { //System.Diagnostics.Debug.WriteLine($"@ {(double)sample / WaveFormat.SampleRate}={curamplitude}"); for (int i = 0; i < readbase; i += 2) { short v1 = BitConverter.ToInt16(buffer, i + offset); v1 = (short)(v1 * curamplitude); curamplitude += sample < attackend ? attackramp : sample < decayend ? decayramp : sample < sustainend ? 0 : sample < releaseend ? releaseramp : 0; //if (sample == attackend || sample == decayend || sample == sustainend || sample == releaseend) System.Diagnostics.Debug.WriteLine($"{(double)sample / WaveFormat.SampleRate}={curamplitude}"); curamplitude = Math.Max(-1, Math.Min(1, curamplitude)); var bytes = BitConverter.GetBytes(v1); buffer[i + offset] = bytes[0]; buffer[i + offset + 1] = bytes[1]; sample++; } } else if (BaseSource.WaveFormat.BytesPerSample == 4) { for (int i = 0; i < readbase; i += 4) { long v1 = BitConverter.ToInt32(buffer, i + offset); v1 = (long)(v1 * curamplitude); curamplitude += sample < attackend ? attackramp : sample < decayend ? decayramp : sample < sustainend ? 0 : sample < releaseend ? releaseramp : 0; var bytes = BitConverter.GetBytes(v1); buffer[i + offset] = bytes[0]; buffer[i + offset + 1] = bytes[1]; buffer[i + offset + 2] = bytes[2]; buffer[i + offset + 3] = bytes[3]; sample++; } } else { for (int i = 0; i < readbase; i += 1) { byte v1 = buffer[i]; v1 = (byte)(v1 * curamplitude); curamplitude += sample < attackend ? attackramp : sample < decayend ? decayramp : sample < sustainend ? 0 : sample < releaseend ? releaseramp : 0; buffer[i] = v1; sample++; } } } return(readbase); }
/// <summary> /// Reads a sequence of bytes from the <see cref="BaseSource"/> and advances the position within the stream by the /// number of bytes read. /// </summary> /// <param name="buffer"> /// An array of bytes. When this method returns, the <paramref name="buffer" /> contains the specified /// byte array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the bytes read from the current source. /// </param> /// <param name="offset"> /// The zero-based byte offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream. /// </param> /// <param name="count">The maximum number of bytes to read from the current source.</param> /// <returns>The total number of bytes read into the buffer.</returns> public virtual int Read(byte[] buffer, int offset, int count) { return(BaseSource.Read(buffer, offset, count)); }
public int Read(byte[] buffer, int offset, int count) { return(BaseSource.Read(buffer, 0, count)); }