I was working with a multi-tap delay and I wanted to create different tap spacing strategies, one of which would be a sequence of prime numbers.

There is a Smalltalk message called nextPrime that returns the next nearest prime number but if you want to use ?VoiceNumber or ?CascadeNumber to fetch the next prime in the sequence, nextPrime will return doubles of primes at various points in the sequence as the ?VoiceNumber. The alternative is to script it to capture the prime number and use that to fetch the next one.

An example is copied from a version of Ian’s Dattorro reverb implementation:

| primes x|
x := 1.
primes:=
1 to: 205 collect: [:I |
x:= x nextPrime.
x.
].

It occurred to me that what I really wanted was different subsets of prime number sequences. We all are familiar with the ‘regular’ sequence of prime numbers but mathematicians do love to a clever game or exploring various formulas to create different prime number subsets.

To implement these completely in code is beyond my needs, desire, or skill for a ‘quick’ afternoon project and since I rarely need more than the first 32 of any subset, it was easier to copy them out by hand into lookup tables which are used to populate a Smalltalk dictionary object.

|  primePresets primeArray  |

primePresets := Dictionary new.

primePresets
add: #regular ->  #(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131);
add: #chen -> #(2 3 5 7 11 13 17 19 23 29 31 37 41 47 53 59 67 71 83 89 101 107 109 113 127 131 137 139 149 157 167 179);
add: #higgs ->  #(2 3 5 7 11 13 19 23 29 31 37 43 47 53 59 61 67 71 79 101 107 127 131 139 149 151 157 173 181 191 197 199);
add: #eisenstein -> #(2 5 11 17 23 29 41 47 53 59 71 83 89 101 107 113 131 137 149 167 173 179 191 197 227 233 239 251 257 263 269 281) ;
add: #gaussian ->  #(3 7 11 19 23 31 43 47 59 67 71 79 83 103 107 127 131 139 151 163 167 179 191 199 211 223 227 239 251 263 271 283);
add: #pythagorean ->  #(5 13 17 29 37 41 53 61 73 89 97 101 109 113 137 149 157 173 181 193 197 229 233 241 257 269 277 281 293 313 317 337);
add: #isolated ->  #(2 23 37 47 53 67 79 83 89 97 113 127 131 157 163 167 173 211 223 233 251 257 263 277 293 307 317 331 337 353 359 367);
add: #ramanujan ->  #(2 11 17 29 41 47 59 67 71 97 101 107 127 149 151 167 179 181 227 229 233 239 241 263 269 281 307 311 347 349 367 373);
add: #harmonic ->  #(5 13 17 23 41 67 73 79 107 113 139 149 157 179 191 193 223 239 241 251 263 277 281 293 307 311 317 331 337 349 431 443);
add: #long ->  #(7 17 19 23 29 47 59 61 97 109 113 131 149 167 179 181 193 223 229 233 257 263 269 313 337 367 379 383 389 419 433 461);
add: #euler ->  #(19 31 43 47 61 67 71 79 101 137 139 149 193 223 241 251 263 277 307 311 349 353 359 373 379 419 433 461 463 491 509 541);
add: #irregular ->  #(37 59 67 101 103 131 149 157 233 257 263 271 283 293 307 311 347 353 379 389 401 409 421 433 461 463 467 491 523 541 547 557);
add: #good ->  #(5 11 17 29 37 41 53 59 67 71 97 101 127 149 179 191 223 227 251 257 269 307 311 331 347 419 431 541 557 563 569 587);
add: #lucky ->  #(3 7 13 31 37 43 67 73 79 127 151 163 193 211 223 241 283 307 331 349 367 409 421 433 463 487 541 577 601 613 619 631);
add: #super ->  #(3 5 11 17 31 41 59 67 83 109 127 157 179 191 211 241 277 283 331 353 367 401 431 461 509 547 563 587 599 617 709 739);
add: #happy ->  #(7 13 19 23 31 79 97 103 109 139 167 193 239 263 293 313 331 367 379 383 397 409 487 563 617 653 673 683 709 739 761 863);
add: #emirps ->  #(13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389 701 709 733 739 743 751 761 769 907 937 941 953);
add: #safe ->  #(5 7 11 23 47 59 83 107 167 179 227 263 347 359 383 467 479 503 563 587 719 839 863 887 983 1019 1187 1283 1307 1319 1367 1439);
add: #balanced ->	#(5 53 157 173 211 257 263 373 563 593 607 653 733 947 977 1103 1123 1187 1223 1367 1511 1747 1753 1907 2287 2417 2677 2903 2963 3307 3313 3637);
add: #circular ->  #(2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311).

I restricted my list to sequences where the 32nd digit was less than 10,000 with most being less than 1000. This gives us 20 options.

Now that they are in the dictionary, we can collect and unroll the array back out of the dictionary named primePresets.

"Build a collection of arrays based on Dictionary of Primes"
primeArray := (1 to: 32) collect: [:i | 
	Array 
	with: (0@ ((primePresets at: #regular) at: i)) 
	with: (1@ ((primePresets at: #chen) at: i))
	with: (2@ ((primePresets at: #higgs) at: i))
	with: (3@ ((primePresets at: #eisenstein) at: i))
	with: (4@ ((primePresets at: #gaussian) at: i))
	with: (5@ ((primePresets at: #pythagorean) at: i))
	with: (6@ ((primePresets at: #isolated) at: i))
	with: (7@ ((primePresets at: #ramanujan) at: i))
	with: (8@ ((primePresets at: #harmonic) at: i))
	with: (9@ ((primePresets at: #long) at: i))
	with: (10@((primePresets at: #euler) at: i))
	with: (11@((primePresets at: #irregular) at: i))
	with: (12@((primePresets at: #good) at: i))
	with: (13@((primePresets at: #lucky) at: i))
	with: (14@((primePresets at: #super) at: i))
	with: (15@((primePresets at: #happy) at: i))
	with: (16@((primePresets at: #emirps) at: i))
	with: (17@((primePresets at: #safe) at: i))
	with: (18@((primePresets at: #balanced) at: i))
	with: (19@((primePresets at: #circular) at: i))
].

Now within the replicated sound, I can use the ?VoiceNumber or ?CascadeNumber to fetch the value at the position within the array and use it to set the tap time.

Example:
(!PrimeType into: (?primeArray at: ?VoiceNumber))

Make your !PrimeType control in the VCS size 0 to 19 to cycle through the dictionary list. Add the list as VCS tick markers to show the names.

It is worth noting that a you could also do this entirely within the CapyTalk expression select: of : as what is created above is a 2d nested array. The advantage of the dictionary approach is for long lists, it can be easier to read and remember which row within the array belongs to which named entry and that can be useful during troubleshooting. The expression select: select: of: creates a 3d array.

Next post will insert the above example into a multi-tap delay.

12 Likes