Skip to content

Commit

Permalink
slicer: rename "transients" to "peaks" as this reflects the truth better
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Oct 19, 2015
1 parent c8c44c3 commit 0e0688c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
16 changes: 7 additions & 9 deletions lib/detect-transients.js → lib/detect-peaks.js
@@ -1,8 +1,7 @@
module.exports = function (data, count, offset) {
offset = offset || [0,1]
offset = offset || [0, 1]


var range = (offset[1]-offset[0]) * data.length
var range = (offset[1] - offset[0]) * data.length
var step = Math.ceil(range / (count * 2))
var start = Math.floor(offset[0] * data.length)
var end = Math.ceil(offset[1] * data.length)
Expand All @@ -15,15 +14,15 @@ module.exports = function (data, count, offset) {

for (var pos = start + step; pos < end; pos += step) {
var peak = getPeak(data, pos, frame)
if (peak[0] > peaks[peaks.length-1][0]) {
if (peak[0] > peaks[peaks.length - 1][0]) {
peaks.push(peak)
}
}

var peaks = peaks.sort(function (a, b) {
return a[1]-b[1]
}).slice(-count).sort(function (a,b) {
return a[0]-b[0]
peaks = peaks.sort(function (a, b) {
return a[1] - b[1]
}).slice(-count).sort(function (a, b) {
return a[0] - b[0]
})

return peaks.map(function (item) {
Expand All @@ -39,7 +38,6 @@ function getPeak (data, offset, length) {
var lastCross = pos

for (var i = offset; i < end; i++) {

if (data[i] === 0 || (i - lastCross > 128 && data[i] < 0.01 && data[i] > -0.01)) {
lastCross = i
}
Expand Down
8 changes: 4 additions & 4 deletions nodes/slicer-chunk/object.js
Expand Up @@ -9,7 +9,7 @@ var lookup = require('observ-node-array/lookup')
var computed = require('observ/computed')
var computedNextTick = require('lib/computed-next-tick')
var ResolvedValue = require('observ-node-array/resolved-value')
var detectTransients = require('lib/detect-transients')
var detectPeaks = require('lib/detect-peaks')
var throttle = require('throttle-observ')
var throttleWatch = require('throttle-observ/watch')
var extend = require('xtend')
Expand Down Expand Up @@ -41,11 +41,11 @@ function SlicerChunk (parentContext) {
obs.sample.slices = computedNextTick([obs.shape, obs.sample.resolvedBuffer, throttle(obs.sample.offset, 1000), obs.sliceMode, obs.sample.mode], function (shape, buffer, offset, sliceMode, triggerMode) {
var count = shape[0] * shape[1]
var playToEnd = triggerMode === 'full'
if (sliceMode === 'transient') {
if (sliceMode === 'peak' || sliceMode === 'transient') {
if (buffer) {
var data = buffer.getChannelData(0)
var transients = detectTransients(data, count, offset)
return sliceOffsets(transients, offset, playToEnd)
var peaks = detectPeaks(data, count, offset)
return sliceOffsets(peaks, offset, playToEnd)
}
}
return divideSlices(count, offset, playToEnd)
Expand Down
2 changes: 1 addition & 1 deletion nodes/slicer-chunk/view.js
Expand Up @@ -13,7 +13,7 @@ var renderEqParams = require('../eq/params')

var sliceOptions = [
['Equal Slices', 'divide'],
['Use Transients', 'transient']
['Use Peaks', 'peak']
]

var triggerOptions = [
Expand Down

0 comments on commit 0e0688c

Please sign in to comment.