Пример #1
0
        // Read in a sample and convert it to mono
        float[] ReadMonoPCM()
        {
            int size = SAMPLE_SIZE;

            // If stereo
            if (PCMStream.WaveFormat.Channels == 2)
            {
                size *= 2;
            }

            float[] output = new float[size];

            // Read in a sample
            if (PCMStream.Read(output, 0, size) == 0)
            {
                // If end of audio file
                return(null);
            }

            // If stereo, convert to mono
            if (PCMStream.WaveFormat.Channels == 2)
            {
                return(ConvertStereoToMono(output));
            }
            else
            {
                return(output);
            }
        }
Пример #2
0
        public void DetectOnsets(float sensitivity = 1.5f)
        {
            onsetDetection = new OnsetDetection(PCMStream.WaveFormat.SampleRate, 1024);
            // Has finished reading in the audio file

            // Set the pcm data back to the beginning
            SetTrackPosition(0);


            float[] buf       = new float[SAMPLE_SIZE];
            var     readtotal = 0;

            do
            {
                var read = PCMStream.Read(buf, 0, buf.Length);
                readtotal += read;

                if (read == 0)
                {
                    break;
                }
                // Read in audio data and find the flux values until end of audio file
                onsetDetection.AddFlux(buf);
            }while (readtotal < PCMStream.Length);
            Console.WriteLine("Finished adding flux!");

            // Find peaks
            onsetDetection.FindOnsets(sensitivity);
        }