Skip to content

Commit 1fddf1b

Browse files
committed
Fix: negative values in exportPeaks
1 parent a4662c5 commit 1fddf1b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/wavesurfer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ class WaveSurfer extends Player<WaveSurferEvents> {
404404
const sampleSize = Math.round(channel.length / maxLength)
405405
for (let i = 0; i < maxLength; i++) {
406406
const sample = channel.slice(i * sampleSize, (i + 1) * sampleSize)
407-
const max = Math.max(...sample)
407+
let max = 0
408+
for (let x = 0; x < sample.length; x++) {
409+
const n = sample[x]
410+
if (Math.abs(n) > Math.abs(max)) max = n
411+
}
408412
data.push(Math.round(max * precision) / precision)
409413
}
410414
peaks.push(data)

src/webaudio.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ class WebAudioPlayer extends EventEmitter<WebAudioPlayerEvents> {
100100
this.emit('pause')
101101
}
102102

103-
stopAt(timeSeconds: number) {
103+
stopAt(timeSeconds: number) {
104104
const delay = timeSeconds - this.currentTime
105105
this.bufferNode?.stop(this.audioContext.currentTime + delay)
106-
107-
this.bufferNode?.addEventListener('ended', () => {
108-
this.bufferNode = null
109-
this.pause()
110-
}, { once: true })
106+
107+
this.bufferNode?.addEventListener(
108+
'ended',
109+
() => {
110+
this.bufferNode = null
111+
this.pause()
112+
},
113+
{ once: true },
114+
)
111115
}
112116

113117
async setSinkId(deviceId: string) {

0 commit comments

Comments
 (0)