Пример #1
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);
            }
        }