Documentation
¶
Overview ¶
Package adpcm encodes 16 bit mono PCM as IMA ADPCM, the "DVI4" variant the Reolink cameras accept for two-way audio.
The cameras describe what they want in their TalkAbility reply, and every camera surveyed here asked for the same thing: adpcm, 16000 Hz, 16 bit precision, mono, lengthPerEncoder 1024. lengthPerEncoder is a count of samples, so a block is 1024 samples, which is 512 bytes of packed nibbles behind a 4 byte preamble carrying the decoder's starting state.
Index ¶
Constants ¶
const BlockBytes = 4 + SamplesPerBlock/2
BlockBytes is the encoded size of one block: a 4 byte preamble and one nibble per sample.
const SamplesPerBlock = 1024
SamplesPerBlock is the block length the cameras ask for in lengthPerEncoder. A short final block is padded with silence rather than sent undersized: the decoder derives its sample count from the block length, so a partial block would be decoded as a full one.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder holds the predictor state that carries across blocks. The state is also written into each block's preamble, so a decoder can start anywhere, but keeping it here means consecutive blocks do not each restart from silence and click at the boundary.
func (*Encoder) EncodeBlock ¶
EncodeBlock encodes exactly SamplesPerBlock samples into one DVI4 block. A short input is padded with silence. The returned slice is BlockBytes long.
The preamble is the predictor and index the decoder must start from, which is the state as it stands *before* this block's samples, not after.