Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exportPeaks is failing with 'Invalid array length' #4018

Open
doctor30309 opened this issue Feb 7, 2025 · 3 comments
Open

exportPeaks is failing with 'Invalid array length' #4018

doctor30309 opened this issue Feb 7, 2025 · 3 comments
Labels

Comments

@doctor30309
Copy link

doctor30309 commented Feb 7, 2025

Bug description

Once the wave file is loaded and the redrawcomplete event is triggered, I call exportPeaks and receive and error generated inside wavesurfer.js. The wav file duration is 82 seconds. It plays as expected.

Environment

  • Browser: Chrome

Minimal code snippet

import WaveSurfer from 'https://cdn.jsdelivr.net/npm/wavesurfer.js@7/dist/wavesurfer.esm.js'

var wavesurfer = WaveSurfer.create({
        container: $(div)[0],
        waveColor: '#FFF',
        progressColor: '#443e3c',
        height: 60,
        /** Stretch the waveform to the full height */
        normalize: true,
        /** The cursor width */
        cursorWidth: 1,
        barWidth: 1,
        barRadius: 3,
        fillParent: true,
        interact: true,
        dragToSeek: true,
        url: compUrl,
    });

wavesurfer.on('redrawcomplete', processWaveReadyEvent);

const peaks = wavesurfer.exportPeaks({
        channels: 2, // how many audio channels to export, defaults to 1
        maxLength: 30000, // how many peaks per channel
        precision: 1e3, // round to 3 digits after comma
    });

Expected result

I would receive a valid array of peaks.

Obtained result

Uncaught (in promise) RangeError: Invalid array length
at u (wavesurfer.esm.js:1:13712)
at h.renderMultiCanvas (wavesurfer.esm.js:1:13967)
at h.renderChannel (wavesurfer.esm.js:1:14957)
at h. (wavesurfer.esm.js:1:16209)
at Generator.next ()
at wavesurfer.esm.js:1:283
at new Promise ()
at t (wavesurfer.esm.js:1:28)
at h.render (wavesurfer.esm.js:1:15005)
at u. (wavesurfer.esm.js:1:26674)

Screenshots

@doctor30309
Copy link
Author

Reopening. Problem occurs on larger wav files. I upped the maxLength to 30000. Had no affect.

The wave file I am trying to load is 14:52 in length. Large wav file.

@doctor30309
Copy link
Author

I jacked up the maxLength to 60000 and got the large file through the process. So the question: if maxLength is supposed to limit how much data is generated in the peak array returned, why does it throw an error if the number of peaks exceeds the maxLength?

@katspaugh
Copy link
Owner

Probably just a bug somewhere here:

https://github.com/katspaugh/wavesurfer.js/blob/main/src/wavesurfer.ts#L528

Likely an off-by-one index going over the channel data size. Perhaps Math.ceil should be Math.floor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants