Ejemplo n.º 1
0
 public void Read(WaveControl wc, string filename, ProgressBar progress)
 {
     m_Wavefile = new WaveSound(filename, wc, progress);
     m_Wavefile.ReadWavFile();
     m_DrawWave = true;
 }
Ejemplo n.º 2
0
        /// <summary>Compare its wave sound to the given sound by applying FFT algorithm.</summary>
        /// <param name="wf">The wave sound that is used to compare with its own wave sound</param>
        /// <returns>percentage of similarity</returns>
        public float Compare(WaveSound wf)
        {
            int nbcorrect = 0;
            int i         = 0;

            bool endfile = false;
            int  a = 0, b = 0;

            float[] frames = new float[nbframe > wf.nbframe ? nbframe : wf.nbframe];
            comparedFrame = nbframe < wf.nbframe ? nbframe : wf.nbframe;
            short[] MissPlay = new short[comparedFrame];
            int     step     = 0;

            if (ProgressBar.Value != MAX_PROGRESS)
            {
                step = (MAX_PROGRESS - ProgressBar.Value) / comparedFrame;
            }

            // Open FFT file
            using (BinaryReader f1 = new BinaryReader(File.Open(filename + ".fft.dat", FileMode.Open)))
                using (BinaryReader f2 = new BinaryReader(File.Open(wf.filename + ".fft.dat", FileMode.Open)))
                    using (StreamWriter sw2 = new StreamWriter(wf.filename + ".fft.txt"))
                    {
                        while (!endfile)
                        {
                            try
                            {
                                a = f1.ReadInt16();
                                b = f2.ReadInt16();
                                if (i == 49)
                                {
                                }
                                if (a == -9999 || b == -9999)
                                {
                                    // Calculate the value for 1 frame
                                    frames[i]          = (float)nbcorrect / (fftPoint / 2);
                                    ProgressBar.Value += step;
                                    i++;
                                    nbcorrect = 0;
                                }
                                else
                                {
                                    if (Math.Abs(a - b) <= 10)
                                    {
                                        nbcorrect++;
                                    }
                                }
                                sw2.Write(a);
                                sw2.WriteLine("," + b);
                            }
                            catch
                            {
                                endfile = true;
                                f1.Close();
                                f2.Close();
                                sw2.Close();
                            }
                        }

                        nbcorrect = 0;
                        int idx = 0;
                        int len = comparedFrame;
                        comparedFrame = 0;

                        for (i = 0; i < len; i++)
                        {
                            nbcorrect += frames[i] >= 0.7 ? 1 : 0;
                            if (frames[i] < 0.7)
                            {
                                MissPlay[idx] = (short)i;
                                idx           = idx + 1;
                                comparedFrame++;
                            }
                        }

                        f1.Close();
                        f2.Close();
                        sw2.Close();
                        for (i = 0; i < comparedFrame; i++)
                        {
                            missData = missData + MissPlay[i] + ";";
                        }
                    }

            return((float)(nbcorrect * 100 / frames.Length));
        }