Exemplo n.º 1
0
        // FEATURES
        /// =======================================================================================================
        public static void WAV_LP_FILTER(string path, string cut_off_hz, string start_ms, string end_ms)
        {
            byte[]    alldata     = File.ReadAllBytes(path);
            double    cutoff      = Convert.ToDouble(cut_off_hz);
            int       startofdata = GetStartOfDataIndex(alldata);
            WAVFormat fmt         = ReadFormat(alldata);

            uint total = (uint)(alldata.Length - startofdata) / (fmt.NumberOfChannels * fmt.ByteDepth);
            uint start = 0;

            try { start = ConvertMsToNumberOfBytes(Convert.ToUInt32(start_ms), fmt) / (fmt.NumberOfChannels * fmt.ByteDepth); } catch { }
            uint end = total;

            try { end = ConvertMsToNumberOfBytes(Convert.ToUInt32(end_ms), fmt) / (fmt.NumberOfChannels * fmt.ByteDepth); } catch { }

            double[] left;
            double[] right;
            GetDoubleArrayFromBytes(alldata, out left, out right);

            double[] leftsection  = new double[end - start];
            double[] rightsection = new double[end - start];
            Array.Copy(left, start, leftsection, 0, leftsection.Length);
            Array.Copy(right, start, rightsection, 0, rightsection.Length);

            LPFilter.Butterworth(ref leftsection, fmt.SampleRate, cutoff);
            LPFilter.Butterworth(ref rightsection, fmt.SampleRate, cutoff);

            Array.Copy(leftsection, 0, left, start, leftsection.Length);
            Array.Copy(rightsection, 0, right, start, rightsection.Length);

            double[,] allsamples = new double[fmt.NumberOfChannels, left.Length];
            for (int i = 0; i < fmt.NumberOfChannels; i++)
            {
                for (int j = 0; j < left.Length; j++)
                {
                    if (i == 0)
                    {
                        allsamples[i, j] = left[j];
                    }
                    else
                    {
                        allsamples[i, j] = right[j];
                    }
                }
            }

            byte[] data = GetBytesFromDoubleArray(allsamples, fmt);
            Array.Copy(data, 0, alldata, startofdata, data.Length);
            File.WriteAllBytes(DISK.AutoIncrementFilename(path), alldata);
        }
Exemplo n.º 2
0
 public LPFilterVM()
 {
     Switch    = new LpFilterCmd();
     _lpFilter = new LPFilter();
 }