Grainimogrifier

A basic granular plugin. It chops some input audio into little pieces, rearranges the pieces and plays them back.

Here’s how to use this one:

Apply to a selection of three or more audio tracks, the first two being monaural “control tracks” and the rest “input tracks”.

The first track is treated as a graph whose height is the length of time until the next grain starts. Negative heights are treated as zero.

The second track is treated as a graph whose height indicates where in the input tracks the grains are being sampled from: a height of zero means the grain is taken from the beginning of the input track, a height of 0.5 indicates the grain starts halfway through the track, and a height of 1 indicates the grain starts at the end of the track (this will result in silence). If “Normalize Sample Start Control Envelope” is set to “Yes”, this graph will be adjusted so that it spans from 0 to 1 exactly.

The remaining tracks are then grainimogrified according to the plugin’s inputs:
“Number of Grains” is the total number of grains.
“Grain Length (Seconds)” is the length of each grain in seconds, and
“Grain Envelope” controls the shape of an envelope applied to each grain, where

  • Triangle is the first half-period of a triangle wave.
  • Sine is the first half-period of a sine wave.
  • Exponential is a misnomer - it starts at full volume when the grain starts, and decays to zero during the Grain Length.
  • Rectangle is no envelope. May cause artifacts.

There’s a bug where the second track can’t be processed (argument stack overflow) if the number of grains is somewhere bigger than 1950, so for now I’ve limited that to 1750.
GRAINIMOGRIFIER.ny (4.57 KB)

When that track approaches zero the grain-density goes soo high there is severe clipping …

GRAINIMOGRIFIER is clipping.gif
Limiting the minimum grain-separation is a solution.

Unfortunately on Audacity 2.3.1 this plug-in silently fails. It appears to quit after processing the first track.

The problem is that the first track returns a list, which is an error because it is not a valid return value for Audacity (it is logged in Audacity’s debug window as: “Nyquist returned nyx_error:”)

The easiest solution to this problem is to return the unmodified track audio for the first two tracks. For example:

      (cond
        ((= index 1) (process-gaps-env) *track*)
        ((= index 2) (process-place-env) *track*)
        (T (process-sample-track)))))

Sounds good. There’s a shiny new parameter: “Minimum Grain Separation (ms)”.
It’s the minimum separation between grains, in milliseconds. Grain length is now also specified in ms.

Good to know. I’ve added the fix you gave, so hopefully it should work now.
GRAINIMOGRIFIER.ny (4.74 KB)

That’s working for me …

grainmog474.gif
‘‘TheDon’’ before-after grainimogrifier(474 KiB)

Logically the grains should be reversed when one of the control tracks goes negative, (track 1 :question: ).

Bad news! Try as I might, I couldn’t find a way to quickly, reliably reverse a sound in Nyquist. Arrays are really slow, shape is slow and cranky, and worst of all, snd-reverse does not exist.

Could you elaborate a bit on why the grains should be reversed? I don’t understand the logic here.

Arrays shouldn’t be too slow for reasonably short selections. What durations are you thinking of?

To complete the set of controls :
Can start & end at different points on the track :heavy_check_mark:
Can play the grains in reverse order :heavy_check_mark:
Can play each grain reversed ✘

Other grainifiers have that ability.

I just saw that the negative area of the control tracks weren’t used, & reverse grains was missing.

[ I didn’t realize how difficult it would be to reverse the grains.]

A workaround is to reverse the track …

track reversed.gif
but it does not have a mixture of backward & forward grains in the grainified remix.

Grains are short? https://forum.audacityteam.org/t/grainimogrifier/51457/8

oops, I was totally thinking about it wrong, it didn’t occur to me you only need to compute the reversed track once (if that).
Try this on for size.
GRAINIMOGRIFIER.ny (6 KB)

That’s it : if track 1 goes negative the grains are played in reverse …
[ apparently the sign of track 2 is ignored ]

grainimogrifier(6 KiB).gif

Yes, for now I’ve changed it so that it takes the absolute value of track 2 - I’m on the fence whether it’s worse to ignore the sign, or to sometimes produce silent grains. Any ideas on how those negative values should be interpreted?

That the track is being played backwards ?

You may be interested in this: https://forum.audacityteam.org/t/reversing-sounds-with-nyquist/51518/1

Hi, sorry for the delay. This version reverses the grains whenever either the first or second track are negative. There was also a bug that caused the second track to be interpreted wrong, now fixed.
GRAINIMOGRIFIER.ny (6.56 KB)

“GRAINIMOGRIFIER.ny (6.56 KiB)” does not make the grains run backward when track 1 goes negative.

Whereas the previous version “GRAINIMOGRIFIER.ny (6 KiB)” did.

Oops! Another 200 bytes to fix that.
GRAINIMOGRIFIER.ny (6.79 KB)

That’s fixed it …