changing pitch of audio samples - TeensyVariablePlayback library

wow, great work everyone!
Hi Nic. As noted, I'm going to be out of circulation for a while, but is it worth considering merging my changes to your repo, either in the master branch or at least on a separate branch? At one point I think I got pretty divergent, but I did then start trying to get back to something closer to your API, e.g. removing the warnings, and changing the interpolation data stuff ... I can re-address that, can't remember where I left it.
 
  • Like
Reactions: Moo
Hey Johnathan. I am more than happy if you want to merge your changes to the master or any other branches. I think you have put more love into this library than anyone.

I have branched master to old_master, just in case. you can merge you fork to master. Don’t worry about keeping the api. People who wish to use it like it is can use the old_master branch.
 
@reso I found this YouTube video which I think is explaining the live pitch shifting algorithm, which is just a slightly different approach.
 
Hey Johnathan. I am more than happy if you want to merge your changes to the master or any other branches. I think you have put more love into this library than anyone.

I have branched master to old_master, just in case. you can merge you fork to master. Don’t worry about keeping the api. People who wish to use it like it is can use the old_master branch.
Not sure about that, it's your baby originally!

OK, thanks ... I'll give it a go and do a PR - probably sometime mid to late November.
 
  • Like
Reactions: Moo
OK, so quite a bit later than advertised, but I've made some progress. Prior to doing a PR I want to sort out an example showing how to access the SD card while streaming audio from it, and update various bits of documentation, but the current state of things can be found at https://github.com/h4yn0nnym0u5e/teensy-variable-playback/tree/dev/h4y/trunk. I believe it's working from at least SD, LittleFS and in-memory arrays, with variable speed, interpolation, cross-fading and looping all OK.

One new example I've added is a piano player, along the lines of the PlaySynthMusic example, but using 9 stereo samples made at 6-semitone intervals, and then changing the playback rate to shift each one between -3 and +2 semitones to re-create a full 4-octave chromatic capability. At 5-note polyphony it registers just over 9% CPU, though this will be an underestimate as the SD card accesses don't occur inside the audio update.

As ever, if you find an issue, please post complete code I can drop into the Arduino IDE to reproduce it :)
 
OK, so quite a bit later than advertised, but I've made some progress. Prior to doing a PR I want to sort out an example showing how to access the SD card while streaming audio from it, and update various bits of documentation, but the current state of things can be found at https://github.com/h4yn0nnym0u5e/teensy-variable-playback/tree/dev/h4y/trunk. I believe it's working from at least SD, LittleFS and in-memory arrays, with variable speed, interpolation, cross-fading and looping all OK.

One new example I've added is a piano player, along the lines of the PlaySynthMusic example, but using 9 stereo samples made at 6-semitone intervals, and then changing the playback rate to shift each one between -3 and +2 semitones to re-create a full 4-octave chromatic capability. At 5-note polyphony it registers just over 9% CPU, though this will be an underestimate as the SD card accesses don't occur inside the audio update.

As ever, if you find an issue, please post complete code I can drop into the Arduino IDE to reproduce it :)
Thanks! This is going to be perfect for my next project. Will let you know once is tested.
 
Great, there’s nothing like independent testing for finding the bugs! Well, and automated regression tests, which I can see in there but need to figure out how to execute…

The repo now has a file access example, which shows the hoops you need to jump through to e.g. read in presets or load samples to memory while playback is active. It’s a bit tedious, but imposed by the structure of existing libraries so you just have to grit your teeth and do it.
 
Hello,

I am new on Teensy 4.0 and try to use the TeensyVariablePlayback library.
My goal is to use a PWM output on pin 3.
Our code is running but I have a background noise and I don't understand where is my issue.
It's my 4.0 who has a problem or just an incompatibility with the PWM mode.
Officially, the 4.0 don't accept a PWM output but in reality, I have a sound on the pin 3.
I use just a 100nF capacitor between pin3 and my 2w amplifier.
This is my configuration:
AudioPlaySdResmp playSdWav1; //xy=366,280
AudioPlaySdWav playSdWav2;
AudioPlaySdWav playSdWav3;
AudioMixer4 mixer1; //xy=607,308
AudioMixer4 mixer2; //xy=621,439
AudioEffectFade fade2; //xy=807,488
AudioMixer4 mixer3; //xy=824,364
AudioMixer4 mixer4; //xy=824,364
AudioEffectFade fade1; //xy=827,276
AudioOutputPWM audioOutput; //xy=1089,357 (pwm)
AudioConnection patchCord1(FX[0].SDWav, 0, mixer2, 0);
AudioConnection patchCord2(FX[1].SDWav, 1, mixer2, 3);
AudioConnection patchCord3(FX[2].SDWav, 0, mixer2, 1);
AudioConnection patchCord4(FX[3].SDWav, 1, mixer2, 2);
AudioConnection patchCord5(playSdWav1, 0, mixer1, 1);
AudioConnection patchCord6(playSdWav1, 1, mixer1, 3);
AudioConnection patchCord7(ENGINE[0].SDWav, 0, mixer1, 0);
AudioConnection patchCord8(ENGINE[0].SDWav, 1, mixer1, 2);
AudioConnection patchCord9(mixer1, fade1);
AudioConnection patchCord10(mixer2, fade2);
AudioConnection patchCord11(fade2, 0, mixer3, 3);
AudioConnection patchCord12(mixer3, 0, audioOutput, 0);
AudioConnection patchCord13(mixer3, 0, audioOutput, 1);
AudioConnection patchCord14(fade1, 0, mixer3, 0);
Thanks for your help,

Pierre
 
This is my configuration:
...followed by a snapshot of your audio configuration ... with all sorts of mystery arrays ... definitely not fulfilling
As ever, if you find an issue, please post complete code I can drop into the Arduino IDE to reproduce it :)
Yes, the Design Tool documentation isn't what you'd call well-maintained: PWM output is an option for Teensy 4.x. The recommended output hardware is documented in the info pane thus:
1738578936459.png

Doesn't sound like you've done this, so I'm not massively surprised you're having issues. Just using pin 3 will certainly degrade your output quality.

Make a test sketch generating a simple sine wave to eliminate all other sources of "background noise".

It's hard to see that this is in any way related to your use of the TeensyVariablePlayback library, but I would recommend you make all your playback objects be AudioPlaySdResmp, as mixing those with the stock AudioPlaySdWav may well cause other problems.
 
Back
Top