Debian Codegraph @

Resources/modules/Filters/Binaural.c5

raw
1 class Module(BaseModule):
2 """
3 "Binaural 3D spatialization"
4
5 Description
6
7 This module provides a realtime 3D spatialization over two channels
8 by the mean of combining VBAP and HRTF algorithms.
9
10 VBAP is used to move the sound over a sixteen channels speaker setup
11 without artifact and its result signals are then processed with
12 Head-related Transfert Functions to mix them on a 3D sphere around a
13 virtual head.
14
15 This treatment is better perceived when listened with headphones!
16
17 Sliders
18
19 # Azimuth :
20 Position of the sound on the horizontal plane, between -180 and 180 degrees.
21 # Elevation :
22 Position of the sound on the vertical plane, between 0 and 90 degrees.
23 # Azimuth Span :
24 Spreading of the sound on the horizontal plane.
25 # Elevation Span :
26 Spreading of the sound on the vertical plane.
27
28 Graph Only
29
30 # Overall Amplitude :
31 The amplitude curve applied on the total duration of the performance
32
33 Popups & Toggles
34
35 # Monofy Source :
36 If checked, a multi-channel source is mixed down to a mono signal before
37 the spatialization. Otherwise, the channels are spreaded in azimuth over
38 360 degrees and are spatialized independently.
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.isMonofied = False
52
53 self.filterMono = Binaural(self.snd.mix(), azimuth=self.azimuth, elevation=self.elevation,
54 azispan=self.azispan, elespan=self.elespan, mul=0.7)
55 self.mixedFilterMono = Mix(self.filterMono, voices=self.nchnls*2, mul=0.7)
56
57 offset = 360.0 / self.nchnls
58 self.scaledAzimuth = Sig(self.azimuth, add=[offset * i - 45. for i in range(self.nchnls)])
59 self.azimuthMulti = Wrap(self.scaledAzimuth, min=-180, max=180)
60 self.filterMulti = Binaural(self.snd, azimuth=self.azimuthMulti, elevation=self.elevation,
61 azispan=self.azispan, elespan=self.elespan, mul=0.7)
62
63 self.interp = Interp(self.mixedFilterMono, self.filterMulti, interp=1)
64 self.out = Mix(self.interp, voices=self.nchnls, mul=self.env)
65
66 self.monofy(self.monofy_value)
67
68 def monofy(self, value):
69 self.isMonofied = value
70 if value:
71 self.filterMono.play()
72 self.mixedFilterMono.play()
73 self.interp.set("interp", 0, 0.01, self.stopped)
74 else:
75 self.scaledAzimuth.play()
76 self.azimuthMulti.play()
77 self.filterMulti.play()
78 self.interp.set("interp", 1, 0.01, self.stopped)
79
80 def stopped(self):
81 if self.isMonofied:
82 self.scaledAzimuth.stop()
83 self.azimuthMulti.stop()
84 self.filterMulti.stop()
85 else:
86 self.filterMono.stop()
87 self.mixedFilterMono.stop()
88
89 Interface = [
90 csampler(name="snd"),
91 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
92 cslider(name="azimuth", label="Azimuth", min=-180, max=180, init=0, unit="deg", col="orange"),
93 cslider(name="elevation", label="Elevation", min=0, max=90, init=0, unit="deg", col="purple1"),
94 cslider(name="azispan", label="Azimuth Span", min=0, max=1, init=0, unit="%", col="orange3"),
95 cslider(name="elespan", label="Elevation Span", min=0, max=1, init=0, unit="%", col="purple3"),
96 ctoggle(name="monofy", label="Monofy Source", init=False, col="blue"),
97 cpoly()
98 ]