Blog

What's Up

Building a Granular Synth in Swift, Part 9: Pitch ControlJanuary 29, 2021

Today’s pull request is almost self-explanatory. We have added a couple pitch controls, detuning all grains, and, more interestingly still, detuning each grain individually with our now standard jitter approach. The addition is straightforward, but the results are even lovelier than I expected. Pitch slightly up and add a little jitter, and you can almost feel the bone-chill of outer space, à la…

Keep Reading →

Building a Granular Synth in Swift, Part 8: More TouchyJanuary 28, 2021

So far we haven’t really explored the interactive potential here and just defaulted to basic controls. This is a great way to get started and test things, but maybe it’s now time to think about interactivity a little and prototype some approaches. Currently dragging the position slider moves the red position indicator in the top WaveView and this begs the question: why not drag the indicator…

Keep Reading →

Building a Granular Synth in Swift, Part 7: Mixing SoundsJanuary 20, 2021

If you have been following along, you may have noticed that our volume drops as we increase density. Density means more grains are playing at once so this is rather counter-intuitive. I breezed past this issue at the outset, but let’s revisit it now. Maybe you noticed this line in the GrainSource struct: When adding up the sound of 10,000 grains, there is the potential for our sound to be 10,00…

Keep Reading →

Building a Granular Synth in Swift, Part 6: JitterJanuary 19, 2021

Way back in Part 4 we smeared grains in time to make the synth sound less like it was looping over a section of audio and more like it was playing a cloud of sounds. Let’s add some of this shaky jitter to grain position and size as well. We can quickly whip up a ControlTwinSliderView that will give us two sliders, one for the primary value and one more for how much we want it to vary. We can add…

Keep Reading →

Building a Granular Synth in Swift, Part 5: Sharing SoundsJanuary 18, 2021

Now is a good time to do some testing and see if any bugs creep up. One issue is doing a modulo by grain length rather than source buffer length when updating grain position: fix position bug · thestrangeagency/GrainSwift@46157c9 · GitHub. Also in our WaveView it’s probably preferable not to wander off the end of the audio buffer: modulo for end of array · thestrangeagency/GrainSwift@7d0edc…

Keep Reading →

Building a Granular Synth in Swift, Part 4: ControlJanuary 08, 2021

It would be great to add some more control to our grain source, and to make this work with SwiftUI. A class derived from ObservableObject gives us a nice way to package up controls and expose them to the UI. We can put it in its own file later, but for now it is convenient to keep all the grainy things in one file, like so: GrainSwift/GrainSource.swift at 6a5117fe15b3251708817c09393486fe1d79cf6…

Keep Reading →

Building a Granular Synth in Swift, Part 3: Making it GrainJanuary 06, 2021

In the previous two posts (1, 2) we’ve essentially created a very barebones AVAudioSourceNode audio playback example. Apple has a good example too, but it’s a command-line app that doesn’t load audio. In any case, it’s time for grains. As most reader probably know, the seminal reference for grain concepts can be found in Curtis Roads’ Microsound. We’ll want a data structure for each audio grain…

Keep Reading →

Building a Granular Synth in Swift, Part 2: Loading AudioJanuary 03, 2021

Now let’s add a little bit of structure and create an AudioSource object that can wrap the file loading and act as a buffer source for our audio engine. Per Choosing Between Structures and Classes we’ll go with struct over class for now, although it might turn out that passing our source around by reference might be useful later. GrainSwift/AudioSource.swift at 7d0c817b0d8fe42d63a8f86848ef935a9ff…

Keep Reading →

Building a Granular Synth in SwiftJanuary 01, 2021

It should perhaps be mentioned at the outset that there are reasons to avoid Swift in the audio thread. I believe we manage to sidestep the pitfalls below, but let us say it here: caveat emptor. Also, it should be noted that this is an experiment in a sort of live coding. Mistakes are made along the way, so do feel free to skip ahead in the repo and avoid copying blindly. Whenever I see a…

Keep Reading →