Skip to content

Commit

Permalink
Move csum to Decoder, only needs to be allocated once.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Aug 28, 2014
1 parent e975960 commit b38a3d5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Decoder struct {
signal []float64
quantized []byte

lut MagnitudeLUT
csum []float64
lut MagnitudeLUT

preamble []byte
slices [][]byte
Expand All @@ -68,6 +69,8 @@ func NewDecoder(cfg PacketConfig) (d Decoder) {
d.signal = make([]float64, d.cfg.BufferLength)
d.quantized = make([]byte, d.cfg.BufferLength)

d.csum = make([]float64, d.cfg.BlockSize+d.cfg.SymbolLength2+1)

if *fastMag {
d.lut = NewAlphaMaxBetaMinLUT()
} else {
Expand Down Expand Up @@ -188,18 +191,16 @@ func (lut AlphaMaxBetaMinLUT) Execute(input []byte, output []float64) {
}

func (d Decoder) Filter(input []float64) {
csum := make([]float64, len(input)+1)

var sum float64
for idx, v := range input {
sum += v
csum[idx+1] = sum
d.csum[idx+1] = sum
}

lower := csum[d.cfg.SymbolLength:]
upper := csum[d.cfg.SymbolLength2:]
lower := d.csum[d.cfg.SymbolLength:]
upper := d.csum[d.cfg.SymbolLength2:]
for idx := range input[:len(input)-d.cfg.SymbolLength2] {
input[idx] = (lower[idx] - csum[idx]) - (upper[idx] - lower[idx])
input[idx] = (lower[idx] - d.csum[idx]) - (upper[idx] - lower[idx])
}

return
Expand Down

0 comments on commit b38a3d5

Please sign in to comment.