Esempio n. 1
0
        static void Run(string input, string text)
        {
            ConsoleProgress.Reset();

            bool isInputFlac = Path.GetExtension(input).ToUpperInvariant() == ".FLAC";

            if (isInputFlac)
            {
                // FLAC -> WAV
                string inputFile  = Path.Combine("flac", input);
                string outputFile = Path.Combine("wav", Path.ChangeExtension(input, ".wav"));

                if (!File.Exists(inputFile))
                {
                    throw new ApplicationException("Input file " + inputFile + " cannot be found!");
                }

                using (WavWriter wav = new WavWriter(outputFile))
                    using (FlacReader flac = new FlacReader(inputFile, wav))
                        flac.Process();
            }
            else
            {
                // WAV -> FLAC
                string inputFile  = Path.Combine("wav", input);
                string outputFile = Path.Combine("flac", Path.ChangeExtension(input, ".flac"));

                if (!File.Exists(inputFile))
                {
                    throw new ApplicationException("Input file " + inputFile + " cannot be found!");
                }

                using (WavReader wav = new WavReader(inputFile))
                {
                    using (FlacWriter flac = new FlacWriter(File.Create(outputFile), wav.BitDepth, wav.Channels, wav.SampleRate))
                    {
                        // Buffer for 1 second's worth of audio data
                        byte[] buffer = new byte[1 * wav.Bitrate / 8];
                        int    bytesRead;

                        do
                        {
                            ConsoleProgress.Update(wav.InputStream.Position, wav.InputStream.Length);

                            bytesRead = wav.InputStream.Read(buffer, 0, buffer.Length);
                            flac.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);

                        // Finished!
                    }
                }
            }
        }
Esempio n. 2
0
        static void Run(string input, string text)
        {
            ConsoleProgress.Reset();

            bool isInputFlac = Path.GetExtension(input).ToUpperInvariant() == ".FLAC";

            if (isInputFlac)
            {
                // FLAC -> WAV
                string inputFile = Path.Combine("flac", input);
                string outputFile = Path.Combine("wav", Path.ChangeExtension(input, ".wav"));

                if (!File.Exists(inputFile))
                    throw new ApplicationException("Input file " + inputFile + " cannot be found!");

                using (WavWriter wav = new WavWriter(outputFile))
                using (FlacReader flac = new FlacReader(inputFile, wav))
                    flac.Process();
            }
            else
            {
                // WAV -> FLAC
                string inputFile = Path.Combine("wav", input);
                string outputFile = Path.Combine("flac", Path.ChangeExtension(input, ".flac"));

                if (!File.Exists(inputFile))
                    throw new ApplicationException("Input file " + inputFile + " cannot be found!");

                using (WavReader wav = new WavReader(inputFile))
                {
                    using (FlacWriter flac = new FlacWriter(File.Create(outputFile), wav.BitDepth, wav.Channels, wav.SampleRate))
                    {
                        // Buffer for 1 second's worth of audio data
                        byte[] buffer = new byte[1 * wav.Bitrate / 8];
                        int bytesRead;

                        do
                        {
                            ConsoleProgress.Update(wav.InputStream.Position, wav.InputStream.Length);

                            bytesRead = wav.InputStream.Read(buffer, 0, buffer.Length);
                            flac.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);

                        // Finished!
                    }
                }
            }
        }