goertzel-stream
Detects the presence of a single frequency in a stream of signal samples.
example
var goertzel = var Generator = var freq = 697 // Generate a sine wave at 697 Hzvar gen = Generator { if time > 1 return 0 else return Math } // Detection stream looking for the 697 Hz frequencyvar detect = // Pipe the signal into the detectorgen detectdetect
{ '697': { start: 0 } }
{ '697': { start: 0, end: 1 } }
api
var detect = goertzel(freq, opts={})
Returns a WriteStream set to detect frequencies. freq
can be a single number
or an array of frequencies to detect.
opts
is mandatory, and has some required and optional parameters:
opts.sampleRate
(required) - how many samples are taken per second. For best results, this should be at least twice the Nyquist frequency. 2.5x works well.opts.testsPerSecond
(optional) - How many tests for the frequency to perform per second's worth of samples. Defaults to 100.
Now you're ready to pipe in an audio source!
detect.on('toneStart', function (tones) { ... })
Emitted when a tone begins. tones
is an object mapping a frequency to its
start time.
{ '697': { start: 0 } }
detect.on('toneEnd', function (tones) { ... })
Emitted when a detected tone ends. tones
is an object mapping a frequency to
its start time and end time.
{ '697': { start: 0, end: 1 } }
install
With npm installed, run
$ npm install goertzel-stream
license
MIT