Skip to content

Commit

Permalink
Remove superfluous check on sample count
Browse files Browse the repository at this point in the history
  • Loading branch information
braheezy committed Jul 30, 2024
1 parent 85521a6 commit 1a77c21
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package qoa
import (
"encoding/binary"
"errors"
"fmt"
)

// encodeHeader encodes the QOA header.
Expand Down Expand Up @@ -197,9 +196,6 @@ func (q *QOA) Encode(sampleData []int16) ([]byte, error) {
frameLen := uint32(QOAFrameLen)
for sampleIndex := uint32(0); sampleIndex < q.Samples; sampleIndex += frameLen {
frameLen = uint32(clamp(QOAFrameLen, 0, int(q.Samples-sampleIndex)))
if (sampleIndex+frameLen)*q.Channels > uint32(len(sampleData)) {
return nil, fmt.Errorf("not enough samples: %v", len(sampleData))
}
frameSamples := sampleData[sampleIndex*q.Channels : (sampleIndex+frameLen)*q.Channels]
frameSize := q.encodeFrame(frameSamples, frameLen, bytes[p:])
p += uint32(frameSize)
Expand Down

0 comments on commit 1a77c21

Please sign in to comment.