addSample adds a sample to a buffer of chunks.Sample, i.e. the general case using an interface as the type.
(s chunks.Sample, buf []chunks.Sample, r *sampleRing)
| 579 | // addSample adds a sample to a buffer of chunks.Sample, i.e. the general case |
| 580 | // using an interface as the type. |
| 581 | func addSample(s chunks.Sample, buf []chunks.Sample, r *sampleRing) []chunks.Sample { |
| 582 | l := len(buf) |
| 583 | // Grow the ring buffer if it fits no more elements. |
| 584 | if l == 0 { |
| 585 | buf = make([]chunks.Sample, 16) |
| 586 | l = 16 |
| 587 | } |
| 588 | if l == r.l { |
| 589 | newBuf := make([]chunks.Sample, 2*l) |
| 590 | copy(newBuf[l+r.f:], buf[r.f:]) |
| 591 | copy(newBuf, buf[:r.f]) |
| 592 | |
| 593 | buf = newBuf |
| 594 | r.i = r.f |
| 595 | r.f += l |
| 596 | l = 2 * l |
| 597 | } else { |
| 598 | r.i++ |
| 599 | if r.i >= l { |
| 600 | r.i -= l |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | buf[r.i] = s.Copy() |
| 605 | r.l++ |
| 606 | |
| 607 | // Free head of the buffer of samples that just fell out of the range. |
| 608 | tmin := s.T() - r.delta |
| 609 | for buf[r.f].T() < tmin { |
| 610 | r.f++ |
| 611 | if r.f >= l { |
| 612 | r.f -= l |
| 613 | } |
| 614 | r.l-- |
| 615 | } |
| 616 | return buf |
| 617 | } |
| 618 | |
| 619 | // addF adds an fSample to a (specialized) fSample buffer. |
| 620 | func addF(s fSample, buf []fSample, r *sampleRing) []fSample { |
searching dependent graphs…