Ejemplo n.º 1
0
		/// <summary>
		/// Implements the Read method of IWaveProvider by delegating to the abstract
		/// Read method taking a short array
		/// </summary>
		public int Read(byte[] buffer, int offset, int count)
		{
			var waveBuffer = new WaveBuffer(buffer);
			int samplesRequired = count/2;
			int samplesRead = Read(waveBuffer.ShortBuffer, offset/2, samplesRequired);
			return samplesRead*2;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Implements the Read method of IWaveProvider by delegating to the abstract
		/// Read method taking a float array
		/// </summary>
		public int Read(byte[] buffer, int offset, int count)
		{
			var waveBuffer = new WaveBuffer(buffer);
			int samplesRequired = count/4;
			int samplesRead = Read(waveBuffer.FloatBuffer, offset/4, samplesRequired);
			return samplesRead*4;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Reads bytes from this wave stream
		/// </summary>
		/// <param name="destBuffer">The destination buffer</param>
		/// <param name="offset">Offset into the destination buffer</param>
		/// <param name="numBytes">Number of bytes read</param>
		/// <returns>Number of bytes read.</returns>
		public int Read(byte[] destBuffer, int offset, int numBytes)
		{
			int sourceBytesRequired = numBytes/2;
			byte[] sourceBuffer = GetSourceBuffer(sourceBytesRequired);
			int sourceBytesRead = sourceProvider.Read(sourceBuffer, offset, sourceBytesRequired);
			var sourceWaveBuffer = new WaveBuffer(sourceBuffer);
			var destWaveBuffer = new WaveBuffer(destBuffer);

			int sourceSamples = sourceBytesRead/2;
			int destOffset = offset/4;
			for (int sample = 0; sample < sourceSamples; sample++)
			{
				destWaveBuffer.FloatBuffer[destOffset++] = (sourceWaveBuffer.ShortBuffer[sample]/32768f)*volume;
			}

			return sourceSamples*4;
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Reads bytes from this WaveProvider
		/// </summary>
		public int Read(byte[] buffer, int offset, int count)
		{
			int sourceBytesRequired = count/2;
			EnsureBuffer(sourceBytesRequired);
			var sourceWaveBuffer = new WaveBuffer(sourceBuffer);
			var destWaveBuffer = new WaveBuffer(buffer);

			int sourceBytesRead = sourceProvider.Read(sourceBuffer, 0, sourceBytesRequired);
			int samplesRead = sourceBytesRead/2;
			int destOffset = offset/2;
			for (int sample = 0; sample < samplesRead; sample++)
			{
				short sampleVal = sourceWaveBuffer.ShortBuffer[sample];
				destWaveBuffer.ShortBuffer[destOffset++] = (short) (LeftVolume*sampleVal);
				destWaveBuffer.ShortBuffer[destOffset++] = (short) (RightVolume*sampleVal);
			}
			return samplesRead*4;
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Reads bytes from this WaveProvider
		/// </summary>
		public int Read(byte[] buffer, int offset, int count)
		{
			int sourceBytesRequired = count*2;
			EnsureBuffer(sourceBytesRequired);
			var sourceWaveBuffer = new WaveBuffer(sourceBuffer);
			var destWaveBuffer = new WaveBuffer(buffer);

			int sourceBytesRead = sourceProvider.Read(sourceBuffer, 0, sourceBytesRequired);
			int samplesRead = sourceBytesRead/2;
			int destOffset = offset/2;
			for (int sample = 0; sample < samplesRead; sample += 2)
			{
				short left = sourceWaveBuffer.ShortBuffer[sample];
				short right = sourceWaveBuffer.ShortBuffer[sample + 1];
				float outSample = (left*LeftVolume) + (right*RightVolume);
				// hard limiting
				if (outSample > Int16.MaxValue) outSample = Int16.MaxValue;
				if (outSample < Int16.MinValue) outSample = Int16.MinValue;

				destWaveBuffer.ShortBuffer[destOffset++] = (short) outSample;
			}
			return sourceBytesRead/2;
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Reads bytes from this wave stream
		/// </summary>
		/// <param name="destBuffer">The destination buffer</param>
		/// <param name="offset">Offset into the destination buffer</param>
		/// <param name="numBytes">Number of bytes read</param>
		/// <returns>Number of bytes read.</returns>
		public int Read(byte[] destBuffer, int offset, int numBytes)
		{
			int sourceBytesRequired = numBytes*2;
			byte[] sourceBuffer = GetSourceBuffer(sourceBytesRequired);
			int sourceBytesRead = sourceProvider.Read(sourceBuffer, offset, sourceBytesRequired);
			var sourceWaveBuffer = new WaveBuffer(sourceBuffer);
			var destWaveBuffer = new WaveBuffer(destBuffer);

			int sourceSamples = sourceBytesRead/4;
			int destOffset = offset/2;
			for (int sample = 0; sample < sourceSamples; sample++)
			{
				// adjust volume
				float sample32 = sourceWaveBuffer.FloatBuffer[sample]*volume;
				// clip
				if (sample32 > 1.0f)
					sample32 = 1.0f;
				if (sample32 < -1.0f)
					sample32 = -1.0f;
				destWaveBuffer.ShortBuffer[destOffset++] = (short) (sample32*32767);
			}

			return sourceSamples*2;
		}