private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refpeak = false;

            if (rightChanged)
            {
                _refWav = new WavFileWrapper(refPath);
                //_refWav = new WavFileWrapper(@"C:\Users\Jimmy\Desktop\Human Voice Detector\HumanVoiceDetector\bin\Debug\Echo IVRresult_id=21774831&t=audio&r=1434196481.wav"); ;
                if (_refWav.Load())
                {
                    if (option.NormalizeAudio)
                    {
                        peakRef = _refWav.Peak();
                        refpeak = option.NormalizeAudio;
                    }
                    refmfcc = new MFCCWrapper(_refWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    refmfcc.Process();

                    refpitch = new PitchWrapper(_refWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        refpitch.SetMedianWindowSize(option.MedianWindow);
                    }

                    refpitch.Process();
                    rightChanged = false;
                    // Debug.WriteLine("Process Ref file completed Time {0}", DateTime.Now);
                }
            }
            if (refmfcc != null && refmfcc.ProcessDone)
            {
                SetDataChart(FormTag.REF_WAVE);
                //Debug.WriteLine("Process Ref: Draw Wave Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_FREQ);
                //Debug.WriteLine("Process Ref: Draw Freq Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_MFCC);
                //Debug.WriteLine("Process Ref: Draw MFCC Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DOUBLE);
                //Debug.WriteLine("Process Ref: Draw Double Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DETAL);
                //Debug.WriteLine("Process Ref: Draw Detal Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_PITCH);
                //Debug.WriteLine("Process Ref: Draw Pitch Done {0}", DateTime.Now);
            }

            //Debug.WriteLine("Set data chart Ref Ref Done {0}", DateTime.Now);


            if (leftChanged)
            {
                _yourWav = new WavFileWrapper(yourPath);

                if (_yourWav.Load())
                {
                    yourmfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (refpeak)
                    {
                        _yourWav.NormalizeWave(peakRef);
                    }
                    yourmfcc.Process();

                    yourpitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        yourpitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    yourpitch.Process();
                    leftChanged = false;
                }
            }
            if (yourmfcc != null && yourmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }


            if (yourmfcc != null && refmfcc != null && yourmfcc.ProcessDone && refmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                string log = string.Format("**********************************************************\nCompare : Your Path - {0}\n          Ref Path - {1}\n", yourPath, refPath);
                log += "Distance of 2 Vec Delta MFCC: ";

                double dis = DTWUtilWrapper.DistanceOf2Vector(yourmfcc.Mfcc, refmfcc.Mfcc, false);
                double fac = yourmfcc.Mfcc.Count > refmfcc.Mfcc.Count ? refmfcc.Mfcc.Count : yourmfcc.Mfcc.Count;
                double cos = dis / fac;

                log += string.Format("Dis MFCC: {0:0.###} Cos  {1:0.###} \n", cos, ScoreMath.Score(cos));
                // TO DO: Process Bar

                log += "Distance of 2 Vec Pitch: ";

                double resPitch = DTWUtilWrapper.DistanceOf2Vector(yourpitch.Pitchs, refpitch.Pitchs, true);
                double facD     = refpitch.Pitchs.Count > yourpitch.Pitchs.Count ? yourpitch.Pitchs.Count : refpitch.Pitchs.Count;
                double cosp     = resPitch / facD;
                log += string.Format("{0:0.###}  \n", cosp);

                List <double> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(yourmfcc.Mfcc, refmfcc.Mfcc, false);
                _mfccViewer.MFCC = res;

                LogUtil.Info(log);
                ShowValueCostMFCC(string.Format("{0:0.###}", ScoreMath.Score(cos)));
                ShowValueCostPitch(string.Format("{0:0.###}", resPitch));
            }
        }
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refpeak = false;

            if (_refChanged)
            {
                _refWav = new WavFileWrapper(refPath);

                if (_refWav.Load())
                {
                    _refMfcc = new MFCCWrapper(_refWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (option.NormalizeAudio)
                    {
                        refpeak = option.NormalizeAudio;
                        peakRef = _refWav.Peak();
                    }

                    _refMfcc.Process();

                    _refPitch = new PitchWrapper(_refWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        _refPitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    _refPitch.Process();
                    /// Debug.WriteLine("Process Ref file completed Time {0}", DateTime.Now);
                }
            }
            if (_refMfcc != null && _refMfcc.ProcessDone)
            {
                SetDataChart(FormTag.REF_WAVE);
                Debug.WriteLine("Process Ref: Draw Wave Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_FREQ);
                Debug.WriteLine("Process Ref: Draw Freq Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_MFCC);
                Debug.WriteLine("Process Ref: Draw MFCC Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DOUBLE);
                Debug.WriteLine("Process Ref: Draw Double Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DETAL);
                Debug.WriteLine("Process Ref: Draw Detal Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_PITCH);
                Debug.WriteLine("Process Ref: Draw Pitch Done {0}", DateTime.Now);
            }

            Debug.WriteLine("Set data chart Ref Ref Done {0}", DateTime.Now);


            if (_yourChanged)
            {
                _yourWav = new WavFileWrapper(_yourPath);

                if (_yourWav.Load())
                {
                    int  size     = _yourWav.FullData.Count;
                    uint startPnt = (uint)(_startSelected * size);
                    uint endPnt   = (uint)(_endSelected * size);
                    Debug.WriteLine("Select Data voice: Start {0} End {1}", startPnt, endPnt);
                    _yourWav.SelectedWave(startPnt, endPnt);

                    if (refpeak)
                    {
                        _yourWav.NormalizeWave(peakRef);
                    }

                    _yourMfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    _yourMfcc.Process();

                    _yourPitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        _yourPitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    _yourPitch.Process();
                }
            }

            if (_yourMfcc != null && _yourMfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }

            if (_yourMfcc != null && _refMfcc != null && _yourMfcc.ProcessDone && _refMfcc.ProcessDone)
            {
                //// TO DO: Process Bar
                //string log = string.Format("\nCompare : Your Path - {0}\n          Ref Path - {1}\n", _yourPath, refPath);

                //// TO DO: Process Bar
                //log += "Distance of 2 Vec Pitch: ";
                //float resPitch = DTWUtilWrapper.DistanceOf2Vector(_yourPitch.Pitchs, _refPitch.Pitchs, true);
                //log += string.Format("{0:0.###}", resPitch);

                //// TO DO: Process Bar
                //log += "Compute DistanceOf2Array3DHorizon:";
                //List<float> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(_yourMfcc.DetalMfcc, _refMfcc.DetalMfcc, true);
                //_mfccViewer.MFCC = res;


                //log += "Distance of 2 Vec Delta MFCC: ";
                //float resMFCC = DTWUtilWrapper.DistanceOf2Array3D(_yourMfcc.Mfcc, _refMfcc.Mfcc, true);

                //log += string.Format("{0:0.###}", resMFCC);

                ////float sum = 0.0f;
                ////for (int i = 0; i < res.Count; i++)
                ////{
                ////    log += string.Format("  {0}: {1}", i, res[i]);
                ////    sum += res[i];
                ////}
                ////ShowValueCostMFCC(string.Format("{0:0.###}", res / res.Count));
                //LogUtil.Info(log);

                ////ShowValueCostPitch(string.Format("{0:0.###}", resPitch));

                // TO DO: Process Bar
                string log = string.Format("**********************************************************\nCompare : Your Path - {0}\n          Ref Path - {1}\n", _yourPath, refPath);
                log += "Distance of 2 Vec Delta MFCC: ";
                //float resMFCC = DTWUtilWrapper.DistanceOf2Array3D(yourmfcc.Mfcc, refmfcc.Mfcc, true);
                double dis = DTWUtilWrapper.DistanceOf2Vector(_yourMfcc.Mfcc, _refMfcc.Mfcc, false);
                double fac = _yourMfcc.Mfcc.Count > _refMfcc.Mfcc.Count ? _refMfcc.Mfcc.Count : _yourMfcc.Mfcc.Count;
                double cos = dis / fac;
                //log += string.Format("Dis MFCC: {0:0.###} Score MFCC: {1:0.###}\n", 10 *dis / fac, -4.51297 * Math.Log10(-0.083653 * dis / fac + 1));
                log += string.Format("Dis MFCC: {0:0.###} Cos  {1:0.###} \n", cos, ScoreMath.Score(cos));
                // TO DO: Process Bar

                log += "Distance of 2 Vec Pitch: ";

                double resPitch = DTWUtilWrapper.DistanceOf2Vector(_yourPitch.Pitchs, _refPitch.Pitchs, true);
                double facD     = _refPitch.Pitchs.Count > _yourPitch.Pitchs.Count ? _yourPitch.Pitchs.Count : _refPitch.Pitchs.Count;
                double cosp     = resPitch / facD;
                log += string.Format("{0:0.###}  \n", cosp);


                // log += string.Format(" Score {0:0.###} {1:0.###} {2:0.###}  \n", );
                // TO DO: Process Bar
                //log += "Distance of Component MFCC:\n";
                List <double> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(_yourMfcc.Mfcc, _refMfcc.Mfcc, false);
                _mfccViewer.MFCC = res;
                //for (int i = 0; i < res.Count; i++) {
                //	log += string.Format("  {0}: {1}\n", i, res[i]);
                //}

                LogUtil.Info(log);
                ShowValueCostMFCC(string.Format("{0:0.###}", ScoreMath.Score(cos)));

                ShowValueCostPitch(string.Format("{0:0.###}", resPitch));
            }
        }