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 ¶
func Decode ¶
Decode expands one DVI4 block. It exists so the encoder can be tested against a decoder that shares no code with it beyond the two tables.
func DecodeStream ¶ added in v0.2.3
DecodeStream is EncodeStream's inverse, for tests and checks.
func EncodeStream ¶ added in v0.2.3
EncodeStream encodes pcm as one continuous run of codes, two per byte, the FIRST sample in the HIGH nibble, starting from silence, with no block preambles. This is the custom siren sound format (import audio, 261): the Reolink app's own upload decodes cleanly this way and drifts the other way, the opposite nibble order to a talk block.
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.