At the end of the last log I discussed how I had finally gotten some grain sound out of the plugin. The next step for me was to pitch it. Naturally, having virtually no idea what I was doing, I looked up pitch shifting in JUCE.
Well, JUCE doesn’t have any pitch shifting algorithms. Oh, it’s really complicated. Great. Ok some libraries exist but they have 100ms delay. That seems pretty good actually but I’m working with about 50-200ms of sound at a time, maybe not the best idea?
Ok I’ll look up the algorithms instead. Phase vocoder… ok looks good. About eight hours later, and to literally no avail. It was KIND of working. With a huge delay. Ok what if I shift the entire sample BEFORE I make a grain. Ok that crashed.
In desperation, I look for another pitch shifting algorithm. Ok let’s see.
Granular Synthesis.
I almost hit my hand against my hand as I read the google metatag. “Granular synthesis is…” I KNOW WHAT IT IS BY NOW.
I realize I’ve been thinking about it all wrong. I can’t pitch shift 5-200ms of audio 400+ times per second. I’ll have to adjust the playback speed. I realized I knew nothing about what I was doing, but had learnt a lot about phase vocoding, which is completely irrelevant for this project, but hey.
I’d like to say I spent the next hours finding the RIGHT solution and implementing it but no.
I went to bed.
I decided I’d make a board to go over what I need to do, put this pitch shifting stuff in a Git branch I’d likely never touch again mainly out of spite, and continue the next day.
And I stuck to it.
Today I implemented interpolation and changed the playback speed to adjust the pitch of the grains. It works pretty well. Grain processing became part of the grain class, which allows me to micromanage each grain a little easier and also makes more sense when reading. I stopped creating an AudioSampleBuffer for every single grain which improved stability and performance quite a bit, and by the end of the day I had a somewhat functional granulator.
This is the first project I’ve really delved into with no tutorial and no reference points, it’s all me and my research for hours on StackOverflow, Google, GitHub, ChatGPT, what have you.
It took weeks but finally I have a semi-functional granulator, with a decent understanding of how it works. So I end on another win, with a lot of bugs and issues to fix, but a win nonetheless.
This is today’s update on the board:
I go to bed knowing that tomorrow may be a lot easier, and a lot of audible progress will be made. With some luck, I could be posting the first image of a currently VERY ugly VST.