コード例 #1
0
        //This function should be called every tick/frame. This used the previous functions to
        //Update time, get the current spectrum and the adaptive threshold and then does a check
        //to see if a beat has occured. It also allows for some post-detection ignore clause.
        //This function also does functions such as update the smoothing median list, create a
        //timestamp object, update the lastBeatRegistered and checks to see if the song
        //is still playing
        public void update()
        {
            // Console.WriteLine(specFlux);

                if (started)
                {
                    float[] specStereo;

                    updateTime();

                    specStereo = getCurrentSpectrum();

                    //Console.WriteLine(specStereo);

                    beatThreshold = calculateFluxAndSmoothing(specStereo);

                    //Beat detected
                    if (specFlux > beatThreshold && ((uint) stopW.ElapsedMilliseconds - timeBetween) > 350)
                    {
                        if (smootherValues.Count > 1)
                            smootherValues.Insert(smootherValues.Count - 1, specFlux);
                        else
                            smootherValues.Insert(smootherValues.Count, specFlux);

                        if (smootherValues.Count >= 5)
                        {
                            smootherValues.Remove(0);
                        }

                        timeBetween = (uint)stopW.ElapsedMilliseconds;

                        TimeStamp t = new TimeStamp(currentMinutes, currentSeconds, currentMillis, specFlux);
                        Console.WriteLine("BEAT AT: " + t.getMinutes() + ":" + t.getSeconds() + ":" + t.getMilliseconds() + " -- BEAT FREQ: " + t.getFrequency() + " -- THRESHOLD: " + beatThreshold);
                        lastBeatRegistered = t;
                    }
                    else if (((uint) stopW.ElapsedMilliseconds - timeBetween) > 5000)
                    {
                        if (thresholdSmoother>0.4f)
                            thresholdSmoother -= 0.4f;

                        timeBetween = (uint)stopW.ElapsedMilliseconds;
                    }

                    if(!delayedSong)
                        songChannel1.isPlaying(ref areWePlaying);
                    else
                        songChannel2.isPlaying(ref areWePlaying);

                    //delete[] specStereo;
                }
                else
                {
                    Console.ReadLine();
                    if (test == 1)
                        setStarted(true);
                }
        }
コード例 #2
0
        //This function should be called every tick/frame. This used the previous functions to
        //Update time, get the current spectrum and the adaptive threshold and then does a check
        //to see if a beat has occured. It also allows for some post-detection ignore clause.
        //This function also does functions such as update the smoothing median list, create a
        //timestamp object, update the lastBeatRegistered and checks to see if the song
        //is still playing
        public void update()
        {
            // Console.WriteLine(specFlux);

            if (started)
            {
                float[] specStereo;

                updateTime();

                specStereo = getCurrentSpectrum();

                //Console.WriteLine(specStereo);

                beatThreshold = calculateFluxAndSmoothing(specStereo);

                //Beat detected
                if (specFlux > beatThreshold && ((uint)stopW.ElapsedMilliseconds - timeBetween) > 350)
                {
                    if (smootherValues.Count > 1)
                    {
                        smootherValues.Insert(smootherValues.Count - 1, specFlux);
                    }
                    else
                    {
                        smootherValues.Insert(smootherValues.Count, specFlux);
                    }

                    if (smootherValues.Count >= 5)
                    {
                        smootherValues.Remove(0);
                    }

                    timeBetween = (uint)stopW.ElapsedMilliseconds;

                    TimeStamp t = new TimeStamp(currentMinutes, currentSeconds, currentMillis, specFlux);
                    Console.WriteLine("BEAT AT: " + t.getMinutes() + ":" + t.getSeconds() + ":" + t.getMilliseconds() + " -- BEAT FREQ: " + t.getFrequency() + " -- THRESHOLD: " + beatThreshold);
                    beatWait           = true;
                    lastBeatRegistered = t;
                }
                else if (((uint)stopW.ElapsedMilliseconds - timeBetween) > 5000)
                {
                    if (thresholdSmoother > 0.4f)
                    {
                        thresholdSmoother -= 0.4f;
                    }

                    timeBetween = (uint)stopW.ElapsedMilliseconds;
                }

                if (!delayedSong)
                {
                    songChannel1.isPlaying(ref areWePlaying);
                }
                else
                {
                    songChannel2.isPlaying(ref areWePlaying);
                }

                //delete[] specStereo;
            }
            else
            {
                Console.ReadLine();
                if (test == 1)
                {
                    setStarted(true);
                }
            }
        }