adpcm

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const BlockBytes = 4 + SamplesPerBlock/2

BlockBytes is the encoded size of one block: a 4 byte preamble and one nibble per sample.

View Source
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

func Decode(block []byte) []int16

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.

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

func (e *Encoder) EncodeBlock(pcm []int16) []byte

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL