AudioWatermarkerBase<T>
Base Classes · AiDotNet.Safety.Watermarking
Abstract base class for keyed audio watermarkers that mark the block-DCT spectrum of the audio with a pattern derived from a secret key, and detect it by correlation.
Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → AudioSafetyModuleBase<T> → AudioWatermarkerBase<T>
Implements: IAudioWatermarker<T>, IKeyedWatermarker
Known derived types: AudioSealWatermarker<T>, AudioWatermarker<T>, SpectralAudioWatermarker<T>
For Beginners
This base class provides common code for all audio watermarkers. The key works like a password: the watermark is a faint pattern spread over thousands of frequency values, too weak to hear in any one place, which adds up to strong evidence for whoever knows the exact pattern.
How It Works
The audio is cut into non-overlapping frames of about 32 ms (the smallest power of two of at least
0.032 x sample rate samples: 512 at 16 kHz, 2048 at 44.1 or 48 kHz). Each frame is transformed with the
orthonormal DCT-II, and the coefficients inside the watermark band (BandLowHz to
BandHighHz, clipped to the Nyquist frequency) are modified by the derived watermarker under the key’s
+/-1 pattern for that frame (SignPattern, one stream per frame). The inverse DCT gives the
marked frame back; samples after the last full frame are left as they are.
Detection computes, per frame, key-independent weights w_k from the received band coefficients
(DetectionWeights) and the correlation z = sum(w_k x_k) / sqrt(sum(w_k^2)) over all frames. Because
the weights do not depend on the key and the pattern bits are fair and independent, z is approximately standard
normal for audio without this key’s mark, whatever the audio is. The confidence is 0 up to z = 3 (false-positive
rate 0.135%) and 1 from z = 6; EvaluateAudio reports from ReportThreshold.
EmbedWatermark checks the result: if the marked audio does not reach z = 6 (too short, silent, or too
low a strength), it throws instead of returning audio that would not be recognised. Frames are aligned to the
first sample, so the mark survives noise, re-quantization and gain changes, but not cropping or time shifts that
move the frame grid.
Properties
| Property | Summary |
|---|---|
bool UsesPublicKey { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<SafetyFinding> EvaluateAudio(Vector<T> audioSamples, int sampleRate) |
|
Vector<T> EmbedWatermark(Vector<T> audioSamples, int sampleRate) |
|
WatermarkResult Detect(Vector<T> audioSamples, int sampleRate) |
Detects this watermarker’s keyed watermark and reports the correlation test behind the confidence. |
double DetectWatermark(Vector<T> audioSamples, int sampleRate) |