// Adjusts the times of the beats by performing a least squares reqression to fit the estimated beats to
// a straight line (on the assumption that the BPM is reasonably constant).
Adjusts the times of the beats by performing a least squares reqression to fit the estimated beats to
a straight line (on the assumption that the BPM is reasonably constant).
// Adjusts the times of the beats by performing a least squares reqression to fit the estimated beats to // a straight line ( on the assumption that the BPM is reasonably constant ) .
func (beats *Beats) Quantize() error {
	switch {
	case beats == nil:
		return nil
	case len(beats.Beats) < 1:
		beats.BPM = 0
		beats.Offset = 0 * time.Millisecond
		return nil
	case len(beats.Beats) < 2:
		beats.BPM = 0
		beats.Offset = beats.Beats[0].At
		return nil
	default:
		m, c, err := fit(beats.Beats)
		if err != nil {
			return err
		}
		quantized := []Beat{}
		for _, b := range beats.Beats {
			quantized = append(quantized, Beat{
				At:       Seconds(float64(b.beat)*m + c),
				Mean:     b.Mean,
				Variance: b.Variance,
				Taps:     b.Taps,
			})
		}
		beats.BPM, beats.Offset = bpm(quantized)
		beats.Beats = quantized
		return nil
	}
}
func ( beats * Beats ) Quantize ( ) error { switch { case beats == nil : return nil case len ( beats . Beats ) < 1 : beats . BPM = 0 beats . Offset = 0 * time . Millisecond return nil case len ( beats . Beats ) < 2 : beats . BPM = 0 beats . Offset = beats . Beats [ 0 ] . At return nil default : m , c , err := fit ( beats . Beats ) if err != nil { return err } quantized := [ ] Beat { } for _ , b := range beats . Beats { quantized = append ( quantized , Beat { At : Seconds ( float64 ( b . beat ) * m + c ) , Mean : b . Mean , Variance : b . Variance , Taps : b . Taps , } ) } beats . BPM , beats . Offset = bpm ( quantized ) beats . Beats = quantized return nil } }
Adjusts the times of the beats by performing a least squares reqression to fit the estimated beats to
a straight line (on the assumption that the BPM is reasonably constant).
Adjusts the times of the beats by performing a least squares reqression to fit the estimated beats to a straight line ( on the assumption that the BPM is reasonably constant ) .