goertzel

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

goertzel - Golang goertzel tone detection library

This library provides tools for tone detection using the goertzel algorithm. All data is expected to be in 16-bit signed linear format, and there may be hidden assumptions. It was built to service telephony-oriented functionality.

Most users will simply make use of the high-level DetectTone function. However, lower-level block-wise control is available by directly manipulating the Target detector.

Contributing

Contributions welcomed. Changes with tests and descriptive commit messages will get priority handling.

Documentation

Index

Constants

View Source
const (

	// BlockSizeNorthAmerica is the optimum block size for North America progress tones: 350 440 480 620 850 1400 1800 Hz
	BlockSizeNorthAmerica = 183

	// BlockSizeSouthAmerica is the optimum block size for Costa Rica and Brazil: 425Hz
	BlockSizeSouthAmerica = 188

	// BlockSizeUKDisconnect is the optimum block size for UK disconnect tone: 400Hz
	BlockSizeUKDisconnect = 160

	// BlockSizeDTMF is the optimum block size for DTMF detection
	BlockSizeDTMF = 102

	// RateTelephony is the standard telephony rate of 8kHz
	RateTelephony = 8000.0

	// ToneThreshold is the standard threshold for tone detection
	ToneThreshold = 7.8e7
)

Variables

View Source
var BlockBufferSize = 50

BlockBufferSize is the number of blocks to buffer for slow readers, when sending BlockSummaries from Targets

View Source
var ContactIDFrequencies = []float64{1400.0, 2300.0}

ContactIDFrequencies is the list of signaling frequencies used in SIA ContactID

View Source
var DTMFFrequencies = []float64{697.0, 770.0, 852.0, 941.0, 1209.0, 1336.0, 1477.0, 1633.0}

DTMFFrequencies is the list of frequencies used by standard North American DTMF

View Source
var NATelephonyFrequencies = []float64{350.0, 440.0, 480.0, 620.0, 850.0, 1400.0, 1800.0}

NATelephonyFrequencies is the list of common frequencies used in the North American telephony space

Functions

func DetectTone

func DetectTone(ctx context.Context, freq, sampleRate float64, minDuration time.Duration, in io.Reader) (found bool, err error)

DetectTone waits for the given tone to be found, returning with `true` when it is. `false` will be returned if canceled by context or by a stream error/completion.

func DetectToneAbsence

func DetectToneAbsence(ctx context.Context, freq, sampleRate float64, minDuration time.Duration, in io.Reader) (found bool, err error)

DetectToneAbsence waits for the given frequency to go away for the requested amount of time

Types

type BlockSummary

type BlockSummary struct {

	// Magnitude2 is the square of the relative magnitude of the frequency in this block
	Magnitude2 float64

	// Frequency is the frequency which was being detected
	Frequency float64

	// Duration is the elapsed time which this block represents
	Duration time.Duration

	// Samples is the number of samples this block represents
	Samples int

	// Present indicates whether the frequency was found in the block, as determined by the target's threshold
	Present bool
}

BlockSummary describes the result of a single block of processing for a Target frequency

type Target

type Target struct {

	// UseOptimized indicates that an optimized (phase-insensitive) Goertzel should be used for faster arithmetic
	UseOptimized bool

	// Frequency in Hz
	Frequency float64

	// Threshold is the threshold at which this frequency is determined to be present
	Threshold float64

	// Magnitude2 is the square of the magnitude of the last-processed block
	Magnitude2 float64
	// contains filtered or unexported fields
}

Target is a target frequency detector. It is a low-level tool which implements the Goertzel algorithm to detect the presence of a frequency on a block-wise basis.

func NewTarget

func NewTarget(freq, sampleRate float64, minDuration time.Duration) *Target

NewTarget creates a Goertzel processor tuned to the given frequency

func (*Target) Blocks

func (t *Target) Blocks() <-chan *BlockSummary

Blocks returns a channel over which the summary of each resulting block from the Target frequency processor will be returned. If Blocks() has already been called, nil will be returned.

func (*Target) Read

func (t *Target) Read(in io.Reader) error

Read processes incoming samples through the Target goertzel

func (*Target) SetBlockSize

func (t *Target) SetBlockSize(n int)

SetBlockSize overrides automatic calculation of the optimal N (block size) value and uses the one provided instead

func (*Target) Stop

func (t *Target) Stop()

Stop terminates the Target processing. It will close the Events channel and stop processing new data.

Jump to

Keyboard shortcuts

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