Compare commits
	
		
			1 Commits
		
	
	
		
			master
			...
			feat/dynsm
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b377e9e8be | 
							
								
								
									
										48
									
								
								examples/dynparamsmooth.nim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								examples/dynparamsmooth.nim
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					## Dynamic Smoothing Using Self Modulating Filter
 | 
				
			||||||
 | 
					## Andrew Simper, Cytomic, 2014, andy@cytomic.com
 | 
				
			||||||
 | 
					## public release: 6th Dec 2016
 | 
				
			||||||
 | 
					## https://cytomic.com/files/dsp/DynamicSmoothing.pdf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type
 | 
				
			||||||
 | 
					    DynParamSmooth* = object
 | 
				
			||||||
 | 
					        baseFreq: float
 | 
				
			||||||
 | 
					        sensitivity: float
 | 
				
			||||||
 | 
					        wc: float
 | 
				
			||||||
 | 
					        low1: float
 | 
				
			||||||
 | 
					        low2: float
 | 
				
			||||||
 | 
					        inz: float
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					proc reset*(self: var DynParamSmooth) =
 | 
				
			||||||
 | 
					    self.low1 = 0.0
 | 
				
			||||||
 | 
					    self.low2 = 0.0
 | 
				
			||||||
 | 
					    self.inz = 0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					proc setSampleRate*(self: var DynParamSmooth, sampleRate: float) =
 | 
				
			||||||
 | 
					    self.wc = self.baseFreq / sampleRate
 | 
				
			||||||
 | 
					    self.reset()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					proc process*(self: var DynParamSmooth, sample: float): float =
 | 
				
			||||||
 | 
					    let low1z = self.low1
 | 
				
			||||||
 | 
					    let low2z = self.low2
 | 
				
			||||||
 | 
					    let bandz = low1z - low2z
 | 
				
			||||||
 | 
					    let wd = self.wc + self.sensitivity * abs(bandz)
 | 
				
			||||||
 | 
					    let g = min(wd * (5.9948827 + wd * (-11.969296 + wd * 15.959062)), 1.0)
 | 
				
			||||||
 | 
					    self.low1 = low1z + g * (0.5 * (sample + self.inz) - low1z)
 | 
				
			||||||
 | 
					    self.low2 = low2z + g * (0.5 * (self.low1 + low1z) - low2z)
 | 
				
			||||||
 | 
					    self.inz = sample
 | 
				
			||||||
 | 
					    return self.low2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					proc initDynParamSmooth*(
 | 
				
			||||||
 | 
					    baseFreq: float = 2.0,
 | 
				
			||||||
 | 
					    sensitivity: float = 2.0,
 | 
				
			||||||
 | 
					    sampleRate: float = 48_000.0
 | 
				
			||||||
 | 
					): DynParamSmooth =
 | 
				
			||||||
 | 
					    result.baseFreq = baseFreq
 | 
				
			||||||
 | 
					    result.sensitivity = sensitivity
 | 
				
			||||||
 | 
					    result.wc = result.baseFreq / sampleRate
 | 
				
			||||||
 | 
					    result.reset()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import nymph
 | 
					import nymph
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import paramsmooth
 | 
					import dynparamsmooth
 | 
				
			||||||
import svf
 | 
					import svf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PluginUri = "urn:nymph:examples:multimode-filter"
 | 
					const PluginUri = "urn:nymph:examples:multimode-filter"
 | 
				
			||||||
@ -20,7 +20,7 @@ type
 | 
				
			|||||||
        q: ptr cfloat
 | 
					        q: ptr cfloat
 | 
				
			||||||
        mode: ptr cfloat
 | 
					        mode: ptr cfloat
 | 
				
			||||||
        svf: FilterSV
 | 
					        svf: FilterSV
 | 
				
			||||||
        smoothCutoff: ParamSmooth
 | 
					        smoothCutoff: DynParamSmooth
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
 | 
					proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
 | 
				
			||||||
@ -28,7 +28,7 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
 | 
				
			|||||||
                 Lv2Handle {.cdecl.} =
 | 
					                 Lv2Handle {.cdecl.} =
 | 
				
			||||||
     let plug = createShared(SVFPlugin)
 | 
					     let plug = createShared(SVFPlugin)
 | 
				
			||||||
     plug.svf = initFilterSV(fmLowPass, sampleRate)
 | 
					     plug.svf = initFilterSV(fmLowPass, sampleRate)
 | 
				
			||||||
     plug.smoothCutoff = initParamSmooth(20.0, sampleRate)
 | 
					     plug.smoothCutoff = initDynParamSmooth(sampleRate=sampleRate)
 | 
				
			||||||
     return plug
 | 
					     return plug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user