Esempio n. 1
0
        /// <summary>
        /// Combines files into one in the order they are passed in..
        /// </summary>
        /// <param name="bufferMultiplier">The multiplier to use against the OptimalBufferSize of the file for the read buffer, sometimes a larger than optimal buffer size is better.</param>
        /// <param name="inputStreams">The streams to combine</param>
        /// <param name="outputStream">The stream to save the combined file to.</param>
        public static void Combine(Stream outputStream, int bufferMultiplier, params Stream[] inputStreams)
        {
            if (inputStreams.Length <= 0)
            {
                return;
            }

            var wmaInput = inputStreams[0] is WmaStreamReader
                ? (WmaStreamReader)inputStreams[0]
                : new WmaStreamReader(inputStreams[0]);

            var wmaOutput = new WmaWriter(outputStream,
                                          wmaInput.Format,
                                          wmaInput.Profile);

            var buffer = new byte[wmaOutput.OptimalBufferSize * bufferMultiplier];

            try
            {
                WriteFile(wmaOutput, wmaInput, buffer);
                for (var i = 1; i < inputStreams.Length; i++)
                {
                    wmaInput = inputStreams[i] is WmaStreamReader
                        ? (WmaStreamReader)inputStreams[i]
                        : new WmaStreamReader(inputStreams[i]);
                    WriteFile(wmaOutput, wmaInput, buffer);
                }
            }
            finally
            {
                wmaOutput.Close();
            }
        }
Esempio n. 2
0
        public Stream GetEncodedStream()
        {
            var encodedStream = new MemoryStream();
            var writer        = new WmaWriter(encodedStream, Format, Profile);

            Seek(0, SeekOrigin.Begin);

            var buffer = new byte[writer.OptimalBufferSize * 50];

            int read;

            while (Position < Length && (read = Read(buffer, 0, buffer.Length)) > 0)
            {
                writer.Write(buffer, 0, read);
            }

            writer.Close();

            return(encodedStream);
        }
Esempio n. 3
0
        /// <summary>
        /// Cuts out a smaller portion of a Wma file.
        /// </summary>
        /// <param name="inputStream">The input stream.</param>
        /// <param name="outputStream">The stream to write the split portion to.</param>
        /// <param name="startTime">The time that the split from the source stream should start.</param>
        /// <param name="endTime">The time that the split from the source stream should end.</param>
        /// <param name="bufferMultiplier">The multiplier to use against the OptimalBufferSize of the file for the read buffer, sometimes a larger than optimal buffer size is better.</param>
        public static void Split(Stream inputStream, Stream outputStream, TimeSpan startTime, TimeSpan endTime, int bufferMultiplier)
        {
            var wmaInput     = inputStream is WmaStreamReader ? (WmaStreamReader)inputStream : new WmaStreamReader(inputStream);
            var wmaOutput    = new WmaWriter(outputStream, wmaInput.Format, wmaInput.Profile);
            int bytesPerSec  = wmaInput.Format.nAvgBytesPerSec;
            var stopPosition = (long)(bytesPerSec * endTime.TotalSeconds);
            var buffer       = new byte[wmaOutput.OptimalBufferSize * bufferMultiplier];

            var offset = (long)(bytesPerSec * startTime.TotalSeconds);

            offset = offset - (offset % wmaInput.SeekAlign);

            wmaInput.Seek(offset, SeekOrigin.Begin);
            try
            {
                WriteFile(wmaOutput, wmaInput, buffer, stopPosition);
            }
            finally
            {
                wmaOutput.Close();
            }
        }
Esempio n. 4
0
        public Stream GetEncodedStream()
        {
            var encodedStream = new MemoryStream();
            var writer = new WmaWriter(encodedStream, Format, Profile);

            Seek(0, SeekOrigin.Begin);

            var buffer = new byte[writer.OptimalBufferSize * 50];

            int read;
            while (Position < Length && (read = Read(buffer, 0, buffer.Length)) > 0)
            {
                writer.Write(buffer, 0, read);
            }

            writer.Close();

            return encodedStream;
        }
Esempio n. 5
0
        /// <summary>
        /// Combines files into one in the order they are passed in..
        /// </summary>
        /// <param name="bufferMultiplier">The multiplier to use against the OptimalBufferSize of the file for the read buffer, sometimes a larger than optimal buffer size is better.</param>
        /// <param name="inputStreams">The streams to combine</param>
        /// <param name="outputStream">The stream to save the combined file to.</param>
        public static void Combine(Stream outputStream, int bufferMultiplier, params Stream[] inputStreams)
        {
            if (inputStreams.Length <= 0)
                return;

            var wmaInput = inputStreams[0] is WmaStreamReader
                ? (WmaStreamReader)inputStreams[0]
                : new WmaStreamReader(inputStreams[0]);

            var wmaOutput = new WmaWriter(outputStream,
                                          wmaInput.Format,
                                          wmaInput.Profile);

            var buffer = new byte[wmaOutput.OptimalBufferSize * bufferMultiplier];

            try
            {
                WriteFile(wmaOutput, wmaInput, buffer);
                for (var i = 1; i < inputStreams.Length; i++)
                {
                    wmaInput = inputStreams[i] is WmaStreamReader
                        ? (WmaStreamReader)inputStreams[i]
                        : new WmaStreamReader(inputStreams[i]);
                    WriteFile(wmaOutput, wmaInput, buffer);
                }
            }
            finally
            {
                wmaOutput.Close();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Cuts out a smaller portion of a Wma file.
        /// </summary>
        /// <param name="inputStream">The input stream.</param>
        /// <param name="outputStream">The stream to write the split portion to.</param>
        /// <param name="startTime">The time that the split from the source stream should start.</param>
        /// <param name="endTime">The time that the split from the source stream should end.</param>
        /// <param name="bufferMultiplier">The multiplier to use against the OptimalBufferSize of the file for the read buffer, sometimes a larger than optimal buffer size is better.</param>
        public static void Split(Stream inputStream, Stream outputStream, TimeSpan startTime, TimeSpan endTime, int bufferMultiplier)
        {
            var wmaInput = inputStream is WmaStreamReader ? (WmaStreamReader) inputStream : new WmaStreamReader(inputStream);
            var wmaOutput = new WmaWriter(outputStream, wmaInput.Format, wmaInput.Profile);
            int bytesPerSec = wmaInput.Format.nAvgBytesPerSec;
            var stopPosition = (long)(bytesPerSec*endTime.TotalSeconds);
            var buffer = new byte[wmaOutput.OptimalBufferSize * bufferMultiplier];

            var offset = (long) (bytesPerSec * startTime.TotalSeconds);
            offset = offset - (offset % wmaInput.SeekAlign);

            wmaInput.Seek(offset, SeekOrigin.Begin);
            try
            {
                WriteFile(wmaOutput, wmaInput, buffer, stopPosition);
            }
            finally
            {
                wmaOutput.Close();
            }
        }