Exemplo n.º 1
0
        /**
         * @return The list of feature vectors from the fileStream used by
         *         audioSource
         */
        private List <float[]> GetFeatures()
        {
            List <float[]> ret = new List <float[]>();

            try
            {
                int   featureLength = -1;
                IData feature       = _frontEnd.GetData();
                while (!(feature is DataEndSignal))
                {
                    if (feature is DoubleData)
                    {
                        double[] featureData = ((DoubleData)feature).Values;
                        if (featureLength < 0)
                        {
                            featureLength = featureData.Length;
                        }
                        float[] convertedData = new float[featureData.Length];
                        for (int i = 0; i < featureData.Length; i++)
                        {
                            convertedData[i] = (float)featureData[i];
                        }
                        ret.Add(convertedData);
                    }
                    else if (feature is FloatData)
                    {
                        float[] featureData = ((FloatData)feature).Values;
                        if (featureLength < 0)
                        {
                            featureLength = featureData.Length;
                        }
                        ret.Add(featureData);
                    }
                    feature = _frontEnd.GetData();
                }
            }
            catch (Exception e)
            {
                e.PrintStackTrace();
            }
            return(ret);
        }
Exemplo n.º 2
0
        public bool Bandwidth(String file)
        {
            _source.SetAudioFile(file, "");

            IData data;
            var   energy = new double[Bands];

            while ((data = _frontend.GetData()) != null)
            {
                if (data is DoubleData)
                {
                    double   maxIntensity = LowIntensity;
                    double[] frame        = ((DoubleData)data).Values;

                    for (int i = 0; i < Bands; i++)
                    {
                        maxIntensity = Math.Max(maxIntensity, frame[i]);
                    }

                    if (maxIntensity <= LowIntensity)
                    {
                        continue;
                    }

                    for (int i = 0; i < Bands; i++)
                    {
                        energy[i] = Math.Max(frame[i] / maxIntensity, energy[i]);
                    }
                }
            }

            double maxLow = Max(energy, LowRangeStart, LowRangeEnd);
            double maxHi  = Max(energy, HighRangeStart, HighRangeEnd);

            // System.out.format("%f %f\n", maxHi, maxLow);
            // for (int i = 0; i < bands; i++)
            // System.out.format("%.4f ", energy[i]);
            // System.out.println();

            if (maxHi < NoSignalLevel && maxLow > SignalLevel)
            {
                return(true);
            }

            return(false);
        }
        private void CompareDump(FrontEnd frontend, String name)
        {
            var stream = new URL(name).OpenStream();
            var st     = new BufferedStream(stream, 8192);
            var br     = new StreamReader(st);


            String line;

            // To dump data next time
            //        while (true) {
            //            Data data = frontend.getData();
            //            if (data == null)
            //                    break;
            //        }
            //        if (false)

            int counter = 0;

            while (null != (line = br.ReadLine()))
            {
                counter++;

                if (counter == 4 && name.Contains("after-cmn"))
                {
                    Trace.WriteLine("we are there");
                }

                var data = frontend.GetData();

                if (line.StartsWith("DataStartSignal"))
                {
                    Assert.IsTrue(data is DataStartSignal);
                }
                if (line.StartsWith("DataEndSignal"))
                {
                    Assert.IsTrue(data is DataEndSignal);
                }
                if (line.StartsWith("SpeechStartSignal"))
                {
                    Assert.IsTrue(data is SpeechStartSignal);
                }
                if (line.StartsWith("SpeechEndSignal"))
                {
                    Assert.IsTrue(data is SpeechEndSignal);
                }

                if (line.StartsWith("Frame"))
                {
                    Assert.IsTrue(data is DoubleData);

                    var values = ((DoubleData)data).Values;
                    var tokens = line.Split(" ");

                    Assert.AreEqual(values.Length, Convert.ToInt32(tokens[1]));


                    for (var i = 0; i < values.Length; i++)
                    {
                        var theValue    = values[i];
                        var doubleValue = Convert.ToDouble(tokens[2 + i], CultureInfo.InvariantCulture.NumberFormat);
                        var closeValue  = Math.Abs(0.01 * values[i]);
                        Assert.IsTrue(Helper.CloseTo(theValue, doubleValue, closeValue));
                    }
                }

                if (line.StartsWith("FloatFrame"))
                {
                    var tokens = line.Split(" ");
                    Assert.IsTrue(data is FloatData);
                    var values = ((FloatData)data).Values;
                    Assert.AreEqual(values.Length, Integer.ValueOf(tokens[1]));
                    for (var i = 0; i < values.Length; i++)
                    {
                        Assert.IsTrue(Helper.CloseTo(values[i], Convert.ToSingle(tokens[2 + i], CultureInfo.InvariantCulture.NumberFormat), Math.Abs(0.01 * values[i])));
                    }
                }
            }
        }