Skip to content

Commit

Permalink
flac: restore original samples after encode for subframes with wasted…
Browse files Browse the repository at this point in the history
… bits

ref: #66 (comment)
  • Loading branch information
mewmew committed Oct 31, 2023
1 parent b3cd2a5 commit 97aacbb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion encode_subframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ func encodeSubframe(bw *bitio.Writer, hdr frame.Header, subframe *frame.Subframe
bps -= subframe.Wasted

// Right shift to account for wasted bits-per-sample.
// TODO: figure out how to make this non-destructive (use defer to restore original samples?).
if subframe.Wasted > 0 {
for i, sample := range subframe.Samples {
subframe.Samples[i] = sample >> subframe.Wasted
}
// NOTE: use defer to restore original samples after encode.
defer func() {
for i, sample := range subframe.Samples {
subframe.Samples[i] = sample << subframe.Wasted
}
}()
}

// Encode audio samples.
Expand Down

0 comments on commit 97aacbb

Please sign in to comment.