Exemplo n.º 1
0
        public int Read(byte[] buffer, int offset, int count)
        {
            WaveBuffer waveBuffer  = new WaveBuffer(buffer);
            int        sampleCount = count / 4;

            return(this.Read(waveBuffer.FloatBuffer, offset / 4, sampleCount) * 4);
        }
Exemplo n.º 2
0
        public int Read(byte[] buffer, int offset, int count)
        {
            WaveBuffer waveBuffer  = new WaveBuffer(buffer);
            int        sampleCount = count / 2;

            return(this.Read(waveBuffer.ShortBuffer, offset / 2, sampleCount) * 2);
        }
Exemplo n.º 3
0
        public int Read(byte[] destBuffer, int offset, int numBytes)
        {
            int num = numBytes * 2;

            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, num);
            int        arg_3D_0    = this.sourceProvider.Read(this.sourceBuffer, 0, num);
            WaveBuffer waveBuffer  = new WaveBuffer(this.sourceBuffer);
            WaveBuffer waveBuffer2 = new WaveBuffer(destBuffer);
            int        num2        = arg_3D_0 / 4;
            int        num3        = offset / 2;

            for (int i = 0; i < num2; i++)
            {
                float num4 = waveBuffer.FloatBuffer[i] * this.volume;
                if (num4 > 1f)
                {
                    num4 = 1f;
                }
                if (num4 < -1f)
                {
                    num4 = -1f;
                }
                waveBuffer2.ShortBuffer[num3++] = (short)(num4 * 32767f);
            }
            return(num2 * 2);
        }
Exemplo n.º 4
0
        public int Read(byte[] buffer, int offset, int count)
        {
            int num = count * 2;

            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, num);
            WaveBuffer waveBuffer  = new WaveBuffer(this.sourceBuffer);
            WaveBuffer waveBuffer2 = new WaveBuffer(buffer);
            int        num2        = this.sourceProvider.Read(this.sourceBuffer, 0, num);
            int        num3        = num2 / 2;
            int        num4        = offset / 2;

            for (int i = 0; i < num3; i += 2)
            {
                short num5 = waveBuffer.ShortBuffer[i];
                short num6 = waveBuffer.ShortBuffer[i + 1];
                float num7 = (float)num5 * this.LeftVolume + (float)num6 * this.RightVolume;
                if (num7 > 32767f)
                {
                    num7 = 32767f;
                }
                if (num7 < -32768f)
                {
                    num7 = -32768f;
                }
                waveBuffer2.ShortBuffer[num4++] = (short)num7;
            }
            return(num2 / 2);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads from this wave stream
        /// </summary>
        /// <param name="buffer">Audio buffer</param>
        /// <param name="offset">Offset into buffer</param>
        /// <param name="count">Number of bytes required</param>
        /// <returns>Number of bytes read</returns>
        public override 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);
        }
Exemplo n.º 6
0
        public override int Read(byte[] destBuffer, int offset, int numBytes)
        {
            object obj = this.lockObject;
            int    result;

            lock (obj)
            {
                int        num        = 0;
                WaveBuffer waveBuffer = new WaveBuffer(destBuffer);
                if (this.position < 0L)
                {
                    num = (int)Math.Min((long)numBytes, 0L - this.position);
                    for (int i = 0; i < num; i++)
                    {
                        destBuffer[i + offset] = 0;
                    }
                }
                if (num < numBytes)
                {
                    this.sampleProvider.LoadNextChunk(this.sourceStream, (numBytes - num) / 8);
                    int   num2 = offset / 4 + num / 4;
                    float num3;
                    float num4;
                    while (this.sampleProvider.GetNextSample(out num3, out num4) && num < numBytes)
                    {
                        num3  = ((this.pan <= 0f) ? num3 : (num3 * (1f - this.pan) / 2f));
                        num4  = ((this.pan >= 0f) ? num4 : (num4 * (this.pan + 1f) / 2f));
                        num3 *= this.volume;
                        num4 *= this.volume;
                        waveBuffer.FloatBuffer[num2++] = num3;
                        waveBuffer.FloatBuffer[num2++] = num4;
                        num += 8;
                        if (this.Sample != null)
                        {
                            this.RaiseSample(num3, num4);
                        }
                    }
                }
                if (this.PadWithZeroes && num < numBytes)
                {
                    Array.Clear(destBuffer, offset + num, numBytes - num);
                    num = numBytes;
                }
                this.position += (long)num;
                result         = num;
            }
            return(result);
        }
Exemplo n.º 7
0
        public int Read(byte[] destBuffer, int offset, int numBytes)
        {
            int num = numBytes / 2;

            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, num);
            int        arg_3D_0    = this.sourceProvider.Read(this.sourceBuffer, offset, num);
            WaveBuffer waveBuffer  = new WaveBuffer(this.sourceBuffer);
            WaveBuffer waveBuffer2 = new WaveBuffer(destBuffer);
            int        num2        = arg_3D_0 / 2;
            int        num3        = offset / 4;

            for (int i = 0; i < num2; i++)
            {
                waveBuffer2.FloatBuffer[num3++] = (float)waveBuffer.ShortBuffer[i] / 32768f * this.volume;
            }
            return(num2 * 4);
        }
Exemplo n.º 8
0
        public int Read(byte[] buffer, int offset, int count)
        {
            int num = count / 2;

            this.sourceBuffer = BufferHelpers.Ensure(this.sourceBuffer, num);
            WaveBuffer waveBuffer  = new WaveBuffer(this.sourceBuffer);
            WaveBuffer waveBuffer2 = new WaveBuffer(buffer);
            int        num2        = this.sourceProvider.Read(this.sourceBuffer, 0, num) / 2;
            int        num3        = offset / 2;

            for (int i = 0; i < num2; i++)
            {
                short num4 = waveBuffer.ShortBuffer[i];
                waveBuffer2.ShortBuffer[num3++] = (short)(this.LeftVolume * (float)num4);
                waveBuffer2.ShortBuffer[num3++] = (short)(this.RightVolume * (float)num4);
            }
            return(num2 * 4);
        }