示例#1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorkerArgs a = e.Argument as BackgroundWorkerArgs;
            var bpsConv            = new BpsConv();

            try {
                using (BinaryReader br = new BinaryReader(File.Open(a.readFileName, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                    if (!bpsConv.ReadFromFile(br))
                    {
                        e.Result = rm.GetString("ConvFailedByWrongFormat");
                        return;
                    }
                }

                for (int i = bpsConv.BitsPerSample - 1; 1 <= i; --i)
                {
                    var cp = new BpsConv.ConvertParams();
                    cp.ditherType = BpsConv.ConvertParams.DitherType.Truncate;

                    if (radioButtonDither.Checked)
                    {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.RpdfDither;
                    }
                    if (radioButtonNoiseShaping.Checked)
                    {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShaping;
                    }
                    if (radioButtonGaussianDither.Checked)
                    {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.GaussianDither;
                    }
                    if (radioButton2ndOrderNS.Checked)
                    {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShaping2;
                    }
                    if (radioButtonMash2.Checked)
                    {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShapingMash2;
                    }
                    cp.newQuantizationBitrate = i;

                    var writeFileName = ReadFileNameToWriteFileName(mReadFileName, cp);

                    backgroundWorker1.ReportProgress(i, cp);
                    using (BinaryWriter bw = new BinaryWriter(File.Open(writeFileName, FileMode.CreateNew))) {
                        bpsConv.Convert(cp, bw);
                    }
                }
            } catch (Exception ex) {
                e.Result = rm.GetString("ConvFailedByException") + "\r\n\r\n" + string.Format(CultureInfo.InvariantCulture, "{0}", ex);
                return;
            }
            e.Result = null;
        }
示例#2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorkerArgs a    = e.Argument as BackgroundWorkerArgs;
            var bpsConv = new BpsConv();

            try {
                using (BinaryReader br = new BinaryReader(File.Open(a.readFileName, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                        if (!bpsConv.ReadFromFile(br)) {
                            e.Result = rm.GetString("ConvFailedByWrongFormat");
                            return;
                        }
                }

                for (int i=bpsConv.BitsPerSample-1; 1 <= i; --i) {
                    var cp = new BpsConv.ConvertParams();
                    cp.ditherType = BpsConv.ConvertParams.DitherType.Truncate;

                    if (radioButtonDither.Checked) {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.RpdfDither;
                    }
                    if (radioButtonNoiseShaping.Checked) {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShaping;
                    }
                    if (radioButtonGaussianDither.Checked) {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.GaussianDither;
                    }
                    if (radioButton2ndOrderNS.Checked) {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShaping2;
                    }
                    if (radioButtonMash2.Checked) {
                        cp.ditherType = BpsConv.ConvertParams.DitherType.NoiseShapingMash2;
                    }
                    cp.newQuantizationBitrate = i;

                    var writeFileName = ReadFileNameToWriteFileName(mReadFileName, cp);

                    backgroundWorker1.ReportProgress(i, cp);
                    using (BinaryWriter bw = new BinaryWriter(File.Open(writeFileName, FileMode.CreateNew))) {
                        bpsConv.Convert(cp, bw);
                    }
                }
            } catch (Exception ex) {
                e.Result = rm.GetString("ConvFailedByException") + "\r\n\r\n" + string.Format(CultureInfo.InvariantCulture, "{0}", ex);
                return;
            }
            e.Result = null;
        }
示例#3
0
 private static string DitherTypeToString(BpsConv.ConvertParams.DitherType dt)
 {
     switch (dt) {
     case BpsConv.ConvertParams.DitherType.Truncate:
         return "";
     case BpsConv.ConvertParams.DitherType.RpdfDither:
         return "_Dither";
     case BpsConv.ConvertParams.DitherType.NoiseShaping:
         return "_NS";
     case BpsConv.ConvertParams.DitherType.GaussianDither:
         return "_Gaussian";
     case BpsConv.ConvertParams.DitherType.NoiseShaping2:
         return "_NS2";
     case BpsConv.ConvertParams.DitherType.NoiseShapingMash2:
         return "_MASH2";
     default:
         System.Diagnostics.Debug.Assert(false);
         return "";
     }
 }
示例#4
0
 private static string ReadFileNameToWriteFileName(string readFileName, BpsConv.ConvertParams a)
 {
     return string.Format(CultureInfo.InvariantCulture, "{0}{1}_{2}.wav",
         readFileName, DitherTypeToString(a.ditherType),
         a.newQuantizationBitrate);
 }