// Estimate the BPM and offset of the first beats by applying least squares reqression to a set of beats.
Estimate the BPM and offset of the first beats by applying least squares reqression to a set of beats.
// Estimate the BPM and offset of the first beats by applying least squares reqression to a set of beats .
func bpm(beats []Beat) (uint, time.Duration) {
	if len(beats) < 2 {
		return 0, 0
	}
	m, c, err := fit(beats)
	if err != nil {
		return 0, 0
	}
	bpm := uint(math.Round(60.0 / m))
	b0 := int(math.Floor(-c / m))
	t0 := float64(b0)*m + c
	for t0 < 0.0 {
		b0++
		t0 = float64(b0)*m + c
	}
	offset := Seconds(t0)
	return bpm, offset
}
func bpm ( beats [ ] Beat ) ( uint , time . Duration ) { if len ( beats ) < 2 { return 0 , 0 } m , c , err := fit ( beats ) if err != nil { return 0 , 0 } bpm := uint ( math . Round ( 60.0 / m ) ) b0 := int ( math . Floor ( - c / m ) ) t0 := float64 ( b0 ) * m + c for t0 < 0.0 { b0 ++ t0 = float64 ( b0 ) * m + c } offset := Seconds ( t0 ) return bpm , offset }
Estimate the BPM and offset of the first beats by applying least squares reqression to a set of beats.
Estimate the BPM and offset of the first beats by applying least squares reqression to a set of beats .