//This function will create a set of PeakData that is based on amplitude thresh holds, //completely ignoring bpm. // //Dynamic Thresh Hold Creation: The required amplitude threshold will be relative to the // current average amplitude at that point in the song. //Slope Detection: This will be used to detect possible slider placement and length. // e.g. a slope close to zero across several samples // would suggest a flat, drawn out sound (I think?). // However, this will never truely occur because most songs will // have multiple instruments playing at the same time. // So a drawn out violin sound would be surrounded by bass "wiggles"/waves. public void PerformRandomBeatDetection() { //Retrive all of the data at once. byte[] buffer = new byte[this.pcm.Length]; this.pcm.Position = 0; int ret = this.pcm.Read(buffer, 0, buffer.Length); PeakData pd = CalculatePeak(0, 0, buffer); var data = CalculatePeak(0, 0, buffer); var meanValue = data.value; Console.WriteLine("Average:" + meanValue); throw new NotImplementedException("Dont use this yet."); }
//TODO: "range" is a very relative value. We will have to experiment with values // to determine a good range. However, this value will most likely be dependant on the // mp3 file, due to the possiblity of multiple channels. /// <summary> /// This moves the stream index to the current millisecond, and reads a range /// of values surrounding it for calculating a peak. /// This IS flexible, we can read bytes from any interval we want. /// </summary> /// <param name="currentMillisecond">The current millisecond in the song.</param> /// <param name="range">The range around the millisecond to take an average of.</param> public PeakData CreatePeakDataAt(int currentMillisecond, int range) { double offsetInSeconds = (double)currentMillisecond / 1000.0; int index = (int)(offsetInSeconds * bytesPerSecond); int size = range * 2; byte[] buffer = new byte[size]; this.pcm.Position = index - range; int ret = this.pcm.Read(buffer, 0, buffer.Length); Console.WriteLine("Ret:" + ret); PeakData pd = CalculatePeak(index, currentMillisecond, buffer); //peakData.Add(pd); return(pd); }