public IEnumerable <Frame> Input(double[] samples, int length)
        {
            int index = 0;

            while (InputUntilStep(samples, length, ref index))
            {
                Debug.Assert(sample % Step == 0);
                shortWindow.Process(buffer, bufferPosition);
                mediumWindow.Process(buffer, bufferPosition);
                longWindow.Process(buffer, bufferPosition);

                Debug.Assert(shortWindow.OutputSize == mediumWindow.OutputSize && mediumWindow.OutputSize == longWindow.OutputSize);
                double[] frame = new double[shortWindow.OutputSize * 2 + mediumWindow.OutputSize * 2 + longWindow.OutputSize * 2];
                shortWindow.PrepareAbsoluteFrame(frame, 0);
                shortWindow.PrepareDifferenceFrame(frame, shortWindow.OutputSize);
                mediumWindow.PrepareAbsoluteFrame(frame, shortWindow.OutputSize * 2);
                mediumWindow.PrepareDifferenceFrame(frame, shortWindow.OutputSize * 2 + mediumWindow.OutputSize);
                longWindow.PrepareAbsoluteFrame(frame, shortWindow.OutputSize * 2 + mediumWindow.OutputSize * 2);
                longWindow.PrepareDifferenceFrame(frame, shortWindow.OutputSize * 2 + mediumWindow.OutputSize * 2 + longWindow.OutputSize);

                double startTime = (sample * 1.0 - Step) / SamplingFrequency;
                double endTime   = (sample * 1.0) / SamplingFrequency;
                yield return(new Frame(startTime, endTime, frame));
            }
        }
Example #2
0
        private static double[] CalculateEnergies(TrackInfo trackInfo)
        {
            using (WaveFile wave = trackInfo.GetWaveFile())
            {
                wave.Open();
                Debug.Assert(wave.SampleRate == 44100);
                PreprocessingWindow window  = new PreprocessingWindow(512, 44100, AccuracyInSamples);
                double[]            samples = new double[wave.Length + 512];
                double[]            result  = new double[wave.Length / AccuracyInSamples];
                Debug.Assert(wave.Read(samples) == wave.Length);

                double[] bands = new double[window.OutputSize];

                for (int i = 0; i < result.Length; i++)
                {
                    window.Process(samples, i * AccuracyInSamples);
                    window.PrepareDifferenceFrame(bands, 0);
                    result[i] = bands.Sum();
                }
                return(result);
            }
        }