Skip to content

Commit

Permalink
Remove the concept of a register/processor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Titcomb committed Mar 1, 2016
1 parent 9a0a138 commit 2086884
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 49 deletions.
22 changes: 9 additions & 13 deletions build/dtmf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 10 additions & 19 deletions build/goertzel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "goertzeljs",
"version": "2.0.0",
"version": "3.0.0",
"description": "A pure JavaScript implementation of the Goertzel algorithm.",
"main": "build/goertzel.js",
"scripts": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"coffee-script": "^1.10.0",
"finalhandler": "^0.4.1",
"jasmine": "^2.4.1",
"jasmine-expect": "^2.0.2",
"jasmine-node": "^1.14.5",
"serve-static": "^1.10.2"
}
Expand Down
16 changes: 7 additions & 9 deletions src/dtmf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class DTMF
return @frequencyTable[lowFrequency][highFrequency] or null
return

floatBufferToInt: (floatBuffer) ->
intBuffer = []
i = 0
while i < floatBuffer.length
intBuffer.push Goertzel.Utilities.floatToIntSample(floatBuffer[i])
i++
intBuffer

processBuffer: (buffer) ->
value = ''
intSample = undefined
Expand All @@ -79,6 +71,7 @@ class DTMF
highEnergies = []
lowEnergies = []
frequency = undefined
result = []
# Downsample by choosing every Nth sample.
i = 0
while i < buffer.length
Expand All @@ -104,13 +97,18 @@ class DTMF
if value == @firstPreviousValue and value != undefined
@repeatCounter += 1
if @repeatCounter == @repeatMin
result.push value
for handler in @decodeHandlers
setTimeout handler(value), 0
else
@repeatCounter = 0
@firstPreviousValue = value
@goertzel.refresh()
result

on: (eventName, handler) ->
switch eventName
when "decode" then @decodeHandlers.push(handler)
when "decode" then @decodeHandlers.push(handler)


module.exports = DTMF if module?.exports
16 changes: 9 additions & 7 deletions src/goertzel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Goertzel
@frequencies = options.frequencies
@refresh()

refresh: () ->
refresh: ->
## Re-initializes Goertzel when we are taking in a new buffer
@[attr] = {} for attr in ['firstPrevious', 'secondPrevious', 'totalPower', 'filterLength', 'energies']
@_initializeCoefficients(@frequencies) unless @coefficient
Expand All @@ -18,12 +18,6 @@ class Goertzel
@_getEnergyOfFrequency sample, frequency
@ # returning self would be most useful here

max: ->
max = undefined
for frequency in @frequencies
if max == undefined
max = {frequency: frequency, energy: @energies[frequency]}

## private
_getEnergyOfFrequency: (sample, frequency) ->
## Main algorithm
Expand Down Expand Up @@ -115,4 +109,12 @@ class Goertzel
i++
buffer

floatBufferToInt: (floatBuffer) ->
intBuffer = []
i = 0
while i < floatBuffer.length
intBuffer.push Goertzel.Utilities.floatToIntSample(floatBuffer[i])
i++
intBuffer

module.exports = Goertzel if module?.exports

0 comments on commit 2086884

Please sign in to comment.