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

Combining multiple waveforms #48

Open
edsilv opened this issue Jul 18, 2018 · 11 comments
Open

Combining multiple waveforms #48

edsilv opened this issue Jul 18, 2018 · 11 comments

Comments

@edsilv
Copy link

edsilv commented Jul 18, 2018

Hi,

I'm currently working on the British Library's Save our Sounds project. We have a use case where we need to combine multiple separate waveforms into a single zoomable waveform on the client-side. Do you know of any examples of the best way to do this? Here's my current attempt:

https://github.com/edsilv/peaksjs-test/blob/gh-pages/multi-waveform.html

However this is crashing Chrome when certain durations are selected.

I'm pretty sure I'm approaching this naively, and need to be using something like resample?

Any pointers greatly appreciated....

@chrisn
Copy link
Member

chrisn commented Jul 18, 2018

Is your goal to concatenate several separate waveforms into one? Do you need to be able to synchronise the visuals with the audio playback (e.g, scroll the waveform or update a playback position marker)? Save our Sounds is a great project, by the way!

@edsilv
Copy link
Author

edsilv commented Jul 18, 2018

Hi Chris,

Thank you for the fast reply, and for this awesome library.

Yes, we've got multiple .dat files - each representing a distinct recording per "manifest", e.g. a tape that is one logical item, but has a distinct recording for each side.

We need to be able to show a combined waveform visualisation for both sides of a tape, that can also be zoomed to a given offset.

Right now (although it may be a requirement in future) there's no requirement to update a playback position marker or scroll the waveform.

Because of the way things are set up on the server side, it's necessary to concatenate the waveforms on the client. I tried combining the byte arrays into a single one in javascript, but couldn't get that to work. So then attempted to split the canvas into separate regions and draw each part individually.

The designs show that I need to draw it in such a way that it's segmented into separate bars rather than a continuous line. I think I've pretty much figured that out.

I'm running into this chrome crashing bug, and feel like I may be barking up the wrong tree with this approach...

@chrisn
Copy link
Member

chrisn commented Jul 19, 2018

I think the way I'd approach this is:

  • Create a WaveformData object for each of the waveforms, i.e., resolve(WaveformData.create(progressEvent.target.response)); in your get(url) function
  • Resample each of those WaveformData objects to your desired zoom level (samples per pixel)
  • Create an abstraction that allows you to treat this collection of waveforms as a single logical array of data points
  • Change the rendering code to use this new abstraction

@edsilv
Copy link
Author

edsilv commented Jul 19, 2018

Sounds good, will give it a try. Many thanks!

@edsilv
Copy link
Author

edsilv commented Jul 23, 2018

I altered your approach slightly to allow drawing ranges within the composite waveform:

https://edsilv.github.io/peaksjs-test/multi-waveform.html

This makes for quite a boring waveform though when zoomed out :-) Is there a way to improve how the peaks are getting averaged out so that they're more "peaky"?

@edsilv
Copy link
Author

edsilv commented Jul 24, 2018

https://edsilv.github.io/peaksjs-test/multi-waveform.html

I made the sample size in getMaxAndMin constant (canvas.width / barSpacing)

Seems to have done the trick!

@chrisn
Copy link
Member

chrisn commented Jul 24, 2018

Looks good! Do you mind if I use this in Peaks.js? I'd like to offer a way to allow users to customise the waveform rendering, and this would be a nice example.

@edsilv
Copy link
Author

edsilv commented Jul 24, 2018 via email

@loretoparisi
Copy link

loretoparisi commented Jul 31, 2018

@edsilv you curious, assumed that you combine two audio waveforms of the same tape, what is the advantage to have them combined together instead of having them separated but in the same visualization, so that the waveforms can be compared? Maybe I'm misunderstood your need, I'm asking 'cause I'm using peaks.js for the same thing.
Thank you!

@edsilv
Copy link
Author

edsilv commented Aug 1, 2018

@loretoparisi Hey, it was just to make it easier for the back-end guys who only had .dat files for individual sides of tape as opposed to the entire recording. Their viewer (universalviewer.io) needs to show individual sides of tape with their waveform, and both sides stiched together with a stiched-together waveform.

@davidturissini
Copy link
Contributor

FWIW this is also the approach i used to make a streaming-compatible waveform. Just make a container that holds other waveforms

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

No branches or pull requests

4 participants