Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.47k stars 977 forks source link

Sampler pitch transition to PitchShift? #105

Closed JackCA closed 8 years ago

JackCA commented 8 years ago

I'm really enjoying the r6 release so far. Great work!

But I was wondering something: Should the Sampler instrument start utilizing the PitchShift effect for its pitch attribute? It currently modifies the playback rate but it seems that PitchShift would be the better move now...

Are there any drawbacks here? Happy to implement if you think it's a good idea.

tambien commented 8 years ago

awesome thanks!

The advantage of using PitchShift over the current playbackRate implementation would be that the duration of the original sample is maintained and the pitch is changed independently.

I can see couple downsides though: first is performance (though i'm happy to give a little on performance in exchange for something that works a lot better). Adding a PitchShift would add a bunch of components to an otherwise pretty lean Sampler.

Also, the real-time pitch shifter uses a very different mechanism for changing the pitch based on ramping delay times. I think it's a cool effect because it adds all kinds of interesting qualities to the input, but it's not as straightforward or objective as just changing the playback rate. Plus it gets pretty crazy on anything above an octave (also it doesn't pitch down as well as it pitches up in my experience).

I appreciate the idea, but I think in this case, simpler is better.

On a side note, i'm super interested in exploring granular synthesis to do pitch shifting and time stretching. That would be yet another approach to add to Tone.

JackCA commented 8 years ago

@tambien thanks for the thorough followup -- totally understand that PitchShift would make the Sampler potentially a little too heavy.

PitchShift opens up a lot of great sampling opportunities so I went ahead and implemented my own custom Instrument that is just a Player --> PitchShift --> AmplitudeEnvelope chain. I had to drastically reduce the Polyphony of my PolySynth but it was worth it because the PitchEffect has such a great output.

re: granular synthesis: very :sunglasses:

joshkpeterson commented 8 years ago

@JackCA I was about to make the instrument you just described, do you have that up anywhere? :)

JackCA commented 8 years ago

@joshkpeterson here's a cut and paste of what I'm using. It's ES6 and I'm importing another library but you should be able to see what I'm doing to make it work

joshkpeterson commented 8 years ago

@JackCA Amazing! Thank you!