| 1 |
class Module(BaseModule): |
| 2 |
""" |
| 3 |
"Filter audo-modulated by an extracted feature of its input sound" |
| 4 |
|
| 5 |
Description |
| 6 |
|
| 7 |
This module implements a variable filter, whose frequency is driven by the |
| 8 |
outcome of an analysis on its input signal. Available analysis continuous amplitude, |
| 9 |
centroid, fundamental frequency and zero-crossing. The filter type can be lowpass, |
| 10 |
highpass, bandpass or bandstop. |
| 11 |
|
| 12 |
Sliders |
| 13 |
|
| 14 |
# Freq Range : |
| 15 |
Lowest and highest filter frequencies, corresponding to the lowest and |
| 16 |
highest values of the analyzer output. |
| 17 |
# Filter Q : |
| 18 |
Q factor (inverse of bandwidth) of the filter. |
| 19 |
# Num of Filters : |
| 20 |
Number of filters (with identical parameters) applied in serie. |
| 21 |
# Dry / Wet : |
| 22 |
Mix between the original and the filtered signals |
| 23 |
|
| 24 |
Graph Only |
| 25 |
|
| 26 |
# Overall Amplitude : |
| 27 |
The amplitude curve applied on the total duration of the performance |
| 28 |
|
| 29 |
Popups & Toggles |
| 30 |
|
| 31 |
# Analysis Type : |
| 32 |
Choose between the four possible analyzers (amplitude, centroid, |
| 33 |
pitch or zero-crossing). |
| 34 |
# Filter Type : |
| 35 |
Choose the type of the filter (lowpass, highpass, bandpass or bandstop). |
| 36 |
# Balance : |
| 37 |
Compression mode. Off, balanced with a fixed signal |
| 38 |
or balanced with the input source. |
| 39 |
# Polyphony Voices : |
| 40 |
Number of voices played simultaneously (polyphony), |
| 41 |
only available at initialization time |
| 42 |
# Polyphony Spread : |
| 43 |
Pitch variation between voices (chorus), |
| 44 |
only available at initialization time |
| 45 |
|
| 46 |
""" |
| 47 |
def __init__(self): |
| 48 |
BaseModule.__init__(self) |
| 49 |
self.snd = self.addSampler("snd") |
| 50 |
|
| 51 |
self.ampFollow = Follower(self.snd, freq=20).stop() |
| 52 |
self.ampScale = Scale(self.ampFollow, outmin=self.frange[0], outmax=self.frange[1]).stop() |
| 53 |
|
| 54 |
self.centroidFollow = Centroid(self.snd, size=512).stop() |
| 55 |
self.centroidScale = Scale(self.centroidFollow, inmin=20, inmax=15000, outmin=self.frange[0], outmax=self.frange[1]).stop() |
| 56 |
|
| 57 |
self.pitchFollow = Yin(self.snd, tolerance=0.20, minfreq=40, maxfreq=2000, cutoff=1000, winsize=2048).stop() |
| 58 |
self.pitchScale = Scale(self.pitchFollow, inmin=40, inmax=2000, outmin=self.frange[0], outmax=self.frange[1]).stop() |
| 59 |
|
| 60 |
self.zcrossFollow = ZCross(self.snd, thresh=0.001).stop() |
| 61 |
self.zcrossScale = Scale(self.zcrossFollow, outmin=self.frange[0], outmax=self.frange[1]).stop() |
| 62 |
|
| 63 |
self.filterFreq = Clip(self.centroidScale, min=self.frange[0], max=self.frange[1]) |
| 64 |
self.filterFreqPort = Port(self.filterFreq, 0.02, 0.02) |
| 65 |
self.filter = Biquadx(self.snd, freq=self.filterFreqPort, q=self.q, type=self.filttype_index, stages=int(self.stages.get())) |
| 66 |
|
| 67 |
self.proc = Interp(self.snd, self.filter, self.drywet, mul=self.env) |
| 68 |
|
| 69 |
self.osc = Sine(10000,mul=.1) |
| 70 |
self.balanced = Balance(self.proc, self.osc, freq=10) |
| 71 |
self.out = Interp(self.proc, self.balanced) |
| 72 |
|
| 73 |
self.lastAnalysis = "" |
| 74 |
self.currentAnalysis = "" |
| 75 |
self.analysisLaterCall = CallAfter(self.analysisTurnoff, time=0.1) |
| 76 |
|
| 77 |
#INIT |
| 78 |
self.balance(self.balance_index, self.balance_value) |
| 79 |
self.analysis(self.analysis_index, self.analysis_value) |
| 80 |
|
| 81 |
def balance(self, index, value): |
| 82 |
if index == 0: |
| 83 |
self.out.interp = 0 |
| 84 |
elif index == 1: |
| 85 |
self.out.interp = 1 |
| 86 |
self.balanced.input2 = self.osc |
| 87 |
elif index == 2: |
| 88 |
self.out.interp = 1 |
| 89 |
self.balanced.input2 = self.snd |
| 90 |
|
| 91 |
def analysis(self, index, value): |
| 92 |
self.lastAnalysis = self.currentAnalysis |
| 93 |
self.currentAnalysis = value |
| 94 |
if index == 0: |
| 95 |
self.ampFollow.play() |
| 96 |
self.ampScale.play() |
| 97 |
self.filterFreq.setInput(self.ampScale, 0.05) |
| 98 |
elif index == 1: |
| 99 |
self.centroidFollow.play() |
| 100 |
self.centroidScale.play() |
| 101 |
self.filterFreq.setInput(self.centroidScale, 0.05) |
| 102 |
elif index == 2: |
| 103 |
self.pitchFollow.play() |
| 104 |
self.pitchScale.play() |
| 105 |
self.filterFreq.setInput(self.pitchScale, 0.05) |
| 106 |
elif index == 2: |
| 107 |
self.zcrossFollow.play() |
| 108 |
self.zcrossScale.play() |
| 109 |
self.filterFreq.setInput(self.zcrossScale, 0.05) |
| 110 |
self.analysisLaterCall.play() |
| 111 |
|
| 112 |
def analysisTurnoff(self): |
| 113 |
if self.lastAnalysis == self.currentAnalysis: |
| 114 |
return |
| 115 |
if self.lastAnalysis == "Amplitude": |
| 116 |
self.ampFollow.stop() |
| 117 |
self.ampScale.stop() |
| 118 |
elif self.lastAnalysis == "Centroid": |
| 119 |
self.centroidFollow.stop() |
| 120 |
self.centroidScale.stop() |
| 121 |
elif self.lastAnalysis == "Pitch": |
| 122 |
self.pitchFollow.stop() |
| 123 |
self.pitchScale.stop() |
| 124 |
elif self.lastAnalysis == "Zero-Crossing": |
| 125 |
self.zcrossFollow.stop() |
| 126 |
self.zcrossScale.stop() |
| 127 |
|
| 128 |
def filttype(self, index, value): |
| 129 |
self.filter.type = index |
| 130 |
|
| 131 |
def stages_up(self, value): |
| 132 |
self.filter.stages = value |
| 133 |
|
| 134 |
Interface = [ |
| 135 |
csampler(name="snd"), |
| 136 |
cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"), |
| 137 |
crange(name='frange', label='Freq Range', min=20.0, max=18000.0, init=[100.0, 5000.0], rel='log', unit='Hz', col='green'), |
| 138 |
cslider(name="q", label="Filter Q", min=0.5, max=5, init=1, unit="Q", col="green2"), |
| 139 |
cslider(name="stages", label="# of Filters", min=1, max=4, init=2, unit="x", res="int", up=True), |
| 140 |
cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue1"), |
| 141 |
cpopup(name="analysis", label="Analysis Type", init="Amplitude", value=["Amplitude", "Centroid", "Pitch", "Zero-Crossing"], col="orange"), |
| 142 |
cpopup(name="filttype", label="Filter Type", init="Lowpass", col="green3", value=["Lowpass","Highpass","Bandpass","Bandstop"]), |
| 143 |
cpopup(name="balance", label = "Balance", init= "Off", col="blue", value=["Off","Compress", "Source"]), |
| 144 |
cpoly() |
| 145 |
] |