Example #1
0
        double GetFrequencySimularity()
        {
            if (rawAudio.SampleLength != producedAudio.SampleLength)
            {
                throw new ArgumentException("Songs do not share the same samplelength");
            }
            long            minLength  = Math.Min(rawAudio.samples.Length, producedAudio.samples.Length);
            List <double[]> tempAmps   = new List <double[]> ();
            int             sampleStep = (int)Math.Round(rawAudio.sampleRate / sampleFrequency);

            for (long i = 0; i < minLength - sampleStep; i += sampleStep)
            {
                double progress = Math.Round(10000.0 * i / (minLength - sampleStep)) / 100;
                WriteToProgressLabel("Transforming produced audio: " + progress + "%");
                double[] amps = Sequencer.FourierTransform(producedAudio.samples, i, sampleStep, rawAudio.SampleLength);
                tempAmps.Add(amps);
            }
            double totalDiff = 0;
            double tot       = 0;

            for (int i = 0; i < tempAmps.Count; i++)
            {
                for (int j = 0; j < tempAmps[i].Length; j++)
                {
                    totalDiff += Math.Abs(allAmps[i][j] - tempAmps[i][j]);
                    tot++;
                }
            }
            totalDiff /= tot;
            return(totalDiff);
        }
Example #2
0
        void SequenceAudio()
        {
            allAmps.Clear();
            // Calculating the step size
            int sampleStep = (int)Math.Round(rawAudio.sampleRate / sampleFrequency);

            for (long i = 0; i < rawAudio.samples.Length - sampleStep; i += sampleStep)
            {
                double progress = Math.Round(10000.0 * i / (rawAudio.samples.Length - sampleStep)) / 100;
                WriteToProgressLabel("Transforming: " + progress + "%");
                double[] amps = Sequencer.FourierTransform(rawAudio.samples, i, sampleStep, rawAudio.SampleLength);
                allAmps.Add(amps);
            }
        }