Skip to content

resample from and to options #50

@germain-gg

Description

@germain-gg

I have recently started playing around with this library. I have generated a .dat file using the CLI tool with the following command

audiowaveform -i audio.mp3 -o audio.dat -z 256 -b 8

My audio file length is approximately 10 minutes. And I used the resample method to be able to draw a scaled visualisation in an HTML5 Canvas.

Reading through the documentation I noticed two options from and to that can be passed to that method in an options object. However I could not get this to work.

Check the documentation for WaveformData#resample

fetch('audio.mp3')
  .then(response => response.arrayBuffer())
  .then(buffer => {
    const waveform = WaveformData.create(buffer);
    const resampled = waveform.resample({
      width: 500,
      from: 10,
      to: 20
    });
  });

My understanding of those two attributes is that it would return a WaveFormData object from/to a specific time within the audio file (i.e. I want to get my audio sample from second 10 to second 20 and scale them so that they can be drawn on a 500px wide canvas)

After digging in the source code, I could see no reference to from or to in lib/core.js. I'm not sure whether this is still relevant?

I am wondering what would be the right approach using waveform-data.js to achieve what I'd like to do?

I'm happy to PR the documentation updates as needed.

Thank you again for open sourcing this project 💯

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions