コード例 #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 ReadFileNameToWriteFileName(string readFileName, BpsConv.ConvertParams a)
 {
     return(string.Format(CultureInfo.InvariantCulture, "{0}{1}_{2}.wav",
                          readFileName, DitherTypeToString(a.ditherType),
                          a.newQuantizationBitrate));
 }