@@ -0,0 +1,242 @@
// P o l y O c t a v e P e d a l . s w i f t
// L y r e b i r d
//
// C o p y r i g h t ( c ) 2 0 2 6 J o s h u a P a r m e n t e r / r e a l i z e d s o u n d
// S P D X - L i c e n s e - I d e n t i f i e r : M I T
import LyrebirdSynth
import LyrebirdUI
// / P o l y p h o n i c o c t a v e g e n e r a t o r i n t h e E H X P O G m o u l d .
// /
// / S t a c k s f o u r f i x e d p i t c h - s h i f t e d v o i c e s — t w o o c t a v e s d o w n , o n e o c t a v e d o w n , o n e o c t a v e u p , t w o
// / o c t a v e s u p — u n d e r t h e d r y n o t e , e a c h w i t h i t s o w n l e v e l , s o a s i n g l e n o t e b e c o m e s a n
// / o r g a n - l i k e c h o r d o f o c t a v e s . U n l i k e t h e ` ` W h a m m y P e d a l ` ` ( o n e v o i c e s w e p t b y a n e x p r e s s i o n
// / p e d a l ) , e v e r y v o i c e s o u n d s a t o n c e a t a * * f i x e d * * i n t e r v a l , a n d b e c a u s e t h e r a t i o s a r e e x a c t
// / p o w e r s o f t w o t h e s h i f t e r n e e d s n o p i t c h t r a c k i n g — c h o r d s s h i f t a s c l e a n l y a s s i n g l e n o t e s .
// /
// / E a c h v o i c e i s a ` P i t c h S h i f t ` — L y r e b i r d ' s f o u r - h e a d S O L A s h i f t e r , w h o s e ` p i t c h R a t i o ` c l a m p s t o
// / ` [ 0 . 2 5 , 4 . 0 ] ` , i . e . e x a c t l y ± 2 o c t a v e s , s o e v e r y v o i c e h e r e i s a s i n g l e s t a g e ( n o c a s c a d e ) .
// /
// / T h e f i v e v o i c e l e v e l s s u m w i t h o u t a n i n t e r n a l l i m i t e r ( a s w i t h t h e O C - 2 - s t y l e
// / ` ` B a s s O c t a v e r P e d a l ` ` ) , s o d r i v i n g s e v e r a l t o f u l l c a n p u s h t h e s u m a b o v e u n i t y ; t h e p e d a l ' s
// / ` l e v e l ` k n o b a n d t h e b o a r d o u t p u t m a s t e r s e t t h e f i n a l g a i n , l i k e a r e a l m i x e r ' s c h a n n e l s u m .
// /
// / A l o w - p a s s * * T o n e * * c o n t r o l t a m e s t h e s h i f t e d v o i c e s ( t h e d r y s t a y s u n t o u c h e d ) , a n d a n
// / * * A t t a c k * * c o n t r o l a d d s t h e P O G ' s s i g n a t u r e v o l u m e * * s w e l l * * : t u r n e d u p , t h e o c t a v e v o i c e s f a d e
// / i n a f t e r e a c h n o t e i n s t e a d o f s o u n d i n g i n s t a n t l y , f o r a b o w e d / s y n t h - p a d b l o o m . T h e s w e l l i s a
// / " s l o w - g e a r " g a i n — t h e r a t i o o f a s l o w e n v e l o p e f o l l o w e r t o a f a s t o n e — s o a t ` A t t a c k = 0 ` t h e
// / t w o f o l l o w e r s a r e i d e n t i c a l a n d t h e g a i n i s u n i t y ( v o i c e s r e s p o n d i n s t a n t l y ) , a n d t h e s w e l l
// / n e v e r d e p e n d s o n h o w l o u d y o u p l a y .
// /
// / # # K n o b s
// / - ` s u b T w o ` : − 2 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
// / - ` s u b O n e ` : − 1 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
// / - ` u p O n e ` : + 1 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
// / - ` u p T w o ` : + 2 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
// / - ` d r y ` : D r y ( d i r e c t ) s i g n a l l e v e l i n ` [ 0 , 1 ] ` .
// / - ` a t t a c k ` : O c t a v e - v o i c e s w e l l i n ` [ 0 , 1 ] ` . ` 0 ` = i n s t a n t ; h i g h e r = s l o w e r v o l u m e b l o o m .
// / - ` t o n e ` : O c t a v e - v o i c e l o w - p a s s c u t o f f i n H z . R a n g e ` [ 5 0 0 , 1 2 0 0 0 ] ` .
public final class PolyOctavePedal : Pedal {
// / O n e - l i n e d e s c r i p t i o n s h o w n i n t h e p i c k e r a n d i n f o p a n e l .
public override var summary : String {
" Stacks fixed octave voices under your note — organ-like, with a volume swell. "
}
// MARK: - P a r a m e t e r s
// / − 2 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
@ UIParam public var subTwo : Double = 0.0
// / − 1 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
@ UIParam public var subOne : Double = 0.0
// / + 1 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
@ UIParam public var upOne : Double = 0.5
// / + 2 o c t a v e v o i c e l e v e l i n ` [ 0 , 1 ] ` .
@ UIParam public var upTwo : Double = 0.0
// / D r y ( d i r e c t ) s i g n a l l e v e l i n ` [ 0 , 1 ] ` .
@ UIParam public var dry : Double = 1.0
// / O c t a v e - v o i c e s w e l l i n ` [ 0 , 1 ] ` . ` 0 ` = i n s t a n t ; h i g h e r = s l o w e r v o l u m e b l o o m a f t e r e a c h n o t e .
@ UIParam public var attack : Double = 0.0
// / O c t a v e - v o i c e l o w - p a s s c u t o f f i n H z . R a n g e ` [ 5 0 0 , 1 2 0 0 0 ] ` .
@ UIParam public var tone : Double = 8000.0
// MARK: - C o n s t a n t s
// / P e d a l b l e n d s e v e r y t h i n g i n t e r n a l l y v i a t h e l e v e l k n o b s , s o t h e b a s e w e t / d r y s t a y s f u l l y w e t .
private static let defaultMix : Double = 1.0
// / F i x e d ` P i t c h S h i f t ` p l a y b a c k r a t i o s f o r t h e f o u r v o i c e s ( e x a c t p o w e r s o f t w o ) .
private let subTwoRatio : Double = 0.25 // − 2 o c t a v e s
private let subOneRatio : Double = 0.5 // − 1 o c t a v e
private let upOneRatio : Double = 2.0 // + 1 o c t a v e
private let upTwoRatio : Double = 4.0 // + 2 o c t a v e s
// / G r a i n w i n d o w f o r e a c h ` P i t c h S h i f t ` , i n s e c o n d s . A t o u c h o v e r t h e s h i f t e r ' s ` 0 . 1 ` d e f a u l t t o
// / s o f t e n t h e p e r i o d i c f o u r - h e a d c o m b w i t h o u t a d d i n g a u d i b l e l a g .
private let voiceWindowSize : Double = 0.11
// / P e r - h e a d t i m i n g j i t t e r f o r e a c h ` P i t c h S h i f t ` , i n s e c o n d s . B r e a k s t h e f i x e d - g r i d c o m b ; k e p t
// / s m a l l s o t h e v o i c e s s t a y t i g h t .
private let voiceTimeDispersion : Double = 0.02
// / F i x e d P R N G s e e d s , o n e p e r v o i c e , s o a g i v e n s e t t i n g r e n d e r s i d e n t i c a l l y e v e r y t i m e
// / ( r e p r o d u c i b l e a u d i o a n d e x a c t - p i t c h t e s t s ) . D i s t i n c t p e r v o i c e s o t h e i r g r a i n d i s p e r s i o n
// / s e q u e n c e s d e c o r r e l a t e i n s t e a d o f j i t t e r i n g i n l o c k s t e p .
private let subTwoSeed : UInt64 = 0x9E37_79B9_7F4A_7C15
private let subOneSeed : UInt64 = 0xC2B2_AE3D_27D4_EB4F
private let upOneSeed : UInt64 = 0x1656_67B1_9E37_79F9
private let upTwoSeed : UInt64 = 0x2545_F491_4F6C_DD1D
// / F a s t e n v e l o p e - f o l l o w e r a t t a c k f o r t h e s w e l l ' s d e n o m i n a t o r , i n s e c o n d s — n e a r - i n s t a n t , s o i t
// / t r a c k s n o t e o n s e t s t i g h t l y . A l s o t h e f l o o r o f t h e m a p p e d s l o w a t t a c k , s o ` a t t a c k = 0 ` m a k e s
// / t h e t w o f o l l o w e r s i d e n t i c a l a n d t h e s w e l l g a i n u n i t y ( n e u t r a l ) .
private let swellFastAttack : Double = 0.005
// / S l o w e s t e n v e l o p e - f o l l o w e r a t t a c k t h e ` a t t a c k ` k n o b m a p s t o , i n s e c o n d s ( a t ` a t t a c k = 1 ` ) .
private let swellMaxAttack : Double = 1.5
// / S h a r e d r e l e a s e t i m e f o r b o t h s w e l l f o l l o w e r s , i n s e c o n d s . E q u a l o n b o t h s o o n l y t h e a t t a c k
// / d i f f e r s b e t w e e n t h e m .
private let swellRelease : Double = 0.15
// / F l o o r a d d e d t o t h e s w e l l d e n o m i n a t o r b e f o r e t h e r e c i p r o c a l , s o a s i l e n t i n p u t ( b o t h
// / f o l l o w e r s n e a r z e r o ) c a n n o t d i v i d e b y z e r o . K e p t w e l l b e l o w a n y r e a l s i g n a l l e v e l
// / ( ` 1 e - 6 ` ≈ − 1 2 0 d B ) s o t h e n e u t r a l g a i n s t a y s ~ 1 a c r o s s t h e w h o l e p l a y i n g r a n g e — a l a r g e r
// / f l o o r w o u l d p u l l t h e ` a t t a c k = 0 ` g a i n t o w a r d ` 0 . 5 ` f o r q u i e t i n p u t .
private let swellDenomFloor : Double = 1.0e-6
// / C l a m p b o u n d s f o r t h e s w e l l g a i n . W i t h e q u a l r e l e a s e t i m e s t h e t w o f o l l o w e r s t r a c k i n
// / l o c k s t e p o n c e s e t t l e d , s o t h e r a t i o s t a y s ` ≤ 1 ` i n n o r m a l u s e ( i t d i p s b e l o w ` 1 ` o n l y d u r i n g
// / t h e a t t a c k r a m p , w h e n t h e s l o w f o l l o w e r l a g s ) ; t h e c e i l i n g i s a d e f e n s i v e g u a r d a g a i n s t a
// / t r a n s i e n t o v e r s h o o t f r o m t h e r e c i p r o c a l , a n d t h e f l o o r k e e p s t h e g a i n n o n - n e g a t i v e .
private let swellGainFloor : Double = 0.0
private let swellGainCeil : Double = 1.0
// / B u t t e r w o r t h Q ( n o r e s o n a n t p e a k ) f o r t h e t o n e l o w - p a s s .
private let toneQ : Double = 0.707
// MARK: - R a n g e s
private let levelRange : ClosedRange < Double > = 0.0 . . . 1.0
private let attackRange : ClosedRange < Double > = 0.0 . . . 1.0
private let toneRange : ClosedRange < Double > = 500.0 . . . 12000.0
// MARK: - K n o b s
public override var effectKnobs : [ PedalKnob ] {
[
PedalKnob ( label : " -2 Oct " , node : $ subTwo , range : levelRange ) ,
PedalKnob ( label : " -1 Oct " , node : $ subOne , range : levelRange ) ,
PedalKnob ( label : " +1 Oct " , node : $ upOne , range : levelRange ) ,
PedalKnob ( label : " +2 Oct " , node : $ upTwo , range : levelRange ) ,
PedalKnob ( label : " Dry " , node : $ dry , range : levelRange ) ,
PedalKnob ( label : " Attack " , node : $ attack , range : attackRange ) ,
PedalKnob ( label : " Tone " , node : $ tone , range : toneRange ) ,
]
}
// MARK: - I n i t
// / C r e a t e s a p o l y p h o n i c o c t a v e p e d a l .
// /
// / - P a r a m e t e r s :
// / - i n p u t B u s : A u d i o b u s i n d e x t o r e a d t h e d r y i n p u t f r o m . D e f a u l t s t o ` 0 ` .
// / - o u t p u t B u s : A u d i o b u s i n d e x t o w r i t e t h e o u t p u t t o . D e f a u l t s t o ` 0 ` .
public init (
inputBus : Int = 0 ,
outputBus : Int = 0
) {
super . init (
name : " Poly Octave " ,
inputBus : inputBus ,
outputBus : outputBus ,
initialMix : PolyOctavePedal . defaultMix
)
}
// MARK: - E f f e c t
public override func effect ( _ dry : any ValidGeneratorInput ) -> any ValidGeneratorInput {
// F o u r f i x e d - r a t i o v o i c e s . E a c h r a t i o i s w i t h i n P i t c h S h i f t ' s ± 2 - o c t a v e c l a m p , s o a s i n g l e
// s t a g e s u f f i c e s ( n o c a s c a d e , u n l i k e t h e W h a m m y ' s 3 - o c t a v e D i v e B o m b ) .
let subTwoVoice : PitchShift . Audio = makeVoice ( dry : dry , ratio : subTwoRatio , seed : subTwoSeed )
let subOneVoice : PitchShift . Audio = makeVoice ( dry : dry , ratio : subOneRatio , seed : subOneSeed )
let upOneVoice : PitchShift . Audio = makeVoice ( dry : dry , ratio : upOneRatio , seed : upOneSeed )
let upTwoVoice : PitchShift . Audio = makeVoice ( dry : dry , ratio : upTwoRatio , seed : upTwoSeed )
// O c t a v e b u s : e a c h v o i c e s c a l e d b y i t s l e v e l k n o b .
let octaveBus : any ValidGeneratorInput =
( subTwoVoice * $ subTwo )
+ ( subOneVoice * $ subOne )
+ ( upOneVoice * $ upOne )
+ ( upTwoVoice * $ upTwo )
// S w e l l : a " s l o w - g e a r " g a i n a p p l i e d t o t h e o c t a v e b u s o n l y ( t h e d r y s t a y s i m m e d i a t e ) .
let swelled : any ValidGeneratorInput = octaveBus * swellGain ( dry : dry )
// T o n e s h a p e s t h e s h i f t e d v o i c e s , n o t t h e d r y .
let octaveToned : RBJLowPass . Audio = RBJLowPass . Audio (
input : swelled ,
freq : $ tone ,
q : toneQ
)
return ( dry * $ dry ) + octaveToned
}
// / B u i l d s o n e f i x e d - r a t i o o c t a v e v o i c e .
// /
// / - P a r a m e t e r s :
// / - d r y : D r y i n p u t t o s h i f t .
// / - r a t i o : F i x e d p l a y b a c k r a t i o ( p o w e r o f t w o ) w i t h i n P i t c h S h i f t ' s ` [ 0 . 2 5 , 4 . 0 ] ` c l a m p .
// / - s e e d : P e r - v o i c e P R N G s e e d f o r r e p r o d u c i b l e g r a i n d i s p e r s i o n .
// / - R e t u r n s : T h e p i t c h - s h i f t e d v o i c e ( p r e - l e v e l ) .
private func makeVoice (
dry : any ValidGeneratorInput ,
ratio : Double ,
seed : UInt64
) -> PitchShift . Audio {
PitchShift . Audio (
input : dry ,
pitchRatio : ratio ,
windowSize : voiceWindowSize ,
timeDispersion : voiceTimeDispersion ,
seed : seed
)
}
// / B u i l d s t h e o c t a v e - v o i c e s w e l l g a i n : t h e r a t i o o f a s l o w e n v e l o p e f o l l o w e r t o a f a s t o n e ,
// / c l a m p e d t o ` [ 0 , 1 ] ` . U n i t y w h e n ` a t t a c k = 0 ` ( b o t h f o l l o w e r s i d e n t i c a l ) , d i p p i n g a n d t h e n
// / r e c o v e r i n g a s ` a t t a c k ` r i s e s , s o t h e v o i c e s b l o o m i n a f t e r e a c h o n s e t i n d e p e n d e n t o f l e v e l .
// /
// / - P a r a m e t e r d r y : D r y i n p u t t h e s w e l l t r a c k s .
// / - R e t u r n s : A ` [ 0 , 1 ] ` g a i n t o m u l t i p l y t h e o c t a v e b u s b y .
private func swellGain ( dry : any ValidGeneratorInput ) -> any ValidGeneratorInput {
// a t t a c k [ 0 , 1 ] → s l o w - f o l l o w e r a t t a c k [ s w e l l F a s t A t t a c k , s w e l l M a x A t t a c k ] s e c o n d s .
let attackSpan : Double = swellMaxAttack - swellFastAttack
let slowAttackTime : any ValidGeneratorInput = ( $ attack * attackSpan ) + swellFastAttack
let fastEnv : AmplitudeFollower . Audio = AmplitudeFollower . Audio (
in : dry ,
attackTime : swellFastAttack ,
releaseTime : swellRelease
)
let slowEnv : AmplitudeFollower . Audio = AmplitudeFollower . Audio (
in : dry ,
attackTime : slowAttackTime ,
releaseTime : swellRelease
)
// g a i n = s l o w E n v / ( f a s t E n v + f l o o r ) , c l a m p e d t o [ 0 , 1 ] .
let denom : any ValidGeneratorInput = fastEnv + swellDenomFloor
let ratio : any ValidGeneratorInput = slowEnv * Reciprocal . Audio ( denom )
return Clip . Audio ( ratio , lo : swellGainFloor , hi : swellGainCeil )
}
}