testsignal

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT 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 testsignal provides the deterministic pseudo-random and multi-tone generators shared across this project's test suites. It is a normal (non-_test) package so it can be imported from test files in any package, which is exactly why it exists: several test packages used to carry their own copy of the same LCG because Go test files are not importable across packages.

LCG and LCGSigned are golden-pinned: the frozen sha256 goldens in the enc and dec test suites (TestFBGolden, TestMdctGolden, TestHuffmanGolden, TestEncodeGolden, and others) replay these exact sequences byte for byte. The expressions below may never change; doing so would silently change every pinned golden hash and every SNR-floor test that consumes them.

MultiTone calls math.Sin. That is deliberate and safe here: the project's no-math.Sin/Cos-at-runtime rule (see internal/enc/mdcttables.go and fbtables.go, whose coefficient tables are frozen literals for bit-exact output) binds internal/enc's production encode path, not this test-support leaf package. testsignal is imported by _test.go files and by the tools/quality harness (a standalone CLI that measures the encoder against LAME), and never runs on any encode path.

Index

Constants

View Source
const (
	FrameSize         = 1152
	ClickPeriodFrames = 4
	ClickBurstFrames  = 1
)

FrameSize is the MPEG-1 Layer III frame size in samples per channel, and ClickPeriodFrames and ClickBurstFrames are the click cadence both the compat gate and the tools/quality corpus drive block switching with.

FrameSize duplicates the root package's mp3.FrameSize because importing it here would cycle: internal/enc's own in-package tests import this package, and the root mp3 package imports internal/enc. The root's compat_test.go asserts the two stay equal.

Variables

This section is empty.

Functions

func ClickTrain

func ClickTrain(nSamples, periodFrames, burstFrames int) []float32

ClickTrain returns nSamples of mono click-train content: silence with a loud LCG-noise burst (amplitude 0.8, seed 0xC1CC7A31) every periodFrames*FrameSize samples, each burst burstFrames*FrameSize samples long, repeating for the whole duration, the first burst at sample 0. It drives an encoder's attack detector repeatedly; the compat gate's block-switching programs (root compat_test.go) and the tools/quality corpus both consume it, so this is the single source of truth for the float32 click-train program's seed and amplitude. A separate int32 mirror in internal/dec/encx_fuzz_test.go repeats the same constants for the same reason IdenticalNoise's does: a fuzz seed cannot double-round through this float32 helper.

func DecorrelatedNoise

func DecorrelatedNoise(nSamples int) (x, y []float32)

DecorrelatedNoise returns two fully independent noise channels with no shared structure: LCG noise from seeds 0x5EED1 (x) and 0x5EED2 (y), each scaled by 0.5, as float32(LCGSigned * 0.5) exactly. Fed as (x, y) stereo input it exercises whichever per-frame M/S versus L/R decisions the PE rule makes on decorrelated content. Single source of truth for the seeds and scale, on the same terms as IdenticalNoise above.

func FramesForOneSecond

func FramesForOneSecond(sampleRate int) int

FramesForOneSecond returns the smallest number of 1152-sample (the MPEG-1 Layer III frame size) MP3 frames covering at least one second of audio at sampleRate.

func IdenticalNoise

func IdenticalNoise(nSamples int) []float32

IdenticalNoise returns nSamples of the canonical identical-channels noise program: LCG noise from seed 0xC0FFEE scaled by 0.3, as float32(LCGSigned * 0.3) exactly (one float64 multiply, one conversion). Duplicated on both channels of a stereo encode, it forces the M/S decision every frame (the side channel is exactly zero before quantization). This is the single source of truth for the seed and scale of the float32 stereo identical-channels program; TestMsIdenticalChannels (internal/dec) and the M/S compat programs (root compat_test.go) consume it, and the fuzz seed builders in internal/dec/encx_fuzz_test.go mirror the same constants in int32 form (they cannot route through this float32 helper without double-rounding their seed bytes; see the comment there). A separate float64 mono program in encx_roundtrip_test.go reuses the same 0xC0FFEE/0.3 pair for XminScale calibration; it is a different signal and deliberately does not route through this helper.

func LCG

func LCG(seed *uint64) float64

LCG advances the PCG-style linear congruential generator at *seed and returns a pseudo-random float64 in the unit interval [0, 1).

func LCGSigned

func LCGSigned(seed *uint64) float64

LCGSigned advances the same generator as LCG but returns a pseudo-random float64 in the signed interval [-1, 1).

func MultiTone

func MultiTone(sampleRate, nSamples int, chPhase, peak float64) []float64

MultiTone returns nSamples samples of a deterministic multi-tone program: a 440 Hz fundamental plus overtones at -6 dB (880 Hz) and -12 dB (1320 Hz), scaled so |x[i]| <= peak for every i regardless of phase alignment (dividing by the SUM of the three weights bounds the signal pointwise, since |sum of sines| <= sum of amplitudes always; the actual peak, reached only where the three tones align in phase, is <= this bound). chPhase offsets the signal's phase so a second, decorrelated channel can be built by calling this with a different chPhase, rather than duplicating the same samples across channels.

func ToneClick

func ToneClick(sampleRate, nSamples, periodFrames, burstFrames int) []float32

ToneClick returns nSamples of mono tone+click content: a steady MultiTone (peak 0.5) interrupted every periodFrames frames by a genuine onset (576 samples of silence, then an LCG-noise burst of burstFrames frames, seed 0x5A17C1CC, amplitude 0.9), clamped to [-1, 1]. The silence-then-burst shape is what a sub-block energy-ratio attack detector actually fires on: a click merely summed onto a loud tone never clears the ratio. The first burst starts one period in, a true mid-stream onset rather than a stream-start granule. Same single-source-of-truth role as ClickTrain.

Types

This section is empty.

Jump to

Keyboard shortcuts

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