示例#1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            int    startPos      = (int)numericStartPos.Value;
            int    outputSamples = (int)numericOutputSamples.Value;
            string path          = textBoxReadWavFile.Text;


            WavData wavData = new WavData();

            Console.WriteLine(rm.GetString("ReadFileStarted"), path);
            using (BinaryReader br1 = new BinaryReader(File.Open(path, FileMode.Open))) {
                if (!wavData.Read(br1))
                {
                    resultString = string.Format(rm.GetString("ReadFileFailFormat"), path) + "\r\n";
                    e.Result     = false;
                    return;
                }
                if (wavData.NumSamples < startPos + outputSamples)
                {
                    resultString = string.Format(rm.GetString("WavFileTooShort"), startPos + outputSamples, wavData.NumSamples, path) + "\r\n";
                    e.Result     = false;
                    return;
                }
            }

            Console.WriteLine(rm.GetString("WavFileSummary"), wavData.NumSamples);
            resultString += string.Format(rm.GetString("WavFileSummary"), wavData.NumSamples);
            double offset = (double)numericUpDownSubSampleOffset.Value;

            if (checkBoxCh0.Checked && !checkBoxCh1.Checked)
            {
                using (StreamWriter sw = new StreamWriter(textBoxWriteFile.Text)) {
                    for (int i = startPos; i < startPos + outputSamples; ++i)
                    {
                        sw.WriteLine("{0} {1}", i + offset, wavData.Sample16Get(0, i));
                    }
                }
            }
            else if (!checkBoxCh0.Checked && checkBoxCh1.Checked)
            {
                using (StreamWriter sw = new StreamWriter(textBoxWriteFile.Text)) {
                    for (int i = startPos; i < startPos + outputSamples; ++i)
                    {
                        sw.WriteLine("{0} {1}", i + offset, wavData.Sample16Get(1, i));
                    }
                }
            }
            else if (checkBoxCh0.Checked && checkBoxCh1.Checked)
            {
                using (StreamWriter sw = new StreamWriter(textBoxWriteFile.Text)) {
                    for (int i = startPos; i < startPos + outputSamples; ++i)
                    {
                        sw.WriteLine("{0} {1} {2}", i + offset, wavData.Sample16Get(0, i), wavData.Sample16Get(1, i));
                    }
                }
            }
            e.Result = true;
        }
示例#2
0
        private void Effect(WavData wavData)
        {
            if (checkBoxInvert.Checked)
            {
                for (int ch = 0; ch < wavData.NumChannels; ++ch)
                {
                    for (int pos = 0; pos < wavData.NumSamples; ++pos)
                    {
                        short val = wavData.Sample16Get(ch, pos);

                        // Invert! we want to do this effect
                        val = (short)-val;

                        wavData.Sample16Set(ch, pos, val);
                    }
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            OptionInfo optionInfo = new OptionInfo(2);

            ParseOptions(ref optionInfo, args);

            WavData ch0Wav = ReadWavFromFile(optionInfo.channels[0].chFileName);
            WavData ch1Wav = ReadWavFromFile(optionInfo.channels[1].chFileName);

            if (ch0Wav.NumSamples != ch1Wav.NumSamples)
            {
                Console.WriteLine("E: NumSamples mismatch. ch0.numSamples={0}, ch1.numSamples={1}",
                                  ch0Wav.NumSamples, ch1Wav.NumSamples);
                PrintUsageAndExit();
            }

            WavData writeWav = new WavData();
            List <PcmSamples1Channel> channels = new List <PcmSamples1Channel>();

            for (int i = 0; i < 2; ++i)
            {
                channels.Add(new PcmSamples1Channel(ch0Wav.NumSamples, ch0Wav.BitsPerSample));
            }

            int ch0UseCh = optionInfo.channels[0].chFileUseCh;
            int ch1UseCh = optionInfo.channels[1].chFileUseCh;

            for (int i = 0; i < ch0Wav.NumSamples; ++i)
            {
                channels[0].Set16(i, ch0Wav.Sample16Get(ch0UseCh, i));
                channels[1].Set16(i, ch1Wav.Sample16Get(ch1UseCh, i));
            }

            writeWav.Create(ch0Wav.SampleRate, ch0Wav.BitsPerSample, channels);

            try {
                using (BinaryWriter bw = new BinaryWriter(File.Open(optionInfo.outputWavFileName, FileMode.CreateNew))) {
                    writeWav.Write(bw);
                }
            } catch (Exception ex) {
                Console.WriteLine("E: {0}", ex);
                PrintUsageAndExit();
            }
        }
示例#4
0
        private void Effect(WavData wavData)
        {
            if (checkBoxInvert.Checked) {
                for (int ch=0; ch < wavData.NumChannels; ++ch) {
                    for (int pos=0; pos < wavData.NumSamples; ++pos) {
                        short val = wavData.Sample16Get(ch, pos);

                        // Invert! we want to do this effect
                        val = (short)-val;

                        wavData.Sample16Set(ch, pos, val);
                    }
                }
            }
        }
示例#5
0
        /** @param delay_return [out] (0 < delay_return) w1 is delayed by delay samples
         *                     (delay_return < 0) w2 is delayed by delay samples
         *  @param w1w2VolumeRatio_return [out] >1: w1 volume is larger than w2, <1: w1 volume is smaller than w2
         */
        private bool SampleDelay(WavData w1, WavData w2, out int delay_return, out double w1w2VolumeRatio_return)
        {
            float ACCUMULATE_SECONDS_MAX = (float)numericAccumulateSeconds.Value;
            float DELAY_SECONDS_MAX      = (float)numericStartDelayTorelance.Value;

            delay_return = 0;

            SortedDictionary <long, VolumeInfo> delayValueAndPos =
                new SortedDictionary <long, VolumeInfo>();

            int samplesPerSecond = w1.SampleRate;

            /* assume w1 is delayed (0 < delay) */
            for (int delay = 0; delay < samplesPerSecond * DELAY_SECONDS_MAX; ++delay)
            {
                VolumeInfo vi = new VolumeInfo();
                vi.delay = delay;

                for (int pos = 0; pos < samplesPerSecond * ACCUMULATE_SECONDS_MAX; ++pos)
                {
                    int w1Value = Math.Abs(w1.Sample16Get(0, pos));
                    int w2Value = Math.Abs(w2.Sample16Get(0, pos + delay));
                    vi.w1Volume        += w1Value;
                    vi.w2Volume        += w2Value;
                    vi.accumulatedDiff += Math.Abs(w1Value - w2Value);
                }
                // Console.Write("[{0} {1}]", delay, acc);
                if (!delayValueAndPos.ContainsKey(vi.accumulatedDiff))
                {
                    delayValueAndPos[vi.accumulatedDiff] = vi;
                }
                backgroundWorker1.ReportProgress(delay * 50 / (int)(samplesPerSecond * DELAY_SECONDS_MAX));
            }

            /* assume w2 is delayed (delay < 0) */
            for (int delay = 1; delay < samplesPerSecond * DELAY_SECONDS_MAX; ++delay)
            {
                VolumeInfo vi = new VolumeInfo();
                vi.delay = -delay;

                for (int pos = 0; pos < samplesPerSecond * ACCUMULATE_SECONDS_MAX; ++pos)
                {
                    int w1Value = Math.Abs(w1.Sample16Get(0, pos + delay));
                    int w2Value = Math.Abs(w2.Sample16Get(0, pos));
                    vi.w1Volume        += w1Value;
                    vi.w2Volume        += w2Value;
                    vi.accumulatedDiff += Math.Abs(w1Value - w2Value);
                }
                // Console.Write("[{0} {1}]", -delay, acc);
                if (!delayValueAndPos.ContainsKey(vi.accumulatedDiff))
                {
                    delayValueAndPos[vi.accumulatedDiff] = vi;
                }
                backgroundWorker1.ReportProgress(50 + delay * 50 / (int)(samplesPerSecond * DELAY_SECONDS_MAX));
            }

            SortedDictionary <long, VolumeInfo> .Enumerator e = delayValueAndPos.GetEnumerator();
            e.MoveNext();

            w1w2VolumeRatio_return = (double)e.Current.Value.w1Volume / e.Current.Value.w2Volume;
            delay_return           = e.Current.Value.delay;

            Console.WriteLine();
            Console.WriteLine(rm.GetString("SampleDelaySummary"),
                              delay_return, (double)delay_return / samplesPerSecond,
                              (double)e.Current.Key / (samplesPerSecond * DELAY_SECONDS_MAX),
                              w1w2VolumeRatio_return);
            if (w1w2VolumeRatio_return < 0.5 || 2.0 < w1w2VolumeRatio_return)
            {
                return(false);
            }
            return(true);
        }