Inheritance: IDisposable
Exemplo n.º 1
0
        public async static Task AudioFileToTipToiAudioFile(CancellationToken cancellationToken, string sourceFile, string oggDestinationFile)
        {
            using (new LogScope(log, "Convert {0} to {1}", sourceFile, oggDestinationFile))
            {
                using (var t = new FileTransaction(oggDestinationFile))
                {
                    var ext = Path.GetExtension(sourceFile).ToLowerInvariant();
                    var wavFile = oggDestinationFile + ".wav";
                    try
                    {
                        switch (ext)
                        {
                            case mp3Extension:
                                {
                                    await SubProcess.CheckedCall(cancellationToken
                                        , "mpg123.exe",
                                        "-w", wavFile.Quote(),
                                        sourceFile.Quote());

                                    bool isMono = true;

                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        wavFile.Quote(),
                                        ("--output=" + t.TempPath).Quote(),
                                        "--resample", "22500",
                                        "--quiet",
                                        isMono ? null : "--downmix"
                                        );
                                }
                                break;
                            case oggExtension:
                                {
                                    bool isMono = GetIsMonoFromOggdecOutput(await SubProcess.GetOutput(cancellationToken
                                        , "oggdec.exe",
                                        "--wavout", wavFile.Quote(),
                                        "-q",
                                        sourceFile.Quote()));

                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        wavFile.Quote(),
                                        ("--output=" + t.TempPath).Quote(),
                                        "--resample", "22500",
                                        "--quiet",
                                        isMono ? null : "--downmix"
                                        );
                                }
                                break;
                            case wavExtension:
                                {
                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        sourceFile.Quote(),
                                        "-o", t.TempPath.Quote(),
                                        "--quiet",
                                        "--resample", "22500",
                                        "--downmix");
                                }
                                break;
                            default:
                                throw new ArgumentOutOfRangeException("sourceFile", sourceFile, "File type is not supported.");
                        }
                    }
                    finally
                    {
                        PathUtil.EnsureFileNotExists(wavFile);
                    }

                    t.Commit();
                }
            }
        }
Exemplo n.º 2
0
        public async static Task AudioFileToTipToiAudioFile(CancellationToken cancellationToken, string sourceFile, string oggDestinationFile)
        {
            using (new LogScope(log, "Convert {0} to {1}", sourceFile, oggDestinationFile))
            {
                using (var t = new FileTransaction(oggDestinationFile))
                {
                    var ext     = Path.GetExtension(sourceFile).ToLowerInvariant();
                    var wavFile = oggDestinationFile + ".wav";
                    try
                    {
                        switch (ext)
                        {
                        case mp3Extension:
                        {
                            await SubProcess.CheckedCall(cancellationToken
                                                         , "mpg123.exe",
                                                         "-w", wavFile.Quote(),
                                                         sourceFile.Quote());

                            bool isMono = true;

                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         wavFile.Quote(),
                                                         ("--output=" + t.TempPath).Quote(),
                                                         "--resample", "22500",
                                                         "--quiet",
                                                         isMono?null : "--downmix"
                                                         );
                        }
                        break;

                        case oggExtension:
                        {
                            bool isMono = GetIsMonoFromOggdecOutput(await SubProcess.GetOutput(cancellationToken
                                                                                               , "oggdec.exe",
                                                                                               "--wavout", wavFile.Quote(),
                                                                                               "-q",
                                                                                               sourceFile.Quote()));

                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         wavFile.Quote(),
                                                         ("--output=" + t.TempPath).Quote(),
                                                         "--resample", "22500",
                                                         "--quiet",
                                                         isMono?null : "--downmix"
                                                         );
                        }
                        break;

                        case wavExtension:
                        {
                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         sourceFile.Quote(),
                                                         "-o", t.TempPath.Quote(),
                                                         "--quiet",
                                                         "--resample", "22500",
                                                         "--downmix");
                        }
                        break;

                        default:
                            throw new ArgumentOutOfRangeException("sourceFile", sourceFile, "File type is not supported.");
                        }
                    }
                    finally
                    {
                        PathUtil.EnsureFileNotExists(wavFile);
                    }

                    t.Commit();
                }
            }
        }