Exemple #1
0
        public void Write(float[] samples, int count)
        {
            if (shortBuffer == null || shortBuffer.Length < count)
            {
                shortBuffer = new short[count];
            }

            if (byteBuffer == null || byteBuffer.Length < count * 2)
            {
                byteBuffer = new byte[count * 2];
            }

            ArrayConverters.FloatToShort(samples, count, shortBuffer);
            ArrayConverters.GetBytes(shortBuffer, count, byteBuffer);

            OnWrite(byteBuffer, count * 2);
        }
Exemple #2
0
        public void Write(byte[] data, int count)
        {
            if (readBuffer == null || readBuffer.Length < count * 10)
            {
                readBuffer = new short[count * 10];
            }

            if (writeBuffer == null || writeBuffer.Length < count * 10)
            {
                writeBuffer = new float[count * 10];
            }

            var samplesDecoded = decoder.Decode(data, 0, count, readBuffer, 0, false);

            if (samplesDecoded > 0)
            {
                ArrayConverters.ShortToFloat(readBuffer, samplesDecoded, writeBuffer);
                decodeCallback(writeBuffer, samplesDecoded);
            }
        }
Exemple #3
0
        private void WriteCore(float[] samples, int count)
        {
            if (shortBuffer == null || shortBuffer.Length < count * 10)
            {
                shortBuffer = new short[count * 10];
            }

            if (byteBuffer == null || byteBuffer.Length < count * 10)
            {
                byteBuffer = new byte[count * 10];
            }

            ArrayConverters.FloatToShort(samples, count, shortBuffer);
            var bytesEncoded = speexEncoder.Encode(shortBuffer, 0, count, byteBuffer, 0, byteBuffer.Length);

            if (encodeOgg)
            {
                oggWriter.WritePacket(byteBuffer, 0, bytesEncoded);
            }
            else
            {
                targetStream.Write(byteBuffer, 0, bytesEncoded);
            }
        }