Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript pitch shift with time stretch

I'm a beginner learning javascript. I've got various projects in mind with an interactive page on my site related to microtonal frequencies and planetary frequencies. I need to be able to play my audio sample .wav file in a loop but have the audio sample timestretched with a corresponding change in pitch.

I tried myAudio.playbackRate = 0.5; which plays the audio 0.5 slower but keeps pitch same. I researched and found something. But how do i set preservesPitch to false or true? And this only works in 'Google Chrome' I think, so other program i found is here :
https://github.com/janesconference/KievII/blob/master/dsp/pitchshift.js

Can't seem to get it working, i don't know how i am supposed to modify it, where do i paste my Audio .wav file URL in the program ? Any other tips related to this would be much appreciated. Thanks in advance for your time and help.

like image 997
GooseCode Avatar asked Aug 06 '14 10:08

GooseCode


People also ask

Does time stretching change the key?

In audio production, time stretching refers to a form of audio processing that extends or contracts the duration of a sample or sound without changing its pitch or tonal characteristics.

What is time Stretch sound quality?

Time stretching is the process of changing the speed or duration of an audio signal without affecting its pitch. Pitch scaling is the opposite: the process of changing the pitch without affecting the speed. Pitch shift is pitch scaling implemented in an effects unit and intended for live performance.

What is time stretch in Daw?

This function allows you to change the length and tempo of the selected audio without affecting the pitch. The available options are: Define Bars section. If you use the tempo setting, you can set the length of the selected audio and the time signature in this section.


1 Answers

you can set the mozPreservesPitch property to false to change the pitch of an element or soundfile with Firefox. webkitPreservesPitch is supposed to work with webkit browsers but note that "this API is not yet standardized" ...

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

This worked for me:

var soundPlayer = new Audio();

function playLowerNote() {
    soundPlayer.src = "piano.mp3";
    soundPlayer.mozPreservesPitch = false;
    soundPlayer.playbackRate = 0.5;
    soundPlayer.play();
}

playLowerNote();

Still looking myself for a better way to loop.

like image 149
shootTheLuck Avatar answered Sep 19 '22 06:09

shootTheLuck