WebAudio API: Change pitch of samples (for example mp3)

主宰稳场 提交于 2019-12-12 02:44:32

问题


I figured I can stretch a sample using playbackRate but how do I set the pitch? Im trying to achieve this without using any libraries.

I found something about a doppler pitch effect in the specification but other than that I couldnt find anything truly relevant to my objective. Just a simple pitch shift, is this even possible? If so then how?

Edit: Could it be that playbackRate changes the pitch as well but the browser applies some sort of correction? I think this might be the case. I have to disable it then if that is the case and possible.


回答1:


There is no "simple" pitch shift for samples. There are lots of ways to change the pitch without changing the playback rate - granular resynthesis, phase-shift vocoding - but none of them are trivial, and none are baked into the Web Audio API. (Doppler is being removed, by the way, since it was pretty hacky.) playbackRate is literally the rate at which the samples will be run through - which will affect both "speed" and apparent pitch (of pitched samples).

I implemented a pitch-shifting (granular resynthesis) effect in the Input Effects demo - using the jungle.js library - but this isn't a trivial thing to do. HTML's <audio> element does stretching, but doesn't specify the algorithm, which leaves it open to a lot of interpretations.



来源:https://stackoverflow.com/questions/34476612/webaudio-api-change-pitch-of-samples-for-example-mp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!