Help us shape the future of Go! Take the 2026 Go Developer Survey

ancearbuds

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 1 Imported by: 0

README

ancearbuds

Model active noise cancellation in true wireless earbuds — what it removes, what it cannot, and what it costs in battery life.

Install

go get github.com/taysirco/ancearbuds

Usage

import "github.com/taysirco/ancearbuds"

e := ancearbuds.Earbuds{
    ANC:             ancearbuds.Hybrid,
    Fit:             ancearbuds.GoodSeal,
    RatedHoursNoANC: 10,
}

e.ReductionAtDB(100)   // strong — aircraft drone is what ANC is for
e.ReductionAtDB(2000)  // much weaker — speech is not
e.PlaybackHours()      // 7 — hybrid ANC costs about 30% of playback time

// A well-sealed budget pair can beat a poorly-fitted flagship at 3kHz
flagship := ancearbuds.Earbuds{ANC: ancearbuds.Hybrid, Fit: ancearbuds.PoorSeal}
budget   := ancearbuds.Earbuds{ANC: ancearbuds.Feedforward, Fit: ancearbuds.FoamSeal}
ancearbuds.BetterAgainst(3000, flagship, budget)   // "b"

Why fit matters as much as the chip

ANC inverts an incoming waveform and plays the inverse back so the two cancel. That requires predicting the waveform, which works well for steady low-frequency sound — engine drone, air conditioning, train rumble — and poorly for sudden high-frequency sound like speech or a slamming door.

Passive isolation from the ear tip covers the opposite end of the spectrum: weak in the bass, strong in the treble. The two are complementary, which is why a poorly sealed flagship can be outperformed by a well-sealed budget pair against voices — the electronics never get the chance to matter.

Calibration

Attenuation figures and battery penalties are approximations calibrated against manufacturer datasheets. Where a datasheet was vague about ANC-on runtime, I cross-checked retail spec tables such as these Soundcore listings, which publish both figures separately.

License

MIT

Documentation

Overview

Package ancearbuds models active noise cancellation in true wireless earbuds: what it can physically remove, what it cannot, and what it costs in battery.

ANC works by inverting an incoming waveform and playing the inverse back, so the two cancel. That works well for predictable low-frequency sound and poorly for sudden high-frequency sound, because the system cannot model what it cannot anticipate. Passive isolation from the ear tip covers the opposite end of the spectrum, which is why fit matters as much as the electronics.

Reference model data used to validate this package is published at https://cairovolt.com/en/soundcore/audio

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BetterAgainst

func BetterAgainst(hz float64, a, b Earbuds) string

BetterAgainst reports which of two configurations attenuates more at a frequency, returning "a", "b" or "equal".

Types

type ANCType

type ANCType int

ANCType is the microphone arrangement used for cancellation.

const (
	// None means no active cancellation, passive isolation only.
	None ANCType = iota
	// Feedforward places the microphone outside the earbud.
	Feedforward
	// Feedback places the microphone inside the ear canal.
	Feedback
	// Hybrid combines both and is what most premium models ship.
	Hybrid
)

func (ANCType) BatteryPenalty

func (a ANCType) BatteryPenalty() float64

BatteryPenalty is the fraction of playback time lost when ANC runs.

func (ANCType) MaxReductionDB

func (a ANCType) MaxReductionDB() float64

MaxReductionDB is a representative peak attenuation for the arrangement, measured against steady low-frequency noise.

func (ANCType) String

func (a ANCType) String() string

type Earbuds

type Earbuds struct {
	ANC             ANCType
	Fit             Fit
	RatedHoursNoANC float64
}

Earbuds combines the electronics and the physical seal.

func (Earbuds) PlaybackHours

func (e Earbuds) PlaybackHours() float64

PlaybackHours returns expected playback time with ANC enabled.

func (Earbuds) ReductionAtDB

func (e Earbuds) ReductionAtDB(hz float64) float64

ReductionAtDB estimates total attenuation at a given frequency in hertz.

ANC effectiveness falls off sharply above a few hundred hertz because the system cannot invert fast, unpredictable waveforms in time. Passive isolation does the opposite: it is weak in the bass and strong in the treble.

type Fit

type Fit int

Fit describes how well the ear tip seals, which governs passive isolation.

const (
	// PoorSeal leaks audibly and undermines both passive and active performance.
	PoorSeal Fit = iota
	// GoodSeal is a correctly sized tip.
	GoodSeal
	// FoamSeal is memory foam, the best passive isolator.
	FoamSeal
)

func (Fit) PassiveReductionDB

func (f Fit) PassiveReductionDB() float64

PassiveReductionDB is the attenuation the seal provides without electronics.

Jump to

Keyboard shortcuts

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