Пример #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();
            }
        }
Пример #2
0
        private static void WriteFile(WmaWriter wmaOutput, WmaStreamReader wmaInput, byte[] buffer, long stopPosition)
        {
            if (stopPosition == -1)
            {
                stopPosition = wmaInput.Length + 1;
            }
            int read;

            //Read the file until we hit our stop position, or the end of the file.
            while (wmaInput.Position < stopPosition && (read = wmaInput.Read(buffer, 0, buffer.Length)) > 0)
            {
                wmaOutput.Write(buffer, 0, read);
            }
        }
Пример #3
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);
        }
Пример #4
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();
            }
        }
Пример #5
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;
        }
Пример #6
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();
            }
        }
Пример #7
0
 private static void WriteFile(WmaWriter wmaOutput, WmaStreamReader wmaInput, byte[] buffer, long stopPosition)
 {
     if (stopPosition == -1)
     {
         stopPosition = wmaInput.Length + 1;
     }
     int read;
     //Read the file until we hit our stop position, or the end of the file.
     while (wmaInput.Position < stopPosition && (read = wmaInput.Read(buffer, 0, buffer.Length)) > 0)
     {
         wmaOutput.Write(buffer, 0, read);
     }
 }
Пример #8
0
 private static void WriteFile(WmaWriter wmaOutput, WmaStreamReader wmaInput, byte[] buffer)
 {
     WriteFile(wmaOutput, wmaInput, buffer, -1);
 }
Пример #9
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();
            }
        }
Пример #10
0
 public static void WmaToWma(
     string wmafilePath, Stream outputStream, WmaWriterConfig wmaFormat, int bufferMultiplier)
 {
     using (var wmaStream = new WmaStreamReader(wmafilePath))
     {
         var writer = new WmaWriter(outputStream, wmaFormat);
         var buffer = new byte[writer.OptimalBufferSize*bufferMultiplier];
         WriteToStream(writer, wmaStream, buffer);
     }
 }
Пример #11
0
 private static void WriteFile(WmaWriter wmaOutput, WmaStreamReader wmaInput, byte[] buffer)
 {
     WriteFile(wmaOutput, wmaInput, buffer, -1);
 }