示例#1
0
        private void Preview_button_Click(object sender, EventArgs e)
        {
            Dettach();

            RunSox();
            if (!File.Exists(this.TempFilename))
            {
                PreviewResult.Text = R._("");
                return;
            }

            long   fromFileSize = U.GetFileSize(this.FromFilename);
            long   tempFileSize;
            string playTempWave;
            string ext = U.GetFilenameExt(this.TempFilename);

            if (ext == ".S")
            {
                byte[] dpcmBin;
                string error = SongUtil.LoadWavS(this.TempFilename, out dpcmBin);
                if (error != "")
                {
                    PreviewResult.Text = error;
                    return;
                }
                tempFileSize = dpcmBin.Length;

                byte[] uncmpWavBin = SongUtil.byteToWavForDPCM(dpcmBin, 0);
                this.TempFilename2 = U.mktemp(".wav");
                File.WriteAllBytes(this.TempFilename2, uncmpWavBin);
                playTempWave = this.TempFilename2;

                double snr = SongUtil.CalculateSNR(this.UncompressWavBIN, uncmpWavBin);
                string str = R._("ファイルサイズ {0} -> {1} ({2}%)\r\n圧縮品質 SNR: {3}dB (高いほど良い。20dB以下は圧縮を使わない方がいいかも。)", fromFileSize, tempFileSize,
                                 Math.Round(tempFileSize * 100 / (double)fromFileSize, 2), Math.Round(snr, 3));
                PreviewResult.Text = str;
            }
            else if (ext == ".DPCM")
            {
                byte[] dpcmBin = File.ReadAllBytes(this.TempFilename);
                tempFileSize = dpcmBin.Length;

                byte[] uncmpWavBin = SongUtil.byteToWavForDPCM(dpcmBin, 0);
                this.TempFilename2 = U.mktemp(".wav");
                File.WriteAllBytes(this.TempFilename2, uncmpWavBin);
                playTempWave = this.TempFilename2;

                double snr = SongUtil.CalculateSNR(this.UncompressWavBIN, uncmpWavBin);
                string str = R._("ファイルサイズ {0} -> {1} ({2}%)\r\n圧縮品質 SNR: {3}dB (高いほど良い。20dB以下は圧縮を使わない方がいいかも。)", fromFileSize, tempFileSize,
                                 Math.Round(tempFileSize * 100 / (double)fromFileSize, 2), Math.Round(snr, 3));
                PreviewResult.Text = str;
            }
            else
            {
                playTempWave = this.TempFilename;
                tempFileSize = U.GetFileSize(this.TempFilename);

                string str = R._("ファイルサイズ {0} -> {1} ({2}%)", fromFileSize, tempFileSize,
                                 Math.Round(tempFileSize * 100 / (double)fromFileSize, 2));
                PreviewResult.Text = str;
            }


            this.WavePlayer = new System.Media.SoundPlayer(playTempWave);
            this.WavePlayer.Play();
        }