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

playback rate / sound pitch #149

Closed
pitrackster opened this issue Mar 20, 2014 · 20 comments
Closed

playback rate / sound pitch #149

pitrackster opened this issue Mar 20, 2014 · 20 comments
Assignees

Comments

@pitrackster
Copy link

Changing playback rate is changing sound pitch.

As this behavior could be needed, sometimes we could need to preserve the original pitch (even with artifacts).

@wolfbiter
Copy link
Contributor

isn't pitch-independent tempo shift a difficult process requiring FFT's? i think this is something webaudio needs as a whole. once it does it'll implicitly be in wavesurfer.

@wnayes
Copy link

wnayes commented Jun 25, 2014

I would find this feature very useful, and it seems to me like it may already be partially finished. The README states that setPlaybackRate is an available method, but it currently is not present on the wavesurfer object. I've attempted to call wavesurfer.backend.setPlaybackRate; this changes the playback rate but also seems to jump the current position line to an incorrect position.

@katspaugh
Copy link
Owner

@wnayes, looks like a bug. We need to scale the position too. And update the setPlaybackRate docs. Thanks for noticing.

@yoyomo
Copy link

yoyomo commented Jul 29, 2016

It seems everyone has ignored the OP's problem.

Changing playback rate is changing sound pitch.

we don't want that. HTML5 tag can neatly do this without changing pitch.

@sprycoder
Copy link

First of all Thanks to team for creating such a useful component for audio.

I am using it for my project and its really easy to use. But I'm disappointed by the change in sound pitch after increasing playbackRate. I tried with waveSufer.setPlaybackRate, waveSurfer.backend.setPlaybackRate and other few options.

Is it still an open bug or I have to do it different way?

@samedayjeremy
Copy link

I'd also be interested in this feature.

@katspaugh
Copy link
Owner

I'll need to do some research on this.

@katspaugh katspaugh self-assigned this Dec 15, 2016
@jsphweid
Copy link

@katspaugh I've been looking into this and wanted to present this to you.

Someone created a javascript version of the famous open-source soundtouch libraries years ago and I used it to create this plunker..

I'm no expert on the Web Audio API and cannot figure out how to integrate it smoothly with your fantastic library. This creates a script processing node and I figured you could just connect it in to your context. Obviously it's more complicated than that; I don't know how to make it work with play and pause OR getting things to line up with different playback rates.

Does this look promising?

@jsphweid
Copy link

@katspaugh Sorry, I can't stop playing around with this.

First off, I made somewhat of a working version with time-stretch preserve pitch: current website & GitHub repo.

But just to summarize, changes to WebAudio js file -> https://www.diffnow.com/?report=w2vuc
It's kind of a mess, I know. But it works mostly well for my purposes. Assumes 2 channel audio (although I just fixed that on my site).

To be honest, I wonder if a lot of this is going to change when they stop supporting script processor nodes (https://webaudio.github.io/web-audio-api/#idl-def-ScriptProcessorNode) in favor of AudioWorklet nodes.

@katspaugh
Copy link
Owner

@jsphweid if you are willing to finish this (and create a PR), I know @jeremylach is ready to sponsor this feature.

@samedayjeremy
Copy link

Yes, a bounty can be arranged for this feature.

@jsphweid
Copy link

Ok, well I finally just finished my web-app that uses it but it looks really messy. I guess the best way to approach this would be to package up the SoundTouch files into a singular object and redo my changes as to not touch WaveSurfer.js, and extend it like a plugin or something.

Honestly, I'm not that great at this sort of thing but I'll give it a try soon.

@samedayjeremy
Copy link

@jsphweid Have you done any more work on this?

@jsphweid
Copy link

@jeremylach I'm afraid not. I'm too green in DSP to code this at the moment. Don't count on me :/

@kaicarver
Copy link

kaicarver commented Jun 25, 2017

I also want to change rate while preserving pitch, and FYI I just found a way to do it with wavesurfer.js: just specify this initialization option in the create() call: backend: 'MediaElement'.

I can't be the only person stymied and baffled by the differences between the HTML <audio> element and the Web Audio API. By default, wavesurfer uses WebAudio as a backend, but if I understand correctly this option tells it to use the <audio> element instead.

With my luck this will break or make impossible other wavesurfer features that work fine only with Web Audio, so I foresee tears in the future... but for the time being this looks like an ok kludgy workaround way to change rate while preserving pitch.

@samedayjeremy
Copy link

This does work @kaicarver however MediaElement does cause other bugs I've noticed.

@fxmarty
Copy link

fxmarty commented Oct 20, 2020

Using MediaElement as a backend seems okay, however I don't really know the difference with WebAudio, but it feels globally not as smooth as WebAudio is with autocenter and scroll.

@sundayz
Copy link
Contributor

sundayz commented Oct 20, 2020

MediaElement backend uses https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement which has the "preservesPitch" option. Changing tempo in WebAudio works differently

@ClemSK
Copy link

ClemSK commented May 15, 2022

I also want to change rate while preserving pitch, and FYI I just found a way to do it with wavesurfer.js: just specify this initialization option in the create() call: backend: 'MediaElement'.

I can't be the only person stymied and baffled by the differences between the HTML <audio> element and the Web Audio API. By default, wavesurfer uses WebAudio as a backend, but if I understand correctly this option tells it to use the <audio> element instead.

With my luck this will break or make impossible other wavesurfer features that work fine only with Web Audio, so I foresee tears in the future... but for the time being this looks like an ok kludgy workaround way to change rate while preserving pitch.

I've used the MediaElement and it solves both the pitch-shifting and playback 'jumping' when toggling playback rate. Overall the HTML5 element is superior to the WabAudio API for delivering functionality. FYI as mentioned in another issue - I recommend setting partialRender: False as the MediaElement didn't render the wave if set to True in my case.

@ruchaheda
Copy link

Thank you for this discussion!

I am using WebAudio for my application with the wavesurfer API because, if I use MediaElement, the regions that I've created sometimes shift on load onto the track. For example, I have a ~40min track, and I find that there are certain regions that are consistently off by ~15seconds from when I initially created them. I confirmed that my file has a constant bit rate (after reading this thread). My understanding is that WebAudio is better to use for more granular interactions on the audio file.

Is there any way that I could continue to use WebAudio and also change the playback rate while preserving pitch?

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

No branches or pull requests