Skip to content

Commit

Permalink
Fix length of bits to pack.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Apr 16, 2016
1 parent 508c42c commit 1742cc5
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,20 @@ func NewDecoder(cfg PacketConfig, decimation int) (d Decoder) {
d.demod = NewMagLUT()

// Pre-calculate a byte-slice version of the preamble for searching.
d.preamble = make([]byte, len(d.Cfg.Preamble))
d.preamble = make([]byte, d.Cfg.PreambleSymbols)
for idx := range d.Cfg.Preamble {
if d.Cfg.Preamble[idx] == '1' {
d.preamble[idx] = 1
}
}

// Slice quantized sample buffer to make searching for the preamble more
// memory local. Pre-allocate a flat buffer so memory is contiguous and
// assign slices to the buffer.
// memory local.
d.slices = make([][]byte, d.DecCfg.SymbolLength2)
flat := make([]byte, d.DecCfg.BlockSize2-(d.DecCfg.BlockSize2%d.DecCfg.SymbolLength2))

symbolsPerBlock := d.DecCfg.BlockSize2 / d.DecCfg.SymbolLength2
symbolsPerBlock := d.DecCfg.BlockSize/d.DecCfg.SymbolLength2 + d.DecCfg.PreambleSymbols
for symbolOffset := range d.slices {
lower := symbolOffset * symbolsPerBlock
upper := (symbolOffset + 1) * symbolsPerBlock
d.slices[symbolOffset] = flat[lower:upper]
d.slices[symbolOffset] = make([]byte, symbolsPerBlock)
}

d.preambleFinder = makeByteFinder(d.preamble)
Expand Down Expand Up @@ -191,7 +187,7 @@ func (d Decoder) Decode(input []byte) []int {
Quantize(d.Filtered, d.Quantized[d.DecCfg.PacketLength-d.DecCfg.SymbolLength2:])

// Pack the quantized signal into slices for searching.
d.Pack(d.Quantized[:d.DecCfg.BlockSize2])
d.Pack(d.Quantized)

// Return a list of indexes the preamble exists at.
return d.Search()
Expand Down

0 comments on commit 1742cc5

Please sign in to comment.