From b38a3d5884be2294e875efc1897af053d0fa6c4f Mon Sep 17 00:00:00 2001 From: bemasher Date: Thu, 28 Aug 2014 03:43:00 -0600 Subject: [PATCH] Move csum to Decoder, only needs to be allocated once. --- decoder.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/decoder.go b/decoder.go index dd4220aab..6ada51699 100644 --- a/decoder.go +++ b/decoder.go @@ -53,7 +53,8 @@ type Decoder struct { signal []float64 quantized []byte - lut MagnitudeLUT + csum []float64 + lut MagnitudeLUT preamble []byte slices [][]byte @@ -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 { @@ -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