cyfaust 0.1.0__cp311-cp311-macosx_15_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (693) hide show
  1. cyfaust/CMakeLists.txt +93 -0
  2. cyfaust/__init__.py +0 -0
  3. cyfaust/__main__.py +819 -0
  4. cyfaust/box.pxd +46 -0
  5. cyfaust/box.pyx +2459 -0
  6. cyfaust/common.pxd +5 -0
  7. cyfaust/common.pyx +61 -0
  8. cyfaust/cyfaust.cpython-311-darwin.so +0 -0
  9. cyfaust/faust_box.pxd +298 -0
  10. cyfaust/faust_box_oo.pyx +66 -0
  11. cyfaust/faust_gui.pxd +261 -0
  12. cyfaust/faust_interp.pxd +160 -0
  13. cyfaust/faust_player.pxd +80 -0
  14. cyfaust/faust_signal.pxd +257 -0
  15. cyfaust/gui_statics.cpp +15 -0
  16. cyfaust/interp.pyx +673 -0
  17. cyfaust/player.cpp +32519 -0
  18. cyfaust/player.pyx +191 -0
  19. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUBase.cpp +2327 -0
  20. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUBase.h +1019 -0
  21. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUDispatch.cpp +423 -0
  22. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUDispatch.h +82 -0
  23. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUInputElement.cpp +151 -0
  24. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUInputElement.h +119 -0
  25. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUOutputElement.cpp +62 -0
  26. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUOutputElement.h +66 -0
  27. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUPlugInDispatch.cpp +615 -0
  28. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUPlugInDispatch.h +128 -0
  29. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUScopeElement.cpp +512 -0
  30. cyfaust/resources/architecture/AU/AUPublic/AUBase/AUScopeElement.h +544 -0
  31. cyfaust/resources/architecture/AU/AUPublic/AUBase/ComponentBase.cpp +370 -0
  32. cyfaust/resources/architecture/AU/AUPublic/AUBase/ComponentBase.h +340 -0
  33. cyfaust/resources/architecture/AU/AUPublic/AUEffectBase/AUEffectBase.cpp +463 -0
  34. cyfaust/resources/architecture/AU/AUPublic/AUEffectBase/AUEffectBase.h +391 -0
  35. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp +837 -0
  36. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUInstrumentBase.h +267 -0
  37. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUMIDIBase.cpp +495 -0
  38. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUMIDIBase.h +213 -0
  39. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/LockFreeFIFO.h +168 -0
  40. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MIDIControlHandler.h +92 -0
  41. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MusicDeviceBase.cpp +354 -0
  42. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MusicDeviceBase.h +126 -0
  43. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthElement.cpp +419 -0
  44. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthElement.h +227 -0
  45. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthEvent.h +145 -0
  46. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNote.cpp +138 -0
  47. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNote.h +186 -0
  48. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNoteList.cpp +93 -0
  49. cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNoteList.h +232 -0
  50. cyfaust/resources/architecture/AU/AUPublic/Utility/AUBaseHelper.cpp +134 -0
  51. cyfaust/resources/architecture/AU/AUPublic/Utility/AUBaseHelper.h +80 -0
  52. cyfaust/resources/architecture/AU/AUPublic/Utility/AUBuffer.cpp +217 -0
  53. cyfaust/resources/architecture/AU/AUPublic/Utility/AUBuffer.h +267 -0
  54. cyfaust/resources/architecture/AU/AUPublic/Utility/AUMIDIDefs.h +136 -0
  55. cyfaust/resources/architecture/AU/AUPublic/Utility/AUSilentTimeout.h +93 -0
  56. cyfaust/resources/architecture/AU/English.lproj/InfoPlist.strings +0 -0
  57. cyfaust/resources/architecture/AU/FaustAU.exp +2 -0
  58. cyfaust/resources/architecture/AU/FaustAU.xcodeproj/project.pbxproj +968 -0
  59. cyfaust/resources/architecture/AU/FaustAU.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  60. cyfaust/resources/architecture/AU/FaustAUCustomView.plist +14 -0
  61. cyfaust/resources/architecture/AU/Info.plist +47 -0
  62. cyfaust/resources/architecture/AU/PublicUtility/CAAtomic.h +305 -0
  63. cyfaust/resources/architecture/AU/PublicUtility/CAAtomicStack.h +239 -0
  64. cyfaust/resources/architecture/AU/PublicUtility/CAAudioChannelLayout.cpp +153 -0
  65. cyfaust/resources/architecture/AU/PublicUtility/CAAudioChannelLayout.h +199 -0
  66. cyfaust/resources/architecture/AU/PublicUtility/CAAutoDisposer.h +508 -0
  67. cyfaust/resources/architecture/AU/PublicUtility/CABufferList.cpp +264 -0
  68. cyfaust/resources/architecture/AU/PublicUtility/CABufferList.h +319 -0
  69. cyfaust/resources/architecture/AU/PublicUtility/CAByteOrder.h +161 -0
  70. cyfaust/resources/architecture/AU/PublicUtility/CADebugMacros.cpp +88 -0
  71. cyfaust/resources/architecture/AU/PublicUtility/CADebugMacros.h +580 -0
  72. cyfaust/resources/architecture/AU/PublicUtility/CADebugPrintf.cpp +89 -0
  73. cyfaust/resources/architecture/AU/PublicUtility/CADebugPrintf.h +115 -0
  74. cyfaust/resources/architecture/AU/PublicUtility/CADebugger.cpp +77 -0
  75. cyfaust/resources/architecture/AU/PublicUtility/CADebugger.h +56 -0
  76. cyfaust/resources/architecture/AU/PublicUtility/CAException.h +83 -0
  77. cyfaust/resources/architecture/AU/PublicUtility/CAGuard.cpp +339 -0
  78. cyfaust/resources/architecture/AU/PublicUtility/CAGuard.h +133 -0
  79. cyfaust/resources/architecture/AU/PublicUtility/CAHostTimeBase.cpp +110 -0
  80. cyfaust/resources/architecture/AU/PublicUtility/CAHostTimeBase.h +231 -0
  81. cyfaust/resources/architecture/AU/PublicUtility/CALogMacros.h +140 -0
  82. cyfaust/resources/architecture/AU/PublicUtility/CAMath.h +68 -0
  83. cyfaust/resources/architecture/AU/PublicUtility/CAMutex.cpp +345 -0
  84. cyfaust/resources/architecture/AU/PublicUtility/CAMutex.h +163 -0
  85. cyfaust/resources/architecture/AU/PublicUtility/CAReferenceCounted.h +87 -0
  86. cyfaust/resources/architecture/AU/PublicUtility/CAStreamBasicDescription.cpp +795 -0
  87. cyfaust/resources/architecture/AU/PublicUtility/CAStreamBasicDescription.h +409 -0
  88. cyfaust/resources/architecture/AU/PublicUtility/CAThreadSafeList.h +255 -0
  89. cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnit.cpp +191 -0
  90. cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnit.h +100 -0
  91. cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnitTypes.h +59 -0
  92. cyfaust/resources/architecture/AU/PublicUtility/CAXException.cpp +49 -0
  93. cyfaust/resources/architecture/AU/PublicUtility/CAXException.h +338 -0
  94. cyfaust/resources/architecture/AU/SectionPatternLight.tiff +0 -0
  95. cyfaust/resources/architecture/AU/Source/AUSource/FaustAU.h +38 -0
  96. cyfaust/resources/architecture/AU/Source/AUSource/FaustAU.r +153 -0
  97. cyfaust/resources/architecture/AU/Source/AUSource/FaustAUVersion.h +64 -0
  98. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Bargraph.h +18 -0
  99. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Bargraph.m +21 -0
  100. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Button.h +20 -0
  101. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Button.m +56 -0
  102. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomView.h +87 -0
  103. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomView.m +834 -0
  104. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomViewFactory.h +13 -0
  105. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomViewFactory.m +22 -0
  106. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Knob.h +81 -0
  107. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Knob.m +199 -0
  108. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Slider.h +18 -0
  109. cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Slider.m +21 -0
  110. cyfaust/resources/architecture/AU/version.plist +16 -0
  111. cyfaust/resources/architecture/VST/Info.plist +28 -0
  112. cyfaust/resources/architecture/VST/PkgInfo +1 -0
  113. cyfaust/resources/architecture/VST/README +11 -0
  114. cyfaust/resources/architecture/VST/VST.xcode/project.pbxproj +655 -0
  115. cyfaust/resources/architecture/alsa-console.cpp +246 -0
  116. cyfaust/resources/architecture/alsa-gtk.cpp +220 -0
  117. cyfaust/resources/architecture/alsa-qt.cpp +229 -0
  118. cyfaust/resources/architecture/api/DspFaust.cpp +612 -0
  119. cyfaust/resources/architecture/api/DspFaust.h +511 -0
  120. cyfaust/resources/architecture/api/README.md +237 -0
  121. cyfaust/resources/architecture/api/doc/Generic.md +38 -0
  122. cyfaust/resources/architecture/au-effect.cpp +487 -0
  123. cyfaust/resources/architecture/au-instrument.cpp +573 -0
  124. cyfaust/resources/architecture/bench.cpp +91 -0
  125. cyfaust/resources/architecture/c-jack-gtk.c +227 -0
  126. cyfaust/resources/architecture/ca-gtk.cpp +284 -0
  127. cyfaust/resources/architecture/ca-qt.cpp +424 -0
  128. cyfaust/resources/architecture/cpal.rs +195 -0
  129. cyfaust/resources/architecture/csound.cpp +245 -0
  130. cyfaust/resources/architecture/csvplot.cpp +227 -0
  131. cyfaust/resources/architecture/daisy/Makefile +14 -0
  132. cyfaust/resources/architecture/daisy/README.md +50 -0
  133. cyfaust/resources/architecture/daisy/ex_faust.cpp +173 -0
  134. cyfaust/resources/architecture/dssi.cpp +1262 -0
  135. cyfaust/resources/architecture/dummy-mem.cpp +186 -0
  136. cyfaust/resources/architecture/dummy.cpp +294 -0
  137. cyfaust/resources/architecture/faust/au/AUUI.h +404 -0
  138. cyfaust/resources/architecture/faust/audio/alsa-dsp.h +693 -0
  139. cyfaust/resources/architecture/faust/audio/android-dsp.h +583 -0
  140. cyfaust/resources/architecture/faust/audio/audio.h +115 -0
  141. cyfaust/resources/architecture/faust/audio/channels.h +122 -0
  142. cyfaust/resources/architecture/faust/audio/coreaudio-dsp.h +1543 -0
  143. cyfaust/resources/architecture/faust/audio/coreaudio-ios-dsp.h +743 -0
  144. cyfaust/resources/architecture/faust/audio/dummy-audio.h +255 -0
  145. cyfaust/resources/architecture/faust/audio/esp32-dsp.h +284 -0
  146. cyfaust/resources/architecture/faust/audio/fpe.h +164 -0
  147. cyfaust/resources/architecture/faust/audio/jack-dsp.h +534 -0
  148. cyfaust/resources/architecture/faust/audio/juce-dsp.h +119 -0
  149. cyfaust/resources/architecture/faust/audio/netjack-dsp.h +354 -0
  150. cyfaust/resources/architecture/faust/audio/oboe-dsp.h +308 -0
  151. cyfaust/resources/architecture/faust/audio/ofaudio-dsp.h +155 -0
  152. cyfaust/resources/architecture/faust/audio/opensles-android-dsp.h +631 -0
  153. cyfaust/resources/architecture/faust/audio/osc-dsp.h +120 -0
  154. cyfaust/resources/architecture/faust/audio/portaudio-dsp.h +236 -0
  155. cyfaust/resources/architecture/faust/audio/rtaudio-dsp.h +241 -0
  156. cyfaust/resources/architecture/faust/audio/samAudio.h +140 -0
  157. cyfaust/resources/architecture/faust/audio/teensy-dsp.h +171 -0
  158. cyfaust/resources/architecture/faust/dsp/cmajor-cpp-dsp.h +253 -0
  159. cyfaust/resources/architecture/faust/dsp/cmajorpatch-dsp.h +483 -0
  160. cyfaust/resources/architecture/faust/dsp/cpp-dsp-adapter.h +38 -0
  161. cyfaust/resources/architecture/faust/dsp/dsp-adapter.h +836 -0
  162. cyfaust/resources/architecture/faust/dsp/dsp-bench.h +611 -0
  163. cyfaust/resources/architecture/faust/dsp/dsp-checker.h +115 -0
  164. cyfaust/resources/architecture/faust/dsp/dsp-combiner.h +810 -0
  165. cyfaust/resources/architecture/faust/dsp/dsp-compute-adapter.h +159 -0
  166. cyfaust/resources/architecture/faust/dsp/dsp-multi.h +702 -0
  167. cyfaust/resources/architecture/faust/dsp/dsp-multifun.h +90 -0
  168. cyfaust/resources/architecture/faust/dsp/dsp-optimizer.h +511 -0
  169. cyfaust/resources/architecture/faust/dsp/dsp-tools.h +229 -0
  170. cyfaust/resources/architecture/faust/dsp/dsp.h +321 -0
  171. cyfaust/resources/architecture/faust/dsp/fastmath.cpp +301 -0
  172. cyfaust/resources/architecture/faust/dsp/faust-dynamic-engine.cpp +494 -0
  173. cyfaust/resources/architecture/faust/dsp/faust-dynamic-engine.h +386 -0
  174. cyfaust/resources/architecture/faust/dsp/faust-engine.h +75 -0
  175. cyfaust/resources/architecture/faust/dsp/faust-poly-engine.h +638 -0
  176. cyfaust/resources/architecture/faust/dsp/interpreter-dsp-c.h +288 -0
  177. cyfaust/resources/architecture/faust/dsp/interpreter-dsp.h +362 -0
  178. cyfaust/resources/architecture/faust/dsp/interpreter-machine-dsp.h +233 -0
  179. cyfaust/resources/architecture/faust/dsp/libfaust-box-c.h +817 -0
  180. cyfaust/resources/architecture/faust/dsp/libfaust-box.h +889 -0
  181. cyfaust/resources/architecture/faust/dsp/libfaust-c.h +116 -0
  182. cyfaust/resources/architecture/faust/dsp/libfaust-signal-c.h +649 -0
  183. cyfaust/resources/architecture/faust/dsp/libfaust-signal.h +731 -0
  184. cyfaust/resources/architecture/faust/dsp/llvm-dsp-adapter.h +160 -0
  185. cyfaust/resources/architecture/faust/dsp/llvm-dsp-c.h +524 -0
  186. cyfaust/resources/architecture/faust/dsp/llvm-dsp.h +575 -0
  187. cyfaust/resources/architecture/faust/dsp/llvm-machine-dsp.h +215 -0
  188. cyfaust/resources/architecture/faust/dsp/one-sample-dsp.h +477 -0
  189. cyfaust/resources/architecture/faust/dsp/poly-dsp.h +1079 -0
  190. cyfaust/resources/architecture/faust/dsp/poly-interpreter-dsp.h +143 -0
  191. cyfaust/resources/architecture/faust/dsp/poly-llvm-dsp.h +249 -0
  192. cyfaust/resources/architecture/faust/dsp/poly-wasm-dsp.h +257 -0
  193. cyfaust/resources/architecture/faust/dsp/proxy-dsp.h +108 -0
  194. cyfaust/resources/architecture/faust/dsp/proxy-osc-dsp.h +109 -0
  195. cyfaust/resources/architecture/faust/dsp/rnbo-dsp.h +187 -0
  196. cyfaust/resources/architecture/faust/dsp/sound-player.h +428 -0
  197. cyfaust/resources/architecture/faust/dsp/timed-dsp.h +279 -0
  198. cyfaust/resources/architecture/faust/dsp/wasm-dsp-imp.h +188 -0
  199. cyfaust/resources/architecture/faust/dsp/wasm-dsp.h +309 -0
  200. cyfaust/resources/architecture/faust/dsp/ysfx-dsp.h +188 -0
  201. cyfaust/resources/architecture/faust/export.h +61 -0
  202. cyfaust/resources/architecture/faust/gui/APIUI.h +726 -0
  203. cyfaust/resources/architecture/faust/gui/BelaOSCUI.h +170 -0
  204. cyfaust/resources/architecture/faust/gui/CGlue.h +667 -0
  205. cyfaust/resources/architecture/faust/gui/CInterface.h +142 -0
  206. cyfaust/resources/architecture/faust/gui/ControlSequenceUI.h +197 -0
  207. cyfaust/resources/architecture/faust/gui/ControlUI.h +137 -0
  208. cyfaust/resources/architecture/faust/gui/DaisyControlUI.h +283 -0
  209. cyfaust/resources/architecture/faust/gui/DaisyPatchInitControlUI.h +254 -0
  210. cyfaust/resources/architecture/faust/gui/DecoratorUI.h +115 -0
  211. cyfaust/resources/architecture/faust/gui/Esp32ControlUI.h +341 -0
  212. cyfaust/resources/architecture/faust/gui/Esp32Reader.h +102 -0
  213. cyfaust/resources/architecture/faust/gui/Esp32SensorUI.h +137 -0
  214. cyfaust/resources/architecture/faust/gui/FUI.h +147 -0
  215. cyfaust/resources/architecture/faust/gui/GTKUI.h +1414 -0
  216. cyfaust/resources/architecture/faust/gui/GUI.h +465 -0
  217. cyfaust/resources/architecture/faust/gui/JSONControl.h +48 -0
  218. cyfaust/resources/architecture/faust/gui/JSONUI.h +722 -0
  219. cyfaust/resources/architecture/faust/gui/JSONUIDecoder.h +589 -0
  220. cyfaust/resources/architecture/faust/gui/JuceGUI.h +2061 -0
  221. cyfaust/resources/architecture/faust/gui/JuceOSCUI.h +163 -0
  222. cyfaust/resources/architecture/faust/gui/JuceParameterUI.h +158 -0
  223. cyfaust/resources/architecture/faust/gui/JuceReader.h +103 -0
  224. cyfaust/resources/architecture/faust/gui/JuceStateUI.h +88 -0
  225. cyfaust/resources/architecture/faust/gui/LayoutUI.h +423 -0
  226. cyfaust/resources/architecture/faust/gui/LibsndfileReader.h +366 -0
  227. cyfaust/resources/architecture/faust/gui/MapUI.h +370 -0
  228. cyfaust/resources/architecture/faust/gui/MemoryReader.h +111 -0
  229. cyfaust/resources/architecture/faust/gui/MetaDataUI.h +357 -0
  230. cyfaust/resources/architecture/faust/gui/MidiUI.h +939 -0
  231. cyfaust/resources/architecture/faust/gui/OCVUI.h +688 -0
  232. cyfaust/resources/architecture/faust/gui/OSCUI.h +219 -0
  233. cyfaust/resources/architecture/faust/gui/PathBuilder.h +228 -0
  234. cyfaust/resources/architecture/faust/gui/PresetUI.h +337 -0
  235. cyfaust/resources/architecture/faust/gui/PrintCUI.h +152 -0
  236. cyfaust/resources/architecture/faust/gui/PrintUI.h +121 -0
  237. cyfaust/resources/architecture/faust/gui/QTUI.h +1891 -0
  238. cyfaust/resources/architecture/faust/gui/RosCI.h +493 -0
  239. cyfaust/resources/architecture/faust/gui/RosUI.h +488 -0
  240. cyfaust/resources/architecture/faust/gui/SaveUI.h +163 -0
  241. cyfaust/resources/architecture/faust/gui/SimpleParser.h +583 -0
  242. cyfaust/resources/architecture/faust/gui/SoundUI.h +217 -0
  243. cyfaust/resources/architecture/faust/gui/Soundfile.h +342 -0
  244. cyfaust/resources/architecture/faust/gui/Styles/Blue.qrc +5 -0
  245. cyfaust/resources/architecture/faust/gui/Styles/Blue.qss +177 -0
  246. cyfaust/resources/architecture/faust/gui/Styles/Default.qrc +5 -0
  247. cyfaust/resources/architecture/faust/gui/Styles/Default.qss +117 -0
  248. cyfaust/resources/architecture/faust/gui/Styles/Grey.qrc +5 -0
  249. cyfaust/resources/architecture/faust/gui/Styles/Grey.qss +174 -0
  250. cyfaust/resources/architecture/faust/gui/Styles/Salmon.qrc +5 -0
  251. cyfaust/resources/architecture/faust/gui/Styles/Salmon.qss +171 -0
  252. cyfaust/resources/architecture/faust/gui/UI.h +87 -0
  253. cyfaust/resources/architecture/faust/gui/ValueConverter.h +543 -0
  254. cyfaust/resources/architecture/faust/gui/WaveReader.h +364 -0
  255. cyfaust/resources/architecture/faust/gui/console.h +322 -0
  256. cyfaust/resources/architecture/faust/gui/httpdUI.h +372 -0
  257. cyfaust/resources/architecture/faust/gui/meta.h +39 -0
  258. cyfaust/resources/architecture/faust/gui/mspUI.h +580 -0
  259. cyfaust/resources/architecture/faust/gui/qrcodegen.h +269 -0
  260. cyfaust/resources/architecture/faust/gui/qrcodegen.impl.h +1025 -0
  261. cyfaust/resources/architecture/faust/gui/ring-buffer.h +414 -0
  262. cyfaust/resources/architecture/faust/midi/RtMidi.cpp +3054 -0
  263. cyfaust/resources/architecture/faust/midi/RtMidi.h +1034 -0
  264. cyfaust/resources/architecture/faust/midi/bela-midi.h +266 -0
  265. cyfaust/resources/architecture/faust/midi/daisy-midi.h +116 -0
  266. cyfaust/resources/architecture/faust/midi/esp32-midi.h +185 -0
  267. cyfaust/resources/architecture/faust/midi/gramophone-midi.h +107 -0
  268. cyfaust/resources/architecture/faust/midi/iplug2-midi.h +148 -0
  269. cyfaust/resources/architecture/faust/midi/jack-midi.h +247 -0
  270. cyfaust/resources/architecture/faust/midi/juce-midi.h +275 -0
  271. cyfaust/resources/architecture/faust/midi/midi.h +475 -0
  272. cyfaust/resources/architecture/faust/midi/rt-midi.h +315 -0
  273. cyfaust/resources/architecture/faust/midi/teensy-midi.h +89 -0
  274. cyfaust/resources/architecture/faust/misc.h +106 -0
  275. cyfaust/resources/architecture/faust/sound-file.h +132 -0
  276. cyfaust/resources/architecture/faust/unity/AudioPluginInterface.h +301 -0
  277. cyfaust/resources/architecture/faust/vst/faust.h +141 -0
  278. cyfaust/resources/architecture/faust/vst/voice.h +43 -0
  279. cyfaust/resources/architecture/faust/vst/vstui.h +524 -0
  280. cyfaust/resources/architecture/faustvst.cpp +3435 -0
  281. cyfaust/resources/architecture/faustvstqt.h +91 -0
  282. cyfaust/resources/architecture/gen-json.cpp +76 -0
  283. cyfaust/resources/architecture/jack-console.cpp +267 -0
  284. cyfaust/resources/architecture/jack-gtk-ros.cpp +139 -0
  285. cyfaust/resources/architecture/jack-gtk.cpp +282 -0
  286. cyfaust/resources/architecture/jack-internal.cpp +560 -0
  287. cyfaust/resources/architecture/jack-qt-chain-footer.cpp +87 -0
  288. cyfaust/resources/architecture/jack-qt-chain-header.cpp +92 -0
  289. cyfaust/resources/architecture/jack-qt.cpp +281 -0
  290. cyfaust/resources/architecture/jack.rs +171 -0
  291. cyfaust/resources/architecture/juce/README.md +84 -0
  292. cyfaust/resources/architecture/juce/juce-plugin.cpp +809 -0
  293. cyfaust/resources/architecture/juce/juce-standalone.cpp +413 -0
  294. cyfaust/resources/architecture/juce/plugin/plugin-llvm.jucer +184 -0
  295. cyfaust/resources/architecture/juce/plugin/plugin.jucer +159 -0
  296. cyfaust/resources/architecture/juce/standalone/standalone-llvm.jucer +216 -0
  297. cyfaust/resources/architecture/juce/standalone/standalone.jucer +191 -0
  298. cyfaust/resources/architecture/ladspa.cpp +543 -0
  299. cyfaust/resources/architecture/latexheader.tex +65 -0
  300. cyfaust/resources/architecture/lv2.cpp +2090 -0
  301. cyfaust/resources/architecture/lv2qtgui.h +62 -0
  302. cyfaust/resources/architecture/lv2ui.cpp +1966 -0
  303. cyfaust/resources/architecture/max-msp/README.md +109 -0
  304. cyfaust/resources/architecture/max-msp/faustgen-wrapper-poly.maxpat +184 -0
  305. cyfaust/resources/architecture/max-msp/faustgen-wrapper.maxpat +163 -0
  306. cyfaust/resources/architecture/max-msp/max-msp.cpp +734 -0
  307. cyfaust/resources/architecture/max-msp/max-msp64.cpp +789 -0
  308. cyfaust/resources/architecture/max-msp/py2max/README.md +277 -0
  309. cyfaust/resources/architecture/max-msp/py2max/py2max/__init__.py +3 -0
  310. cyfaust/resources/architecture/max-msp/py2max/py2max/common.py +7 -0
  311. cyfaust/resources/architecture/max-msp/py2max/py2max/core.py +1387 -0
  312. cyfaust/resources/architecture/max-msp/py2max/py2max/maxclassdb.py +318 -0
  313. cyfaust/resources/architecture/max-msp/py2max/py2max/utils.py +20 -0
  314. cyfaust/resources/architecture/max-msp/rnbo.py +1591 -0
  315. cyfaust/resources/architecture/max-msp/sndfile/sndfile.h +857 -0
  316. cyfaust/resources/architecture/max-msp/ui.js +230 -0
  317. cyfaust/resources/architecture/max-msp/wrapper-poly.maxpat +153 -0
  318. cyfaust/resources/architecture/max-msp/wrapper.maxpat +131 -0
  319. cyfaust/resources/architecture/minimal-bench.cpp +100 -0
  320. cyfaust/resources/architecture/minimal-effect.c +149 -0
  321. cyfaust/resources/architecture/minimal-effect.cpp +70 -0
  322. cyfaust/resources/architecture/minimal-fixed-point.cpp +195 -0
  323. cyfaust/resources/architecture/minimal-static.cpp +160 -0
  324. cyfaust/resources/architecture/minimal.c +103 -0
  325. cyfaust/resources/architecture/minimal.cpp +84 -0
  326. cyfaust/resources/architecture/minimal.rs +223 -0
  327. cyfaust/resources/architecture/module.cpp +91 -0
  328. cyfaust/resources/architecture/octave.cpp +471 -0
  329. cyfaust/resources/architecture/oscio-gtk.cpp +115 -0
  330. cyfaust/resources/architecture/oscio-qt.cpp +121 -0
  331. cyfaust/resources/architecture/owl.cpp +345 -0
  332. cyfaust/resources/architecture/pa-gtk.cpp +119 -0
  333. cyfaust/resources/architecture/pa-qt.cpp +261 -0
  334. cyfaust/resources/architecture/path-printer.cpp +100 -0
  335. cyfaust/resources/architecture/plot.cpp +128 -0
  336. cyfaust/resources/architecture/portaudio.rs +192 -0
  337. cyfaust/resources/architecture/puredata.cpp +636 -0
  338. cyfaust/resources/architecture/ra-qt.cpp +238 -0
  339. cyfaust/resources/architecture/sam/fast_pow2.h +69 -0
  340. cyfaust/resources/architecture/sam/fastexp.h +140 -0
  341. cyfaust/resources/architecture/sam/samFaustDSP.cpp +125 -0
  342. cyfaust/resources/architecture/sam/samFaustDSP.h +107 -0
  343. cyfaust/resources/architecture/scheduler.cpp +1391 -0
  344. cyfaust/resources/architecture/sndfile.cpp +291 -0
  345. cyfaust/resources/architecture/supercollider.cpp +611 -0
  346. cyfaust/resources/architecture/teensy/README.md +13 -0
  347. cyfaust/resources/architecture/teensy/teensy.cpp +214 -0
  348. cyfaust/resources/architecture/teensy/teensy.h +71 -0
  349. cyfaust/resources/architecture/thread.h +373 -0
  350. cyfaust/resources/architecture/vcvrack/README.md +78 -0
  351. cyfaust/resources/architecture/vcvrack/template/.gitignore +6 -0
  352. cyfaust/resources/architecture/vcvrack/template/Makefile +22 -0
  353. cyfaust/resources/architecture/vcvrack/template/res/FaustModule.svg +299 -0
  354. cyfaust/resources/architecture/vcvrack/template/src/FaustModule.cpp +942 -0
  355. cyfaust/resources/architecture/vst.cpp +947 -0
  356. cyfaust/resources/libraries/aanl.lib +900 -0
  357. cyfaust/resources/libraries/all.lib +36 -0
  358. cyfaust/resources/libraries/analyzers.lib +980 -0
  359. cyfaust/resources/libraries/basics.lib +2681 -0
  360. cyfaust/resources/libraries/compressors.lib +1341 -0
  361. cyfaust/resources/libraries/delays.lib +401 -0
  362. cyfaust/resources/libraries/demos.lib +1556 -0
  363. cyfaust/resources/libraries/dx7.lib +1036 -0
  364. cyfaust/resources/libraries/effect.lib +1645 -0
  365. cyfaust/resources/libraries/envelopes.lib +666 -0
  366. cyfaust/resources/libraries/examples/README.md +13 -0
  367. cyfaust/resources/libraries/examples/ambisonics/fourSourcesToOcto.dsp +20 -0
  368. cyfaust/resources/libraries/examples/ambisonics/oneSourceToStereo.dsp +12 -0
  369. cyfaust/resources/libraries/examples/analysis/FFT.dsp +26 -0
  370. cyfaust/resources/libraries/examples/analysis/dbmeter.dsp +19 -0
  371. cyfaust/resources/libraries/examples/analysis/spectralLevel.dsp +8 -0
  372. cyfaust/resources/libraries/examples/analysis/spectralTiltLab.dsp +20 -0
  373. cyfaust/resources/libraries/examples/analysis/vumeter.dsp +18 -0
  374. cyfaust/resources/libraries/examples/autodiff/delay/diff.dsp +2 -0
  375. cyfaust/resources/libraries/examples/autodiff/delay/gt.dsp +2 -0
  376. cyfaust/resources/libraries/examples/autodiff/gain/diff.dsp +7 -0
  377. cyfaust/resources/libraries/examples/autodiff/gain/gt.dsp +1 -0
  378. cyfaust/resources/libraries/examples/autodiff/gain_dc/diff.dsp +7 -0
  379. cyfaust/resources/libraries/examples/autodiff/gain_dc/gt.dsp +4 -0
  380. cyfaust/resources/libraries/examples/autodiff/gain_exp/diff.dsp +9 -0
  381. cyfaust/resources/libraries/examples/autodiff/gain_exp/gt.dsp +1 -0
  382. cyfaust/resources/libraries/examples/autodiff/gain_pow/diff.dsp +9 -0
  383. cyfaust/resources/libraries/examples/autodiff/gain_pow/gt.dsp +1 -0
  384. cyfaust/resources/libraries/examples/autodiff/gain_pow_trig/diff.dsp +12 -0
  385. cyfaust/resources/libraries/examples/autodiff/gain_pow_trig/gt.dsp +1 -0
  386. cyfaust/resources/libraries/examples/autodiff/gain_sq/diff.dsp +7 -0
  387. cyfaust/resources/libraries/examples/autodiff/gain_sq/gt.dsp +1 -0
  388. cyfaust/resources/libraries/examples/autodiff/mem/diff.dsp +1 -0
  389. cyfaust/resources/libraries/examples/autodiff/mem/gt.dsp +1 -0
  390. cyfaust/resources/libraries/examples/autodiff/noise.dsp +2 -0
  391. cyfaust/resources/libraries/examples/autodiff/noop.dsp +2 -0
  392. cyfaust/resources/libraries/examples/autodiff/one_zero/diff.dsp +2 -0
  393. cyfaust/resources/libraries/examples/autodiff/one_zero/gt.dsp +2 -0
  394. cyfaust/resources/libraries/examples/autodiff/ramp.dsp +1 -0
  395. cyfaust/resources/libraries/examples/autodiff/recursion/diff.dsp +2 -0
  396. cyfaust/resources/libraries/examples/autodiff/recursion/gt.dsp +1 -0
  397. cyfaust/resources/libraries/examples/autodiff/recursion/target.dsp +13 -0
  398. cyfaust/resources/libraries/examples/autodiff/tremolo/diff.dsp +14 -0
  399. cyfaust/resources/libraries/examples/autodiff/tremolo/diffable.lib +7 -0
  400. cyfaust/resources/libraries/examples/autodiff/tremolo/gt.dsp +11 -0
  401. cyfaust/resources/libraries/examples/delayEcho/echo.dsp +15 -0
  402. cyfaust/resources/libraries/examples/delayEcho/quadEcho.dsp +21 -0
  403. cyfaust/resources/libraries/examples/delayEcho/smoothDelay.dsp +26 -0
  404. cyfaust/resources/libraries/examples/delayEcho/stereoEcho.dsp +16 -0
  405. cyfaust/resources/libraries/examples/delayEcho/tapiir.dsp +44 -0
  406. cyfaust/resources/libraries/examples/dynamic/compressor.dsp +8 -0
  407. cyfaust/resources/libraries/examples/dynamic/distortion.dsp +8 -0
  408. cyfaust/resources/libraries/examples/dynamic/gateCompressor.dsp +10 -0
  409. cyfaust/resources/libraries/examples/dynamic/noiseGate.dsp +8 -0
  410. cyfaust/resources/libraries/examples/dynamic/volume.dsp +15 -0
  411. cyfaust/resources/libraries/examples/filtering/APF.dsp +13 -0
  412. cyfaust/resources/libraries/examples/filtering/BPF.dsp +13 -0
  413. cyfaust/resources/libraries/examples/filtering/DNN.dsp +25 -0
  414. cyfaust/resources/libraries/examples/filtering/HPF.dsp +13 -0
  415. cyfaust/resources/libraries/examples/filtering/LPF.dsp +13 -0
  416. cyfaust/resources/libraries/examples/filtering/bandFilter.dsp +44 -0
  417. cyfaust/resources/libraries/examples/filtering/cryBaby.dsp +4 -0
  418. cyfaust/resources/libraries/examples/filtering/diodeLadder.dsp +12 -0
  419. cyfaust/resources/libraries/examples/filtering/filterBank.dsp +6 -0
  420. cyfaust/resources/libraries/examples/filtering/graphicEqLab.dsp +10 -0
  421. cyfaust/resources/libraries/examples/filtering/highShelf.dsp +13 -0
  422. cyfaust/resources/libraries/examples/filtering/korg35HPF.dsp +13 -0
  423. cyfaust/resources/libraries/examples/filtering/korg35LPF.dsp +13 -0
  424. cyfaust/resources/libraries/examples/filtering/lfBoost.dsp +40 -0
  425. cyfaust/resources/libraries/examples/filtering/lowBoost.dsp +40 -0
  426. cyfaust/resources/libraries/examples/filtering/lowCut.dsp +40 -0
  427. cyfaust/resources/libraries/examples/filtering/lowShelf.dsp +13 -0
  428. cyfaust/resources/libraries/examples/filtering/moogHalfLadder.dsp +12 -0
  429. cyfaust/resources/libraries/examples/filtering/moogLadder.dsp +12 -0
  430. cyfaust/resources/libraries/examples/filtering/moogVCF.dsp +6 -0
  431. cyfaust/resources/libraries/examples/filtering/multibandFilter.dsp +14 -0
  432. cyfaust/resources/libraries/examples/filtering/notch.dsp +13 -0
  433. cyfaust/resources/libraries/examples/filtering/oberheim.dsp +14 -0
  434. cyfaust/resources/libraries/examples/filtering/oberheimBPF.dsp +13 -0
  435. cyfaust/resources/libraries/examples/filtering/oberheimBSF.dsp +13 -0
  436. cyfaust/resources/libraries/examples/filtering/oberheimHPF.dsp +13 -0
  437. cyfaust/resources/libraries/examples/filtering/oberheimLPF.dsp +13 -0
  438. cyfaust/resources/libraries/examples/filtering/parametricEqLab.dsp +10 -0
  439. cyfaust/resources/libraries/examples/filtering/parametricEqualizer.dsp +6 -0
  440. cyfaust/resources/libraries/examples/filtering/peakNotch.dsp +13 -0
  441. cyfaust/resources/libraries/examples/filtering/peakingEQ.dsp +13 -0
  442. cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrder.dsp +14 -0
  443. cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderBPF.dsp +13 -0
  444. cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderHPF.dsp +13 -0
  445. cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderLPF.dsp +13 -0
  446. cyfaust/resources/libraries/examples/filtering/sallenKeyOnePole.dsp +13 -0
  447. cyfaust/resources/libraries/examples/filtering/sallenKeyOnePoleHPF.dsp +12 -0
  448. cyfaust/resources/libraries/examples/filtering/sallenKeyOnePoleLPF.dsp +12 -0
  449. cyfaust/resources/libraries/examples/filtering/spectralTilt.dsp +8 -0
  450. cyfaust/resources/libraries/examples/filtering/vcfWahLab.dsp +12 -0
  451. cyfaust/resources/libraries/examples/filtering/vocoder.dsp +8 -0
  452. cyfaust/resources/libraries/examples/filtering/wahPedal.dsp +6 -0
  453. cyfaust/resources/libraries/examples/gameaudio/bubble.dsp +42 -0
  454. cyfaust/resources/libraries/examples/gameaudio/door.dsp +58 -0
  455. cyfaust/resources/libraries/examples/gameaudio/fire.dsp +46 -0
  456. cyfaust/resources/libraries/examples/gameaudio/insects.dsp +148 -0
  457. cyfaust/resources/libraries/examples/gameaudio/rain.dsp +27 -0
  458. cyfaust/resources/libraries/examples/gameaudio/wind.dsp +23 -0
  459. cyfaust/resources/libraries/examples/generator/filterOsc.dsp +8 -0
  460. cyfaust/resources/libraries/examples/generator/noise.dsp +52 -0
  461. cyfaust/resources/libraries/examples/generator/noiseMetadata.dsp +74 -0
  462. cyfaust/resources/libraries/examples/generator/osc.dsp +17 -0
  463. cyfaust/resources/libraries/examples/generator/osci.dsp +17 -0
  464. cyfaust/resources/libraries/examples/generator/sawtoothLab.dsp +8 -0
  465. cyfaust/resources/libraries/examples/generator/virtualAnalog.dsp +8 -0
  466. cyfaust/resources/libraries/examples/generator/virtualAnalogLab.dsp +10 -0
  467. cyfaust/resources/libraries/examples/misc/UITester.dsp +71 -0
  468. cyfaust/resources/libraries/examples/misc/autopan.dsp +59 -0
  469. cyfaust/resources/libraries/examples/misc/capture.dsp +24 -0
  470. cyfaust/resources/libraries/examples/misc/drumkit.dsp +36 -0
  471. cyfaust/resources/libraries/examples/misc/guitarix.dsp +184 -0
  472. cyfaust/resources/libraries/examples/misc/matrix.dsp +17 -0
  473. cyfaust/resources/libraries/examples/misc/midiTester.dsp +122 -0
  474. cyfaust/resources/libraries/examples/misc/mixer.dsp +27 -0
  475. cyfaust/resources/libraries/examples/misc/statespace.dsp +39 -0
  476. cyfaust/resources/libraries/examples/misc/switcher.dsp +20 -0
  477. cyfaust/resources/libraries/examples/misc/tester.dsp +32 -0
  478. cyfaust/resources/libraries/examples/misc/tester2.dsp +31 -0
  479. cyfaust/resources/libraries/examples/old/README.md +5 -0
  480. cyfaust/resources/libraries/examples/old/freeverb.dsp +109 -0
  481. cyfaust/resources/libraries/examples/old/rewriting/Makefile +21 -0
  482. cyfaust/resources/libraries/examples/old/rewriting/fact.dsp +3 -0
  483. cyfaust/resources/libraries/examples/old/rewriting/fold.dsp +61 -0
  484. cyfaust/resources/libraries/examples/old/rewriting/mesh.dsp +43 -0
  485. cyfaust/resources/libraries/examples/old/rewriting/mesh.pd +37 -0
  486. cyfaust/resources/libraries/examples/old/rewriting/sample.pd +12 -0
  487. cyfaust/resources/libraries/examples/old/rewriting/serial.dsp +7 -0
  488. cyfaust/resources/libraries/examples/old/rewriting/sum.dsp +55 -0
  489. cyfaust/resources/libraries/examples/old/rewriting/test.pd +48 -0
  490. cyfaust/resources/libraries/examples/phasing/flanger.dsp +8 -0
  491. cyfaust/resources/libraries/examples/phasing/phaser.dsp +8 -0
  492. cyfaust/resources/libraries/examples/phasing/phaserFlangerLab.dsp +12 -0
  493. cyfaust/resources/libraries/examples/physicalModeling/brass.dsp +8 -0
  494. cyfaust/resources/libraries/examples/physicalModeling/brassMIDI.dsp +8 -0
  495. cyfaust/resources/libraries/examples/physicalModeling/churchBell.dsp +8 -0
  496. cyfaust/resources/libraries/examples/physicalModeling/clarinet.dsp +8 -0
  497. cyfaust/resources/libraries/examples/physicalModeling/clarinetMIDI.dsp +8 -0
  498. cyfaust/resources/libraries/examples/physicalModeling/djembeMIDI.dsp +8 -0
  499. cyfaust/resources/libraries/examples/physicalModeling/elecGuitarMIDI.dsp +10 -0
  500. cyfaust/resources/libraries/examples/physicalModeling/englishBell.dsp +8 -0
  501. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/NLFeks.dsp +91 -0
  502. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/NLFfm.dsp +70 -0
  503. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/README +125 -0
  504. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bass.dsp +84 -0
  505. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bass.h +91 -0
  506. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/blowBottle.dsp +102 -0
  507. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bowed.dsp +114 -0
  508. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/brass.dsp +103 -0
  509. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/clarinet.dsp +110 -0
  510. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/flute.dsp +116 -0
  511. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/fluteStk.dsp +121 -0
  512. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/glassHarmonica.dsp +131 -0
  513. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/harpsi.dsp +90 -0
  514. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/harpsichord.h +185 -0
  515. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/instrument.h +114 -0
  516. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/modalBar.dsp +122 -0
  517. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/modalBar.h +48 -0
  518. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/audio-out.pd +33 -0
  519. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/bottle.pd +10 -0
  520. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/clarinets.pd +15 -0
  521. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/audio-out.pd +33 -0
  522. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/bass.pd +162 -0
  523. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/canon.pd +55 -0
  524. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/flute.pd +343 -0
  525. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/pachelbel.mid +0 -0
  526. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/audio-out.pd +33 -0
  527. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/daisy.mid +0 -0
  528. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/daisy.pd +45 -0
  529. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/piano.pd +205 -0
  530. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/voiceForm.pd +340 -0
  531. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/audio-out.pd +33 -0
  532. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/blowHole.pd +330 -0
  533. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/piano.pd +205 -0
  534. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/take5.mid +0 -0
  535. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/take5.pd +45 -0
  536. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/audio-out.pd +33 -0
  537. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/harpsi.pd +204 -0
  538. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/turkish-march.mid +0 -0
  539. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/turkish-march.pd +31 -0
  540. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/audio-out.pd +33 -0
  541. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/bass.pd +162 -0
  542. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/modalBar.pd +258 -0
  543. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/piano.pd +205 -0
  544. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/what-a-friend.pd +52 -0
  545. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/what_a_friend.mid +0 -0
  546. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/flutes.pd +15 -0
  547. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fm.pd +10 -0
  548. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/glassBare.pd +10 -0
  549. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/harpsichord-poly.pd +10 -0
  550. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/ironBare.pd +10 -0
  551. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/midi-in.pd +111 -0
  552. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/modal.pd +10 -0
  553. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/osc.pd +26 -0
  554. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/piano-poly.pd +10 -0
  555. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/plucked.pd +20 -0
  556. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/saxophone.pd +10 -0
  557. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/tibetan.pd +10 -0
  558. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/trumpet.pd +10 -0
  559. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/violin.pd +10 -0
  560. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/voiceSynth.pd +10 -0
  561. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/woodenBare.pd +10 -0
  562. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/phonemes.h +189 -0
  563. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/piano.dsp +255 -0
  564. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/piano.h +751 -0
  565. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/saxophony.dsp +114 -0
  566. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/sitar.dsp +48 -0
  567. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/tibetanBowl.dsp +155 -0
  568. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/tunedBar.dsp +123 -0
  569. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/uniBar.dsp +100 -0
  570. cyfaust/resources/libraries/examples/physicalModeling/faust-stk/voiceForm.dsp +125 -0
  571. cyfaust/resources/libraries/examples/physicalModeling/fds/1dDampedWaveEquation.dsp +43 -0
  572. cyfaust/resources/libraries/examples/physicalModeling/fds/2dKirchhoffThinPlate.dsp +75 -0
  573. cyfaust/resources/libraries/examples/physicalModeling/fds/BowedString.dsp +61 -0
  574. cyfaust/resources/libraries/examples/physicalModeling/fds/ControllableNonPhysicalString.dsp +72 -0
  575. cyfaust/resources/libraries/examples/physicalModeling/fds/HammeredString.dsp +74 -0
  576. cyfaust/resources/libraries/examples/physicalModeling/fds/PianoHammeredString.dsp +85 -0
  577. cyfaust/resources/libraries/examples/physicalModeling/fds/StiffString.dsp +54 -0
  578. cyfaust/resources/libraries/examples/physicalModeling/flute.dsp +8 -0
  579. cyfaust/resources/libraries/examples/physicalModeling/fluteMIDI.dsp +8 -0
  580. cyfaust/resources/libraries/examples/physicalModeling/frenchBell.dsp +8 -0
  581. cyfaust/resources/libraries/examples/physicalModeling/germanBell.dsp +8 -0
  582. cyfaust/resources/libraries/examples/physicalModeling/guitarMIDI.dsp +8 -0
  583. cyfaust/resources/libraries/examples/physicalModeling/karplus.dsp +8 -0
  584. cyfaust/resources/libraries/examples/physicalModeling/marimbaMIDI.dsp +10 -0
  585. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator.dsp +58 -0
  586. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator2.dsp +62 -0
  587. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator3.dsp +65 -0
  588. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/01_ParamControl/paramOsc.dsp +63 -0
  589. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/02_AudioParamControl/audioParamOsc.dsp +63 -0
  590. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/03_HammerTime/hammerOsc.dsp +71 -0
  591. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/04_Gravity/bouncingOsc.dsp +64 -0
  592. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/05_PluckedOscillator/pluckedOsc.dsp +57 -0
  593. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/06_BowedOscillator/bowedOsc.dsp +65 -0
  594. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/07_NonLinearOscillator/nlOsc.dsp +78 -0
  595. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/08_TwoMassChain/2massChain.dsp +75 -0
  596. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/09_TinyString/tinyString.dsp +101 -0
  597. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/10_PluckedString/pluckedString.dsp +678 -0
  598. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/11_BowedString/bowedString.dsp +671 -0
  599. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/12_TriangleMesh/triangleMesh.dsp +448 -0
  600. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/13_Construction/construction.dsp +1036 -0
  601. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/14_Polyphonic/polyTriangle.dsp +79 -0
  602. cyfaust/resources/libraries/examples/physicalModeling/mi-faust/15_PhysicalLFO/physicalLFO.dsp +107 -0
  603. cyfaust/resources/libraries/examples/physicalModeling/modularInterpInstrMIDI.dsp +8 -0
  604. cyfaust/resources/libraries/examples/physicalModeling/nylonGuitarMIDI.dsp +8 -0
  605. cyfaust/resources/libraries/examples/physicalModeling/old/harpe.dsp +45 -0
  606. cyfaust/resources/libraries/examples/physicalModeling/old/karplus.dsp +34 -0
  607. cyfaust/resources/libraries/examples/physicalModeling/old/karplus32.dsp +47 -0
  608. cyfaust/resources/libraries/examples/physicalModeling/russianBell.dsp +8 -0
  609. cyfaust/resources/libraries/examples/physicalModeling/standardBell.dsp +8 -0
  610. cyfaust/resources/libraries/examples/physicalModeling/violin.dsp +8 -0
  611. cyfaust/resources/libraries/examples/physicalModeling/violinMIDI.dsp +8 -0
  612. cyfaust/resources/libraries/examples/physicalModeling/vocalBP.dsp +8 -0
  613. cyfaust/resources/libraries/examples/physicalModeling/vocalBPMIDI.dsp +8 -0
  614. cyfaust/resources/libraries/examples/physicalModeling/vocalFOF.dsp +8 -0
  615. cyfaust/resources/libraries/examples/physicalModeling/vocalFOFMIDI.dsp +8 -0
  616. cyfaust/resources/libraries/examples/pitchShifting/pitchShifter.dsp +20 -0
  617. cyfaust/resources/libraries/examples/psychoacoustic/harmonicExciter.dsp +10 -0
  618. cyfaust/resources/libraries/examples/quantizing/quantizedChords.dsp +49 -0
  619. cyfaust/resources/libraries/examples/reverb/dattorro.dsp +8 -0
  620. cyfaust/resources/libraries/examples/reverb/fdnRev.dsp +8 -0
  621. cyfaust/resources/libraries/examples/reverb/freeverb.dsp +8 -0
  622. cyfaust/resources/libraries/examples/reverb/greyhole.dsp +8 -0
  623. cyfaust/resources/libraries/examples/reverb/jprev.dsp +8 -0
  624. cyfaust/resources/libraries/examples/reverb/reverbDesigner.dsp +12 -0
  625. cyfaust/resources/libraries/examples/reverb/reverbTester.dsp +8 -0
  626. cyfaust/resources/libraries/examples/reverb/zitaRev.dsp +8 -0
  627. cyfaust/resources/libraries/examples/reverb/zitaRevFDN.dsp +8 -0
  628. cyfaust/resources/libraries/examples/smartKeyboard/acGuitar.dsp +100 -0
  629. cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/elecGuitarEffect.dsp +8 -0
  630. cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/myEffect.dsp +5 -0
  631. cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/reverb.dsp +5 -0
  632. cyfaust/resources/libraries/examples/smartKeyboard/bells.dsp +80 -0
  633. cyfaust/resources/libraries/examples/smartKeyboard/bowed.dsp +87 -0
  634. cyfaust/resources/libraries/examples/smartKeyboard/brass.dsp +82 -0
  635. cyfaust/resources/libraries/examples/smartKeyboard/clarinet.dsp +113 -0
  636. cyfaust/resources/libraries/examples/smartKeyboard/crazyGuiro.dsp +96 -0
  637. cyfaust/resources/libraries/examples/smartKeyboard/drums.dsp +74 -0
  638. cyfaust/resources/libraries/examples/smartKeyboard/dubDub.dsp +87 -0
  639. cyfaust/resources/libraries/examples/smartKeyboard/elecGuitar.dsp +67 -0
  640. cyfaust/resources/libraries/examples/smartKeyboard/fm.dsp +78 -0
  641. cyfaust/resources/libraries/examples/smartKeyboard/frog.dsp +74 -0
  642. cyfaust/resources/libraries/examples/smartKeyboard/harp.dsp +84 -0
  643. cyfaust/resources/libraries/examples/smartKeyboard/midiOnly.dsp +62 -0
  644. cyfaust/resources/libraries/examples/smartKeyboard/multiSynth.dsp +75 -0
  645. cyfaust/resources/libraries/examples/smartKeyboard/toy.dsp +71 -0
  646. cyfaust/resources/libraries/examples/smartKeyboard/trumpet.dsp +59 -0
  647. cyfaust/resources/libraries/examples/smartKeyboard/turenas.dsp +114 -0
  648. cyfaust/resources/libraries/examples/smartKeyboard/violin.dsp +91 -0
  649. cyfaust/resources/libraries/examples/smartKeyboard/violin2.dsp +84 -0
  650. cyfaust/resources/libraries/examples/smartKeyboard/vocal.dsp +43 -0
  651. cyfaust/resources/libraries/examples/spat/panpot.dsp +17 -0
  652. cyfaust/resources/libraries/examples/spat/spat.dsp +25 -0
  653. cyfaust/resources/libraries/fds.lib +535 -0
  654. cyfaust/resources/libraries/filter.lib +1710 -0
  655. cyfaust/resources/libraries/filters.lib +3125 -0
  656. cyfaust/resources/libraries/hoa.lib +1081 -0
  657. cyfaust/resources/libraries/instruments.lib +263 -0
  658. cyfaust/resources/libraries/interpolators.lib +675 -0
  659. cyfaust/resources/libraries/math.lib +602 -0
  660. cyfaust/resources/libraries/maths.lib +798 -0
  661. cyfaust/resources/libraries/maxmsp.lib +237 -0
  662. cyfaust/resources/libraries/mi.lib +528 -0
  663. cyfaust/resources/libraries/misceffects.lib +998 -0
  664. cyfaust/resources/libraries/music.lib +496 -0
  665. cyfaust/resources/libraries/noises.lib +487 -0
  666. cyfaust/resources/libraries/oscillator.lib +450 -0
  667. cyfaust/resources/libraries/oscillators.lib +1838 -0
  668. cyfaust/resources/libraries/phaflangers.lib +235 -0
  669. cyfaust/resources/libraries/physmodels.lib +3990 -0
  670. cyfaust/resources/libraries/platform.lib +59 -0
  671. cyfaust/resources/libraries/quantizers.lib +310 -0
  672. cyfaust/resources/libraries/reducemaps.lib +235 -0
  673. cyfaust/resources/libraries/reverbs.lib +686 -0
  674. cyfaust/resources/libraries/routes.lib +262 -0
  675. cyfaust/resources/libraries/sf.lib +53 -0
  676. cyfaust/resources/libraries/signals.lib +570 -0
  677. cyfaust/resources/libraries/soundfiles.lib +234 -0
  678. cyfaust/resources/libraries/spats.lib +173 -0
  679. cyfaust/resources/libraries/stdfaust.lib +38 -0
  680. cyfaust/resources/libraries/synths.lib +322 -0
  681. cyfaust/resources/libraries/tonestacks.lib +427 -0
  682. cyfaust/resources/libraries/tubes.lib +5039 -0
  683. cyfaust/resources/libraries/vaeffects.lib +984 -0
  684. cyfaust/resources/libraries/version.lib +22 -0
  685. cyfaust/resources/libraries/wdmodels.lib +2276 -0
  686. cyfaust/resources/libraries/webaudio.lib +402 -0
  687. cyfaust/signal.pxd +44 -0
  688. cyfaust/signal.pyx +1993 -0
  689. cyfaust-0.1.0.dist-info/METADATA +355 -0
  690. cyfaust-0.1.0.dist-info/RECORD +693 -0
  691. cyfaust-0.1.0.dist-info/WHEEL +5 -0
  692. cyfaust-0.1.0.dist-info/entry_points.txt +3 -0
  693. cyfaust-0.1.0.dist-info/licenses/LICENSE +26 -0
@@ -0,0 +1,3125 @@
1
+ //##################################### filters.lib ########################################
2
+ // Filters library. Its official prefix is `fi`.
3
+ //
4
+ // The Filters library is organized into 22 sections:
5
+ //
6
+ // * [Basic Filters](#basic-filters)
7
+ // * [Comb Filters](#comb-filters)
8
+ // * [Direct-Form Digital Filter Sections](#direct-form-digital-filter-sections)
9
+ // * [Direct-Form Second-Order Biquad Sections](#direct-form-second-order-biquad-sections)
10
+ // * [Ladder/Lattice Digital Filters](#ladderlattice-digital-filters)
11
+ // * [Useful Special Cases](#useful-special-cases)
12
+ // * [Ladder/Lattice Allpass Filters](#ladderlattice-allpass-filters)
13
+ // * [Digital Filter Sections Specified as Analog Filter Sections](#digital-filter-sections-specified-as-analog-filter-sections)
14
+ // * [Simple Resonator Filters](#simple-resonator-filters)
15
+ // * [Butterworth Lowpass/Highpass Filters](#butterworth-lowpasshighpass-filters)
16
+ // * [Special Filter-Bank Delay-Equalizing Allpass Filters](#special-filter-bank-delay-equalizing-allpass-filters)
17
+ // * [Elliptic (Cauer) Lowpass Filters](#elliptic-cauer-lowpass-filters)
18
+ // * [Elliptic Highpass Filters](#elliptic-highpass-filters)
19
+ // * [Butterworth Bandpass/Bandstop Filters](#butterworth-bandpassbandstop-filters)
20
+ // * [Elliptic Bandpass Filters](#elliptic-bandpass-filters)
21
+ // * [Parametric Equalizers (Shelf, Peaking)](#parametric-equalizers-shelf-peaking)
22
+ // * [Mth-Octave Filter-Banks](#mth-octave-filter-banks)
23
+ // * [Arbitrary-Crossover Filter-Banks and Spectrum Analyzers](#arbitrary-crossover-filter-banks-and-spectrum-analyzers)
24
+ // * [State Variable Filters (SVF)](#state-variable-filters)
25
+ // * [Linkwitz-Riley 4th-order 2-way, 3-way, and 4-way crossovers](#linkwitz-riley-4th-order-2-way-3-way-and-4-way-crossovers)
26
+ // * [Standardized Filters](#standardized-filters)
27
+ // * [Averaging Functions](#averaging-functions)
28
+ //
29
+ // #### References
30
+ // * <https://github.com/grame-cncm/faustlibraries/blob/master/filters.lib>
31
+ //
32
+ //########################################################################################
33
+
34
+ // NOTE ABOUT LICENSES:
35
+ // Each function in this library has its own license. Licenses are declared
36
+ // before each function. Corresponding license terms can be found at the
37
+ // bottom of this file or in the Faust libraries documentation.
38
+
39
+ ma = library("maths.lib");
40
+ ba = library("basics.lib");
41
+ ro = library("routes.lib");
42
+ de = library("delays.lib");
43
+ an = library("analyzers.lib");
44
+ ef = library("misceffects.lib");
45
+ si = library("signals.lib");
46
+ fi = library("filters.lib"); // for compatible copy/paste out of this file
47
+
48
+ declare name "Faust Filters Library";
49
+ declare version "1.3.0";
50
+
51
+ //===============================Basic Filters============================================
52
+ //========================================================================================
53
+
54
+ //----------------------`(fi.)zero`--------------------------
55
+ // One zero filter. Difference equation: \(y(n) = x(n) - zx(n-1)\).
56
+ //
57
+ // #### Usage
58
+ //
59
+ // ```
60
+ // _ : zero(z) : _
61
+ // ```
62
+ //
63
+ // Where:
64
+ //
65
+ // * `z`: location of zero along real axis in z-plane
66
+ //
67
+ // #### Reference
68
+ // <https://ccrma.stanford.edu/~jos/filters/One_Zero.html>
69
+ //----------------------------------------------------------
70
+ declare zero author "Julius O. Smith III";
71
+ declare zero copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
72
+ declare zero license "MIT-style STK-4.3 license";
73
+ zero(z) = _ <: _,mem : _,*(z) : -;
74
+
75
+ //------------------------`(fi.)pole`---------------------------
76
+ // One pole filter. Could also be called a "leaky integrator".
77
+ // Difference equation: \(y(n) = x(n) + py(n-1)\).
78
+ //
79
+ // #### Usage
80
+ //
81
+ // ```
82
+ // _ : pole(p) : _
83
+ // ```
84
+ //
85
+ // Where:
86
+ //
87
+ // * `p`: pole location = feedback coefficient
88
+ //
89
+ // #### Reference
90
+ // <https://ccrma.stanford.edu/~jos/filters/One_Pole.html>
91
+ //------------------------------------------------------------
92
+ declare pole author "Julius O. Smith III";
93
+ declare pole copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
94
+ declare pole license "MIT-style STK-4.3 license";
95
+ pole(p) = + ~ *(p);
96
+
97
+ //----------------------`(fi.)integrator`--------------------------
98
+ // Same as `pole(1)` [implemented separately for block-diagram clarity].
99
+ //------------------------------------------------------------
100
+ declare integrator author "Julius O. Smith III";
101
+ declare integrator copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
102
+ declare integrator license "MIT-style STK-4.3 license";
103
+ integrator = + ~ _;
104
+
105
+ //-------------------`(fi.)dcblockerat`-----------------------
106
+ // DC blocker with configurable break frequency.
107
+ // The amplitude response is substantially flat above \(fb\),
108
+ // and sloped at about +6 dB/octave below \(fb\).
109
+ // Derived from the analog transfer function:
110
+ // $$H(s) = \frac{s}{(s + 2 \pi fb)}$$
111
+ // (which can be seen as a 1st-order Butterworth highpass filter)
112
+ // by the low-frequency-matching bilinear transform method
113
+ // (i.e., the standard frequency-scaling constant 2*SR).
114
+ //
115
+ // #### Usage
116
+ //
117
+ // ```
118
+ // _ : dcblockerat(fb) : _
119
+ // ```
120
+ //
121
+ // Where:
122
+ //
123
+ // * `fb`: "break frequency" in Hz, i.e., -3 dB gain frequency.
124
+ //
125
+ // #### Reference
126
+ // <https://ccrma.stanford.edu/~jos/pasp/Bilinear_Transformation.html>
127
+ //------------------------------------------------------------
128
+ declare dcblockerat author "Julius O. Smith III";
129
+ declare dcblockerat copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
130
+ declare dcblockerat license "MIT-style STK-4.3 license";
131
+ dcblockerat(fb) = *(b0) : zero(1) : pole(p)
132
+ with {
133
+ wn = ma.PI*fb/ma.SR;
134
+ b0 = 1.0 / (1 + wn);
135
+ p = (1 - wn) * b0;
136
+ };
137
+
138
+ //----------------------`(fi.)dcblocker`--------------------------
139
+ // DC blocker. Default dc blocker has -3dB point near 35 Hz (at 44.1 kHz)
140
+ // and high-frequency gain near 1.0025 (due to no scaling).
141
+ // `dcblocker` is as standard Faust function.
142
+ //
143
+ // #### Usage
144
+ //
145
+ // ```
146
+ // _ : dcblocker : _
147
+ // ```
148
+ //------------------------------------------------------------
149
+ declare dcblocker author "Julius O. Smith III";
150
+ declare dcblocker copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
151
+ declare dcblocker license "MIT-style STK-4.3 license";
152
+ dcblocker = zero(1) : pole(0.995);
153
+
154
+ //----------------------------`(fi.)lptN`--------------------------------------
155
+ // One-pole lowpass filter with arbitrary dis/charging factors set in dB and
156
+ // times set in seconds.
157
+ //
158
+ // #### Usage
159
+ //
160
+ // ```
161
+ // _ : lptN(N, tN) : _
162
+ // ```
163
+ //
164
+ // Where:
165
+ //
166
+ // * `N`: is the attenuation factor in dB
167
+ // * `tN`: is the filter period in seconds, that is, the time for the
168
+ // impulse response to decay by `N` dB
169
+ //
170
+ // #### Reference
171
+ // <https://ccrma.stanford.edu/~jos/mdft/Exponentials.html>
172
+ //----------------------------------------------------------
173
+ declare lptN author "Julius O. Smith III";
174
+ declare lptN copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
175
+ declare lptN license "MIT-style STK-4.3 license";
176
+ lptN(N, tN, x) = x : si.smooth(ba.tau2pole(tN / log(10.0^(float(N)/20.0))));
177
+ // Special cases of lptN
178
+ lptau(tN, x) = lptN(8.6858896381, tN, x); // Tau time constant, i.e., 1/e atten. after tN secs
179
+ lpt60(tN, x) = lptN(60, tN, x); // T60 constant, i.e., 1/1000 atten. after tN secs
180
+ lpt19(tN, x) = lptN(19, tN, x); // T19 constant, i.e., 1/e^2.2 atten. after tN secs
181
+
182
+ //=======================================Comb Filters=====================================
183
+ //========================================================================================
184
+
185
+ //------`(fi.)ff_comb`--------
186
+ // Feed-Forward Comb Filter. Note that `ff_comb` requires integer delays
187
+ // (uses `delay` internally).
188
+ // `ff_comb` is a standard Faust function.
189
+ //
190
+ // #### Usage
191
+ //
192
+ // ```
193
+ // _ : ff_comb(maxdel,intdel,b0,bM) : _
194
+ // ```
195
+ //
196
+ // Where:
197
+ //
198
+ // * `maxdel`: maximum delay (a power of 2)
199
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
200
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
201
+ // * `b0`: gain applied to delay-line input
202
+ // * `bM`: gain applied to delay-line output and then summed with input
203
+ //
204
+ // #### Reference
205
+ // <https://ccrma.stanford.edu/~jos/pasp/Feedforward_Comb_Filters.html>
206
+ //------------------------------------------------------------
207
+ declare ff_comb author "Julius O. Smith III";
208
+ declare ff_comb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
209
+ declare ff_comb license "MIT-style STK-4.3 license";
210
+ ff_comb(maxdel,M,b0,bM) = _ <: *(b0), bM * de.delay(maxdel,M) : +;
211
+
212
+ //------`(fi.)ff_fcomb`--------
213
+ // Feed-Forward Comb Filter. Note that `ff_fcomb` takes floating-point delays
214
+ // (uses `fdelay` internally).
215
+ // `ff_fcomb` is a standard Faust function.
216
+ //
217
+ // #### Usage
218
+ //
219
+ // ```
220
+ // _ : ff_fcomb(maxdel,del,b0,bM) : _
221
+ // ```
222
+ //
223
+ // Where:
224
+ //
225
+ // * `maxdel`: maximum delay (a power of 2)
226
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
227
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
228
+ // * `b0`: gain applied to delay-line input
229
+ // * `bM`: gain applied to delay-line output and then summed with input
230
+ //
231
+ // #### Reference
232
+ // <https://ccrma.stanford.edu/~jos/pasp/Feedforward_Comb_Filters.html>
233
+ //------------------------------------------------------------
234
+ declare ff_fcomb author "Julius O. Smith III";
235
+ declare ff_fcomb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
236
+ declare ff_fcomb license "MIT-style STK-4.3 license";
237
+ ff_fcomb(maxdel,M,b0,bM) = _ <: *(b0), bM * de.fdelay(maxdel,M) : +;
238
+
239
+ //-----------`(fi.)ffcombfilter`-------------------
240
+ // Typical special case of `ff_comb()` where: `b0 = 1`.
241
+ //------------------------------------------------------------
242
+ declare ff_combfilter author "Julius O. Smith III";
243
+ declare ff_combfilter copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
244
+ declare ff_combfilter license "MIT-style STK-4.3 license";
245
+ ffcombfilter(maxdel,del,g) = ff_comb(maxdel,del,1,g);
246
+
247
+
248
+ //-----------------------`(fi.)fb_comb`-----------------------
249
+ // Feed-Back Comb Filter (integer delay).
250
+ //
251
+ // #### Usage
252
+ //
253
+ // ```
254
+ // _ : fb_comb(maxdel,intdel,b0,aN) : _
255
+ // ```
256
+ //
257
+ // Where:
258
+ //
259
+ // * `maxdel`: maximum delay (a power of 2)
260
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
261
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
262
+ // * `b0`: gain applied to delay-line input and forwarded to output
263
+ // * `aN`: minus the gain applied to delay-line output before summing with the input
264
+ // and feeding to the delay line
265
+ //
266
+ // #### Reference
267
+ // <https://ccrma.stanford.edu/~jos/pasp/Feedback_Comb_Filters.html>
268
+ //------------------------------------------------------------
269
+ declare fb_comb author "Julius O. Smith III";
270
+ declare fb_comb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
271
+ declare fb_comb license "MIT-style STK-4.3 license";
272
+ fb_comb(maxdel,N,b0,aN) = (+ <: de.delay(maxdel,N-1),_) ~ *(-aN) : !,*(b0) : mem;
273
+
274
+
275
+ //-----------------------`(fi.)fb_fcomb`-----------------------
276
+ // Feed-Back Comb Filter (floating point delay).
277
+ //
278
+ // #### Usage
279
+ //
280
+ // ```
281
+ // _ : fb_fcomb(maxdel,del,b0,aN) : _
282
+ // ```
283
+ //
284
+ // Where:
285
+ //
286
+ // * `maxdel`: maximum delay (a power of 2)
287
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
288
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
289
+ // * `b0`: gain applied to delay-line input and forwarded to output
290
+ // * `aN`: minus the gain applied to delay-line output before summing with the input
291
+ // and feeding to the delay line
292
+ //
293
+ // #### Reference
294
+ // <https://ccrma.stanford.edu/~jos/pasp/Feedback_Comb_Filters.html>
295
+ //------------------------------------------------------------
296
+ declare fb_fcomb author "Julius O. Smith III";
297
+ declare fb_fcomb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
298
+ declare fb_fcomb license "MIT-style STK-4.3 license";
299
+ fb_fcomb(maxdel,N,b0,aN) = (+ <: de.fdelay(maxdel,float(N)-1.0),_) ~ *(-aN) : !,*(b0) : mem;
300
+
301
+ //-----------------------`(fi.)rev1`-----------------------
302
+ // Special case of `fb_comb` (`rev1(maxdel,N,g)`).
303
+ // The "rev1 section" dates back to the 1960s in computer-music reverberation.
304
+ // See the `jcrev` and `brassrev` in `reverbs.lib` for usage examples.
305
+ //------------------------------------------------------------
306
+ declare rev1 author "Julius O. Smith III";
307
+ declare rev1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
308
+ declare rev1 license "MIT-style STK-4.3 license";
309
+ rev1(maxdel,N,g) = fb_comb (maxdel,N,1,-g);
310
+
311
+ //-----`(fi.)fbcombfilter` and `(fi.)ffbcombfilter`------------
312
+ // Other special cases of Feed-Back Comb Filter.
313
+ //
314
+ // #### Usage
315
+ //
316
+ // ```
317
+ // _ : fbcombfilter(maxdel,intdel,g) : _
318
+ // _ : ffbcombfilter(maxdel,del,g) : _
319
+ // ```
320
+ //
321
+ // Where:
322
+ //
323
+ // * `maxdel`: maximum delay (a power of 2)
324
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
325
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
326
+ // * `g`: feedback gain
327
+ //
328
+ // #### Reference
329
+ // <https://ccrma.stanford.edu/~jos/pasp/Feedback_Comb_Filters.html>
330
+ //------------------------------------------------------------
331
+ declare fbcombfilter author "Julius O. Smith III";
332
+ declare fbcombfilter copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
333
+ declare fbcombfilter license "MIT-style STK-4.3 license";
334
+ fbcombfilter(maxdel,intdel,g) = (+ : de.delay(maxdel,intdel)) ~ *(g);
335
+
336
+ declare ffbcombfilter author "Julius O. Smith III";
337
+ declare ffbcombfilter copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
338
+ declare ffbcombfilter license "MIT-style STK-4.3 license";
339
+ ffbcombfilter(maxdel,del,g) = (+ : de.fdelay(maxdel,del)) ~ *(g);
340
+
341
+
342
+ //-------------------`(fi.)allpass_comb`-----------------
343
+ // Schroeder Allpass Comb Filter. Note that:
344
+ //
345
+ // ```
346
+ // allpass_comb(maxlen,len,aN) = ff_comb(maxlen,len,aN,1) : fb_comb(maxlen,len-1,1,aN);
347
+ // ```
348
+ //
349
+ // which is a direct-form-1 implementation, requiring two delay lines.
350
+ // The implementation here is direct-form-2 requiring only one delay line.
351
+ //
352
+ // #### Usage
353
+ //
354
+ // ```
355
+ // _ : allpass_comb(maxdel,intdel,aN) : _
356
+ // ```
357
+ //
358
+ // Where:
359
+ //
360
+ // * `maxdel`: maximum delay (a power of 2)
361
+ // * `intdel`: current (integer) comb-filter delay between 0 and maxdel
362
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
363
+ // * `aN`: minus the feedback gain
364
+ //
365
+ // #### References
366
+ // * <https://ccrma.stanford.edu/~jos/pasp/Allpass_Two_Combs.html>
367
+ // * <https://ccrma.stanford.edu/~jos/pasp/Schroeder_Allpass_Sections.html>
368
+ // * <https://ccrma.stanford.edu/~jos/filters/Four_Direct_Forms.html>
369
+ //------------------------------------------------------------
370
+ declare allpass_comb author "Julius O. Smith III";
371
+ declare allpass_comb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
372
+ declare allpass_comb license "MIT-style STK-4.3 license";
373
+ allpass_comb(maxdel,N,aN) = (+ <: de.delay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : +;
374
+
375
+
376
+ //-------------------`(fi.)allpass_fcomb`-----------------
377
+ // Schroeder Allpass Comb Filter. Note that:
378
+ //
379
+ // ```
380
+ // allpass_comb(maxlen,len,aN) = ff_comb(maxlen,len,aN,1) : fb_comb(maxlen,len-1,1,aN);
381
+ // ```
382
+ //
383
+ // which is a direct-form-1 implementation, requiring two delay lines.
384
+ // The implementation here is direct-form-2 requiring only one delay line.
385
+ //
386
+ // `allpass_fcomb` is a standard Faust library.
387
+ //
388
+ // #### Usage
389
+ //
390
+ // ```
391
+ // _ : allpass_comb(maxdel,intdel,aN) : _
392
+ // _ : allpass_fcomb(maxdel,del,aN) : _
393
+ // ```
394
+ //
395
+ // Where:
396
+ //
397
+ // * `maxdel`: maximum delay (a power of 2)
398
+ // * `intdel`: current (float) comb-filter delay between 0 and maxdel
399
+ // * `del`: current (float) comb-filter delay between 0 and maxdel
400
+ // * `aN`: minus the feedback gain
401
+ //
402
+ // #### References
403
+ // * <https://ccrma.stanford.edu/~jos/pasp/Allpass_Two_Combs.html>
404
+ // * <https://ccrma.stanford.edu/~jos/pasp/Schroeder_Allpass_Sections.html>
405
+ // * <https://ccrma.stanford.edu/~jos/filters/Four_Direct_Forms.html>
406
+ //------------------------------------------------------------
407
+ declare allpass_fcomb author "Julius O. Smith III";
408
+ declare allpass_fcomb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
409
+ declare allpass_fcomb license "MIT-style STK-4.3 license";
410
+ allpass_fcomb(maxdel,N,aN) = (+ <: de.fdelay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : +;
411
+
412
+
413
+ //-----------------------`(fi.)rev2`-----------------------
414
+ // Special case of `allpass_comb` (`rev2(maxlen,len,g)`).
415
+ // The "rev2 section" dates back to the 1960s in computer-music reverberation.
416
+ // See the `jcrev` and `brassrev` in `reverbs.lib` for usage examples.
417
+ //------------------------------------------------------------
418
+ declare rev2 author "Julius O. Smith III";
419
+ declare rev2 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
420
+ declare rev2 license "MIT-style STK-4.3 license";
421
+ rev2(maxlen,len,g) = allpass_comb(maxlen,len,-g);
422
+
423
+ //-------------------`(fi.)allpass_fcomb5` and `(fi.)allpass_fcomb1a`-----------------
424
+ // Same as `allpass_fcomb` but use `fdelay5` and `fdelay1a` internally
425
+ // (Interpolation helps - look at an fft of faust2octave on
426
+ //
427
+ // ```
428
+ // `1-1' <: allpass_fcomb(1024,10.5,0.95), allpass_fcomb5(1024,10.5,0.95);`).
429
+ // ```
430
+ //------------------------------------------------------------
431
+ declare allpass_fcomb5 author "Julius O. Smith III";
432
+ declare allpass_fcomb5 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
433
+ declare allpass_fcomb5 license "MIT-style STK-4.3 license";
434
+ allpass_fcomb5(maxdel,N,aN) = (+ <: de.fdelay5(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : +;
435
+
436
+ declare allpass_fcomb1a author "Julius O. Smith III";
437
+ declare allpass_fcomb1a copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
438
+ declare allpass_fcomb1a license "MIT-style STK-4.3 license";
439
+ allpass_fcomb1a(maxdel,N,aN) = (+ <: de.fdelay1a(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : +;
440
+
441
+
442
+ //========================Direct-Form Digital Filter Sections=============================
443
+ //========================================================================================
444
+
445
+ // Specified by transfer-function polynomials B(z)/A(z) as in matlab
446
+
447
+ //----------------------------`(fi.)iir`-------------------------------
448
+ // Nth-order Infinite-Impulse-Response (IIR) digital filter,
449
+ // implemented in terms of the Transfer-Function (TF) coefficients.
450
+ // Such filter structures are termed "direct form".
451
+ //
452
+ // `iir` is a standard Faust function.
453
+ //
454
+ // #### Usage
455
+ //
456
+ // ```
457
+ // _ : iir(bcoeffs,acoeffs) : _
458
+ // ```
459
+ //
460
+ // Where:
461
+ //
462
+ // * `bcoeffs`: (b0,b1,...,b_order) = TF numerator coefficients
463
+ // * `acoeffs`: (a1,...,a_order) = TF denominator coeffs (a0=1)
464
+ //
465
+ // #### Reference
466
+ // <https://ccrma.stanford.edu/~jos/filters/Four_Direct_Forms.html>
467
+ //------------------------------------------------------------
468
+ declare iir author "Julius O. Smith III";
469
+ declare iir copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
470
+ declare iir license "MIT-style STK-4.3 license";
471
+ iir(bv,av) = ma.sub ~ fir(av) : fir(bv);
472
+
473
+ //-----------------------------`(fi.)fir`---------------------------------
474
+ // FIR filter (convolution of FIR filter coefficients with a signal). `fir` is standard Faust function.
475
+ //
476
+ // #### Usage
477
+ //
478
+ // ```
479
+ // _ : fir(bv) : _
480
+ // ```
481
+ //
482
+ // Where:
483
+ //
484
+ // * `bv` = b0,b1,...,bn is a parallel bank of coefficient signals.
485
+ //
486
+ // #### Note
487
+ //
488
+ // `bv` is processed using pattern-matching at compile time,
489
+ // so it must have this normal form (parallel signals).
490
+ //
491
+ // #### Example test program
492
+ //
493
+ // Smoothing white noise with a five-point moving average:
494
+ //
495
+ // ```
496
+ // bv = .2,.2,.2,.2,.2;
497
+ // process = noise : fir(bv);
498
+ // ```
499
+ //
500
+ // Equivalent (note double parens):
501
+ //
502
+ // ```
503
+ // process = noise : fir((.2,.2,.2,.2,.2));
504
+ // ```
505
+ //------------------------------------------------------------
506
+ //fir(bv) = conv(bv);
507
+ declare fir author "Julius O. Smith III";
508
+ declare fir copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
509
+ declare fir license "MIT-style STK-4.3 license";
510
+ fir((b0,bv)) = _ <: *(b0), R(1,bv) :> _ with {
511
+ R(n,(bn,bv)) = (@(n):*(bn)), R(n+1,bv);
512
+ R(n, bn) = (@(n):*(bn)); };
513
+ fir(b0) = *(b0);
514
+
515
+ //---------------`(fi.)conv` and `(fi.)convN`-------------------------------
516
+ // Convolution of input signal with given coefficients.
517
+ //
518
+ // #### Usage
519
+ //
520
+ // ```
521
+ // _ : conv((k1,k2,k3,...,kN)) : _ // Argument = one signal bank
522
+ // _ : convN(N,(k1,k2,k3,...)) : _ // Useful when N < count((k1,...))
523
+ // ```
524
+ //------------------------------------------------------------
525
+ //convN(N,kv,x) = sum(i,N,take(i+1,kv) * x@i); // take() defined in math.lib
526
+
527
+ declare convN author "Julius O. Smith III";
528
+ declare convN copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
529
+ declare convN license "MIT-style STK-4.3 license";
530
+ convN(N,kv) = sum(i,N, @(i)*take(i+1,kv)); // take() defined in math.lib
531
+ //conv(kv,x) = sum(i,count(kv),take(i+1,kv) * x@i); // count() from math.lib
532
+
533
+ declare conv author "Julius O. Smith III";
534
+ declare conv copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
535
+ declare conv license "MIT-style STK-4.3 license";
536
+ conv(kv) = fir(kv);
537
+
538
+ //----------------`(fi.)tf1`, `(fi.)tf2` and `(fi.)tf3`----------------------
539
+ // tfN = N'th-order direct-form digital filter.
540
+ //
541
+ // #### Usage
542
+ //
543
+ // ```
544
+ // _ : tf1(b0,b1,a1) : _
545
+ // _ : tf2(b0,b1,b2,a1,a2) : _
546
+ // _ : tf3(b0,b1,b2,b3,a1,a2,a3) : _
547
+ // ```
548
+ //
549
+ // Where:
550
+ //
551
+ // * `a`: the poles
552
+ // * `b`: the zeros
553
+ //
554
+ // #### Reference
555
+ // <https://ccrma.stanford.edu/~jos/fp/Direct_Form_I.html>
556
+ //------------------------------------------------------------
557
+ declare tf1 author "Julius O. Smith III";
558
+ declare tf1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
559
+ declare tf1 license "MIT-style STK-4.3 license";
560
+ tf1(b0,b1,a1) = _ <: *(b0), (mem : *(b1)) :> + ~ *(0-a1);
561
+
562
+ declare tf2 author "Julius O. Smith III";
563
+ declare tf2 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
564
+ declare tf2 license "MIT-style STK-4.3 license";
565
+ tf2(b0,b1,b2,a1,a2) = iir((b0,b1,b2),(a1,a2));
566
+ // tf2 is a variant of tf22 below with duplicated mems
567
+
568
+ declare tf3 author "Julius O. Smith III";
569
+ declare tf3 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
570
+ declare tf3 license "MIT-style STK-4.3 license";
571
+ tf3(b0,b1,b2,b3,a1,a2,a3) = iir((b0,b1,b2,b3),(a1,a2,a3));
572
+
573
+ // "Original" version for music.lib. This is here for comparison but people should
574
+ // use tf2 instead
575
+ TF2(b0,b1,b2,a1,a2) = sub ~ conv2(a1,a2) : conv3(b0,b1,b2)
576
+ with {
577
+ conv3(k0,k1,k2,x) = k0*x + k1*x' + k2*x'';
578
+ conv2(k0,k1,x) = k0*x + k1*x';
579
+ sub(x,y) = y-x;
580
+ };
581
+
582
+ //------------`(fi.)notchw`--------------
583
+ // Simple notch filter based on a biquad (`tf2`).
584
+ // `notchw` is a standard Faust function.
585
+ //
586
+ // #### Usage:
587
+ //
588
+ // ```
589
+ // _ : notchw(width,freq) : _
590
+ // ```
591
+ //
592
+ // Where:
593
+ //
594
+ // * `width`: "notch width" in Hz (approximate)
595
+ // * `freq`: "notch frequency" in Hz
596
+ //
597
+ // #### Reference
598
+ // <https://ccrma.stanford.edu/~jos/pasp/Phasing_2nd_Order_Allpass_Filters.html>
599
+ //------------------------------------------------------------
600
+ declare notchw author "Julius O. Smith III";
601
+ declare notchw copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
602
+ declare notchw license "MIT-style STK-4.3 license";
603
+ notchw(width,freq) = tf2(b0,b1,b2,a1,a2)
604
+ with {
605
+ fb = 0.5*width; // First design a dcblockerat(width/2)
606
+ wn = ma.PI*fb/ma.SR;
607
+ b0db = 1.0 / (1 + wn);
608
+ p = (1 - wn) * b0db; // This is our pole radius.
609
+ // Now place unit-circle zeros at desired angles:
610
+ tn = 2*ma.PI*freq/ma.SR;
611
+ a2 = p * p;
612
+ a2p1 = 1+a2;
613
+ a1 = -a2p1*cos(tn);
614
+ b1 = a1;
615
+ b0 = 0.5*a2p1;
616
+ b2 = b0;
617
+ };
618
+
619
+ //======================Direct-Form Second-Order Biquad Sections==========================
620
+ // Direct-Form Second-Order Biquad Sections
621
+ //
622
+ // #### Reference
623
+ // <https://ccrma.stanford.edu/~jos/filters/Four_Direct_Forms.html>
624
+ //========================================================================================
625
+
626
+ //----------------`(fi.)tf21`, `(fi.)tf22`, `(fi.)tf22t` and `(fi.)tf21t`----------------------
627
+ // tfN = N'th-order direct-form digital filter where:
628
+ //
629
+ // * `tf21` is tf2, direct-form 1
630
+ // * `tf22` is tf2, direct-form 2
631
+ // * `tf22t` is tf2, direct-form 2 transposed
632
+ // * `tf21t` is tf2, direct-form 1 transposed
633
+ //
634
+ // #### Usage
635
+ //
636
+ // ```
637
+ // _ : tf21(b0,b1,b2,a1,a2) : _
638
+ // _ : tf22(b0,b1,b2,a1,a2) : _
639
+ // _ : tf22t(b0,b1,b2,a1,a2) : _
640
+ // _ : tf21t(b0,b1,b2,a1,a2) : _
641
+ // ```
642
+ //
643
+ // Where:
644
+ //
645
+ // * `a`: the poles
646
+ // * `b`: the zeros
647
+ //
648
+ // #### Reference
649
+ // <https://ccrma.stanford.edu/~jos/fp/Direct_Form_I.html>
650
+ //------------------------------------------------------------
651
+ declare tf21 author "Julius O. Smith III";
652
+ declare tf21 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
653
+ declare tf21 license "MIT-style STK-4.3 license";
654
+ tf21(b0,b1,b2,a1,a2) = // tf2, direct-form 1:
655
+ _ <:(mem<:((mem:*(b2)),*(b1))),*(b0) :>_
656
+ : ((_,_,_:>_) ~(_<:*(-a1),(mem:*(-a2))));
657
+
658
+ declare tf22 author "Julius O. Smith III";
659
+ declare tf22 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
660
+ declare tf22 license "MIT-style STK-4.3 license";
661
+ tf22(b0,b1,b2,a1,a2) = // tf2, direct-form 2:
662
+ _ : (((_,_,_:>_)~*(-a1)<:mem,*(b0))~*(-a2))
663
+ : (_<:mem,*(b1)),_ : *(b2),_,_ :> _;
664
+
665
+ declare tf22t author "Julius O. Smith III";
666
+ declare tf22t copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
667
+ declare tf22t license "MIT-style STK-4.3 license";
668
+ tf22t(b0,b1,b2,a1,a2) = // tf2, direct-form 2 transposed:
669
+ _ : (_,_,(_ <: *(b2)',*(b1)',*(b0))
670
+ : _,+',_,_ :> _)~*(-a1)~*(-a2) : _;
671
+
672
+ declare tf21t author "Julius O. Smith III";
673
+ declare tf21t copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
674
+ declare tf21t license "MIT-style STK-4.3 license";
675
+ tf21t(b0,b1,b2,a1,a2) = // tf2, direct-form 1 transposed:
676
+ tf22t(1,0,0,a1,a2) : tf22t(b0,b1,b2,0,0); // or write it out if you want
677
+
678
+ //=========================== Ladder/Lattice Digital Filters =============================
679
+ // Ladder and lattice digital filters generally have superior numerical
680
+ // properties relative to direct-form digital filters. They can be derived
681
+ // from digital waveguide filters, which gives them a physical interpretation.
682
+
683
+ // #### Reference
684
+ // * F. Itakura and S. Saito: "Digital Filtering Techniques for Speech Analysis and Synthesis",
685
+ // 7th Int. Cong. Acoustics, Budapest, 25 C 1, 1971.
686
+ // * J. D. Markel and A. H. Gray: Linear Prediction of Speech, New York: Springer Verlag, 1976.
687
+ // * <https://ccrma.stanford.edu/~jos/pasp/Conventional_Ladder_Filters.html>
688
+ //========================================================================================
689
+
690
+ //-------------------------------`(fi.)av2sv`-----------------------------------
691
+ // Compute reflection coefficients sv from transfer-function denominator av.
692
+ //
693
+ // #### Usage
694
+ //
695
+ // ```
696
+ // sv = av2sv(av)
697
+ // ```
698
+ //
699
+ // Where:
700
+ //
701
+ // * `av`: parallel signal bank `a1,...,aN`
702
+ // * `sv`: parallel signal bank `s1,...,sN`
703
+ //
704
+ // where `ro = ith` reflection coefficient, and
705
+ // `ai` = coefficient of `z^(-i)` in the filter
706
+ // transfer-function denominator `A(z)`.
707
+ //
708
+ // #### Reference
709
+ // <https://ccrma.stanford.edu/~jos/filters/Step_Down_Procedure.html>
710
+ // (where reflection coefficients are denoted by k rather than s).
711
+ //------------------------------------------------------------
712
+ declare av2sv author "Julius O. Smith III";
713
+ declare av2sv copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
714
+ declare av2sv license "MIT-style STK-4.3 license";
715
+ av2sv(av) = par(i,M,s(i+1)) with {
716
+ M = ba.count(av);
717
+ s(m) = sr(M-m+1); // m=1..M
718
+ sr(m) = Ari(m,M-m+1); // s_{M-1-m}
719
+ Ari(m,i) = ba.take(i+1,Ar(m-1));
720
+ //step-down recursion for lattice/ladder digital filters:
721
+ Ar(0) = (1,av); // Ar(m) is order M-m (i.e. "reverse-indexed")
722
+ Ar(m) = 1,par(i,M-m, (Ari(m,i+1) - sr(m)*Ari(m,M-m-i))/(1-sr(m)*sr(m)));
723
+ };
724
+
725
+ //----------------------------`(fi.)bvav2nuv`--------------------------------
726
+ // Compute lattice tap coefficients from transfer-function coefficients.
727
+ //
728
+ // #### Usage
729
+ //
730
+ // ```
731
+ // nuv = bvav2nuv(bv,av)
732
+ // ```
733
+ //
734
+ // Where:
735
+ //
736
+ // * `av`: parallel signal bank `a1,...,aN`
737
+ // * `bv`: parallel signal bank `b0,b1,...,aN`
738
+ // * `nuv`: parallel signal bank `nu1,...,nuN`
739
+ //
740
+ // where `nui` is the i'th tap coefficient,
741
+ // `bi` is the coefficient of `z^(-i)` in the filter numerator,
742
+ // `ai` is the coefficient of `z^(-i)` in the filter denominator
743
+ //------------------------------------------------------------
744
+ declare bvav2nuv author "Julius O. Smith III";
745
+ declare bvav2nuv copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
746
+ declare bvav2nuv license "MIT-style STK-4.3 license";
747
+ bvav2nuv(bv,av) = par(m,M+1,nu(m)) with {
748
+ M = ba.count(av);
749
+ nu(m) = ba.take(m+1,Pr(M-m)); // m=0..M
750
+ // lattice/ladder tap parameters:
751
+ Pr(0) = bv; // Pr(m) is order M-m, 'r' means "reversed"
752
+ Pr(m) = par(i,M-m+1, (Pri(m,i) - nu(M-m+1)*Ari(m,M-m-i+1)));
753
+ Pri(m,i) = ba.take(i+1,Pr(m-1));
754
+ Ari(m,i) = ba.take(i+1,Ar(m-1));
755
+ //step-down recursion for lattice/ladder digital filters:
756
+ Ar(0) = (1,av); // Ar(m) is order M-m (recursion index must start at constant)
757
+ Ar(m) = 1,par(i,M-m, (Ari(m,i+1) - sr(m)*Ari(m,M-m-i))/(1-sr(m)*sr(m)));
758
+ sr(m) = Ari(m,M-m+1); // s_{M-1-m}
759
+ };
760
+
761
+ //--------------------`(fi.)iir_lat2`-----------------------
762
+ // Two-multiply latice IIR filter of arbitrary order.
763
+ //
764
+ // #### Usage
765
+ //
766
+ // ```
767
+ // _ : iir_lat2(bv,av) : _
768
+ // ```
769
+ //
770
+ // Where:
771
+ //
772
+ // * bv: zeros as a bank of parallel signals
773
+ // * av: poles as a bank of parallel signals
774
+ //------------------------------------------------------------
775
+ declare iir_lat2 author "Julius O. Smith III";
776
+ declare iir_lat2 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
777
+ declare iir_lat2 license "MIT-style STK-4.3 license";
778
+ iir_lat2(bv,av) = allpassnt(M,sv) : sum(i,M+1,*(ba.take(M-i+1,tg)))
779
+ with {
780
+ M = ba.count(av);
781
+ sv = av2sv(av); // sv = vector of sin(theta) reflection coefficients
782
+ tg = bvav2nuv(bv,av); // tg = vector of tap gains
783
+ };
784
+
785
+ //-----------------------`(fi.)allpassnt`--------------------------
786
+ // Two-multiply lattice allpass (nested order-1 direct-form-ii allpasses).
787
+ //
788
+ // #### Usage
789
+ //
790
+ // ```
791
+ // _ : allpassnt(n,sv) : _
792
+ // ```
793
+ //
794
+ // Where:
795
+ //
796
+ // * `n`: the order of the filter
797
+ // * `sv`: the reflection coefficients (-1 1)
798
+ //------------------------------------------------------------
799
+ declare allpassnt author "Julius O. Smith III";
800
+ declare allpassnt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
801
+ declare allpassnt license "MIT-style STK-4.3 license";
802
+ allpassnt(0,sv) = _;
803
+ allpassnt(n,sv) = _ : ((+ <: (allpassnt(n-1,sv),*(s)))~*(-s)) : fsec(n)
804
+ with {
805
+ fsec(1) = ro.crossnn(1) : _, (_<:mem,_) : +,_;
806
+ fsec(n) = ro.crossn1(n) : _, (_<:mem,_),par(i,n-1,_) : +, par(i,n,_);
807
+ innertaps(n) = par(i,n,_);
808
+ s = ba.take(n,sv); // reflection coefficient s = sin(theta)
809
+ };
810
+
811
+ //--------------------`(fi.)iir_kl`-----------------------
812
+ // Kelly-Lochbaum ladder IIR filter of arbitrary order.
813
+ //
814
+ // #### Usage
815
+ //
816
+ // ```
817
+ // _ : iir_kl(bv,av) : _
818
+ // ```
819
+ //
820
+ // Where:
821
+ //
822
+ // * bv: zeros as a bank of parallel signals
823
+ // * av: poles as a bank of parallel signals
824
+ //------------------------------------------------------------
825
+ declare iir_kl author "Julius O. Smith III";
826
+ declare iir_kl copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
827
+ declare iir_kl license "MIT-style STK-4.3 license";
828
+ iir_kl(bv,av) = allpassnklt(M,sv) : sum(i,M+1,*(tghr(i)))
829
+ with {
830
+ M = ba.count(av);
831
+ sv = av2sv(av); // sv = vector of sin(theta) reflection coefficients
832
+ tg = bvav2nuv(bv,av); // tg = vector of tap gains for 2mul case
833
+ tgr(i) = ba.take(M+1-i,tg);
834
+ tghr(n) = tgr(n)/pi(n);
835
+ pi(0) = 1;
836
+ pi(n) = pi(n-1)*(1+ba.take(M-n+1,sv)); // all sign parameters '+'
837
+ };
838
+
839
+ //-----------------------`(fi.)allpassnklt`--------------------------
840
+ // Kelly-Lochbaum ladder allpass.
841
+ //
842
+ // #### Usage:
843
+ //
844
+ // ```
845
+ // _ : allpassnklt(n,sv) : _
846
+ // ```
847
+ //
848
+ // Where:
849
+ //
850
+ // * `n`: the order of the filter
851
+ // * `sv`: the reflection coefficients (-1 1)
852
+ //------------------------------------------------------------
853
+ declare allpassnklt author "Julius O. Smith III";
854
+ declare allpassnklt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
855
+ declare allpassnklt license "MIT-style STK-4.3 license";
856
+ allpassnklt(0,sv) = _;
857
+ allpassnklt(n,sv) = _ <: *(s),(*(1+s) : (+
858
+ : allpassnklt(n-1,sv))~(*(-s))) : fsec(n)
859
+ with {
860
+ fsec(1) = _, (_<:mem*(1-s),_) : sumandtaps(n);
861
+ fsec(n) = _, (_<:mem*(1-s),_), par(i,n-1,_) : sumandtaps(n);
862
+ s = ba.take(n,sv);
863
+ sumandtaps(n) = +,par(i,n,_);
864
+ };
865
+
866
+ //--------------------`(fi.)iir_lat1`-----------------------
867
+ // One-multiply latice IIR filter of arbitrary order.
868
+ //
869
+ // #### Usage
870
+ //
871
+ // ```
872
+ // _ : iir_lat1(bv,av) : _
873
+ // ```
874
+ //
875
+ // Where:
876
+ //
877
+ // * bv: zeros as a bank of parallel signals
878
+ // * av: poles as a bank of parallel signals
879
+ //------------------------------------------------------------
880
+ declare iir_lat1 author "Julius O. Smith III";
881
+ declare iir_lat1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
882
+ declare iir_lat1 license "MIT-style STK-4.3 license";
883
+ iir_lat1(bv,av) = allpassn1mt(M,sv) : sum(i,M+1,*(tghr(i+1)))
884
+ with {
885
+ M = ba.count(av);
886
+ sv = av2sv(av); // sv = vector of sin(theta) reflection coefficients
887
+ tg = bvav2nuv(bv,av); // tg = vector of tap gains
888
+ tgr(i) = ba.take(M+2-i,tg); // i=1..M+1 (for "takability")
889
+ tghr(n) = tgr(n)/pi(n);
890
+ pi(1) = 1;
891
+ pi(n) = pi(n-1)*(1+ba.take(M-n+2,sv)); // all sign parameters '+'
892
+ };
893
+
894
+ //-----------------------`(fi.)allpassn1mt`--------------------------
895
+ // One-multiply lattice allpass with tap lines.
896
+ //
897
+ // #### Usage
898
+ //
899
+ // ```
900
+ // _ : allpassn1mt(N,sv) : _
901
+ // ```
902
+ //
903
+ // Where:
904
+ //
905
+ // * `N`: the order of the filter (fixed at compile time)
906
+ // * `sv`: the reflection coefficients (-1 1)
907
+ //------------------------------------------------------------
908
+ declare allpassn1mt author "Julius O. Smith III";
909
+ declare allpassn1mt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
910
+ declare allpassn1mt license "MIT-style STK-4.3 license";
911
+ allpassn1mt(0,sv) = _;
912
+ allpassn1mt(n,sv) = _ <: _,_ : ((+:*(s) <: _,_),_ : _,+ : ro.crossnn(1)
913
+ : allpassn1mt(n-1,sv),_)~(*(-1)) : fsec(n)
914
+ with {
915
+ fsec(1) = ro.crossnn(1) : _, (_<:mem,_) : +,_;
916
+ fsec(n) = ro.crossn1(n) : _, (_<:mem,_),par(i,n-1,_) : +, par(i,n,_);
917
+ innertaps(n) = par(i,n,_);
918
+ s = ba.take(n,sv); // reflection coefficient s = sin(theta)
919
+ };
920
+
921
+ //-------------------------------`(fi.)iir_nl`-------------------------
922
+ // Normalized ladder filter of arbitrary order.
923
+ //
924
+ // #### Usage
925
+ //
926
+ // ```
927
+ // _ : iir_nl(bv,av) : _
928
+ // ```
929
+ //
930
+ // Where:
931
+ //
932
+ // * bv: zeros as a bank of parallel signals
933
+ // * av: poles as a bank of parallel signals
934
+ //
935
+ // #### References
936
+ // * J. D. Markel and A. H. Gray, Linear Prediction of Speech, New York: Springer Verlag, 1976.
937
+ // * <https://ccrma.stanford.edu/~jos/pasp/Normalized_Scattering_Junctions.html>
938
+ //------------------------------------------------------------
939
+ declare iir_nl author "Julius O. Smith III";
940
+ declare iir_nl copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
941
+ declare iir_nl license "MIT-style STK-4.3 license";
942
+ iir_nl(bv,av) = allpassnnlt(M,sv) : sum(i,M+1,*(tghr(i)))
943
+ with {
944
+ M = ba.count(av);
945
+ sv = av2sv(av); // sv = vector of sin(theta) reflection coefficients
946
+ tg = bvav2nuv(bv,av); // tg = vector of tap gains for 2mul case
947
+ tgr(i) = ba.take(M+1-i,tg);
948
+ tghr(n) = tgr(n)/pi(n);
949
+ pi(0) = 1;
950
+ s(n) = ba.take(M-n+1,sv); // reflection coefficient = sin(theta)
951
+ c(n) = sqrt(max(0,1-s(n)*s(n))); // compiler crashes on sqrt(-)
952
+ pi(n) = pi(n-1)*c(n);
953
+ };
954
+
955
+ //-------------------------------`(fi.)allpassnnlt`-------------------------
956
+ // Normalized ladder allpass filter of arbitrary order.
957
+ //
958
+ // #### Usage:
959
+ //
960
+ // ```
961
+ // _ : allpassnnlt(N,sv) : _
962
+ // ```
963
+ //
964
+ // Where:
965
+ //
966
+ // * `N`: the order of the filter (fixed at compile time)
967
+ // * `sv`: the reflection coefficients (-1,1)
968
+ //
969
+ // #### References
970
+ // * J. D. Markel and A. H. Gray, Linear Prediction of Speech, New York: Springer Verlag, 1976.
971
+ // * <https://ccrma.stanford.edu/~jos/pasp/Normalized_Scattering_Junctions.html>
972
+ //------------------------------------------------------------
973
+ declare allpassnnlt author "Julius O. Smith III";
974
+ declare allpassnnlt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
975
+ declare allpassnnlt license "MIT-style STK-4.3 license";
976
+ allpassnnlt(0,sv) = _;
977
+ allpassnnlt(n,scl*(sv)) = allpassnnlt(n,par(i,count(sv),scl*(sv(i))));
978
+ allpassnnlt(n,sv) = _ <: *(s),(*(c) : (+
979
+ : allpassnnlt(n-1,sv))~(*(-s))) : fsec(n)
980
+ with {
981
+ fsec(1) = _, (_<:mem*(c),_) : sumandtaps(n);
982
+ fsec(n) = _, (_<:mem*(c),_), par(i,n-1,_) : sumandtaps(n);
983
+ s = ba.take(n,sv);
984
+ c = sqrt(max(0,1-s*s));
985
+ sumandtaps(n) = +,par(i,n,_);
986
+ };
987
+
988
+ //=============================Useful Special Cases=======================================
989
+ //========================================================================================
990
+
991
+ //--------------------------------`(fi.)tf2np`------------------------------------
992
+ // Biquad based on a stable second-order Normalized Ladder Filter
993
+ // (more robust to modulation than `tf2` and protected against instability).
994
+ //
995
+ // #### Usage
996
+ //
997
+ // ```
998
+ // _ : tf2np(b0,b1,b2,a1,a2) : _
999
+ // ```
1000
+ //
1001
+ // Where:
1002
+ //
1003
+ // * `a`: the poles
1004
+ // * `b`: the zeros
1005
+ //------------------------------------------------------------
1006
+ declare tf2np author "Julius O. Smith III";
1007
+ declare tf2np copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1008
+ declare tf2np license "MIT-style STK-4.3 license";
1009
+ tf2np(b0,b1,b2,a1,a2) = allpassnnlt(M,sv) : sum(i,M+1,*(tghr(i)))
1010
+ with {
1011
+ smax = 1.0-ma.EPSILON; // maximum reflection-coefficient magnitude allowed
1012
+ s2 = max(-smax, min(smax,a2)); // Project both reflection-coefficients
1013
+ s1 = max(-smax, min(smax,a1/(1+a2))); // into the defined stability-region.
1014
+ sv = (s1,s2); // vector of sin(theta) reflection coefficients
1015
+ M = 2;
1016
+ nu(2) = b2;
1017
+ nu(1) = b1 - b2*a1;
1018
+ nu(0) = (b0-b2*a2) - nu(1)*s1;
1019
+ tg = (nu(0),nu(1),nu(2));
1020
+ tgr(i) = ba.take(M+1-i,tg); // vector of tap gains for 2mul case
1021
+ tghr(n) = tgr(n)/pi(n); // apply pi parameters for NLF case
1022
+ pi(0) = 1;
1023
+ s(n) = ba.take(M-n+1,sv);
1024
+ c(n) = sqrt(1-s(n)*s(n));
1025
+ pi(n) = pi(n-1)*c(n);
1026
+ };
1027
+
1028
+ //-----------------------------`(fi.)wgr`---------------------------------
1029
+ // Second-order transformer-normalized digital waveguide resonator.
1030
+ //
1031
+ // #### Usage
1032
+ //
1033
+ // ```
1034
+ // _ : wgr(f,r) : _
1035
+ // ```
1036
+ //
1037
+ // Where:
1038
+ //
1039
+ // * `f`: resonance frequency (Hz)
1040
+ // * `r`: loss factor for exponential decay (set to 1 to make a numerically stable oscillator)
1041
+ //
1042
+ // #### References
1043
+ // * <https://ccrma.stanford.edu/~jos/pasp/Power_Normalized_Waveguide_Filters.html>
1044
+ // * <https://ccrma.stanford.edu/~jos/pasp/Digital_Waveguide_Oscillator.html>
1045
+ //------------------------------------------------------------
1046
+ declare wgr author "Julius O. Smith III";
1047
+ declare wgr copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1048
+ declare wgr license "MIT-style STK-4.3 license";
1049
+ wgr(f,r,x) = (*(G),_<:_,((+:*(C))<:_,_),_:+,_,_:+(x),-) ~ cross : _,*(0-gi)
1050
+ with {
1051
+ C = cos(2*ma.PI*f/ma.SR);
1052
+ gi = sqrt(max(0,(1+C)/(1-C))); // compensate amplitude (only needed when
1053
+ G = r*(1-1' + gi')/gi; // frequency changes substantially)
1054
+ cross = _,_ <: !,_,_,!;
1055
+ };
1056
+
1057
+ //-----------------------------`(fi.)nlf2`--------------------------------
1058
+ // Second order normalized digital waveguide resonator.
1059
+ //
1060
+ // #### Usage
1061
+ //
1062
+ // ```
1063
+ // _ : nlf2(f,r) : _
1064
+ // ```
1065
+ //
1066
+ // Where:
1067
+ //
1068
+ // * `f`: resonance frequency (Hz)
1069
+ // * `r`: loss factor for exponential decay (set to 1 to make a sinusoidal oscillator)
1070
+ //
1071
+ // #### Reference
1072
+ // <https://ccrma.stanford.edu/~jos/pasp/Power_Normalized_Waveguide_Filters.html>
1073
+ //------------------------------------------------------------
1074
+ declare nlf2 author "Julius O. Smith III";
1075
+ declare nlf2 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1076
+ declare nlf2 license "MIT-style STK-4.3 license";
1077
+ nlf2(f,r,x) = ((_<:_,_),(_<:_,_) : (*(s),*(c),*(c),*(0-s)) :>
1078
+ (*(r),+(x))) ~ cross
1079
+ with {
1080
+ th = 2*ma.PI*f/ma.SR;
1081
+ c = cos(th);
1082
+ s = sin(th);
1083
+ cross = _,_ <: !,_,_,!;
1084
+ };
1085
+
1086
+
1087
+ //------------`(fi.)apnl`---------------
1088
+ // Passive Nonlinear Allpass based on Pierce switching springs idea.
1089
+ // Switch between allpass coefficient `a1` and `a2` at signal zero crossings.
1090
+ //
1091
+ // #### Usage
1092
+ //
1093
+ // ```
1094
+ // _ : apnl(a1,a2) : _
1095
+ // ```
1096
+ //
1097
+ // Where:
1098
+ //
1099
+ // * `a1` and `a2`: allpass coefficients
1100
+ //
1101
+ // #### Reference
1102
+ // * "A Passive Nonlinear Digital Filter Design ..." by John R. Pierce and Scott
1103
+ // A. Van Duyne, JASA, vol. 101, no. 2, pp. 1120-1126, 1997
1104
+ //------------------------------------------------------------
1105
+ declare apnl author "Julius O. Smith III";
1106
+ declare apnl copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1107
+ declare apnl license "MIT-style STK-4.3 license";
1108
+ apnl(a1,a2,x) = nonLinFilter
1109
+ with {
1110
+ condition = _>0;
1111
+ nonLinFilter = (x - _ <: _*(condition*a1 + (1-condition)*a2),_')~_ :> +;
1112
+ };
1113
+
1114
+
1115
+ //============================Ladder/Lattice Allpass Filters==============================
1116
+ // An allpass filter has gain 1 at every frequency, but variable phase.
1117
+ // Ladder/lattice allpass filters are specified by reflection coefficients.
1118
+ // They are defined here as nested allpass filters, hence the names allpassn*.
1119
+ //
1120
+ // #### References
1121
+ // * <https://ccrma.stanford.edu/~jos/pasp/Conventional_Ladder_Filters.html>
1122
+ // * <https://ccrma.stanford.edu/~jos/pasp/Nested_Allpass_Filters.html>
1123
+ // * Linear Prediction of Speech, Markel and Gray, Springer Verlag, 1976
1124
+ //========================================================================================
1125
+
1126
+ //---------------`(fi.)allpassn`-----------------
1127
+ // Two-multiply lattice - each section is two multiply-adds.
1128
+ //
1129
+ // #### Usage:
1130
+ //
1131
+ // ```
1132
+ // _ : allpassn(n,sv) : _
1133
+ // ```
1134
+ // #### Where:
1135
+ //
1136
+ // * `n`: the order of the filter
1137
+ // * `sv`: the reflection coefficients (-1 1)
1138
+ //
1139
+ // #### References
1140
+ // * J. O. Smith and R. Michon, "Nonlinear Allpass Ladder Filters in FAUST", in
1141
+ // Proceedings of the 14th International Conference on Digital Audio Effects
1142
+ // (DAFx-11), Paris, France, September 19-23, 2011.
1143
+ //----------------------------------------------
1144
+ declare allpassn author "Julius O. Smith III and Romain Michon";
1145
+ declare allpassn copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu> and Romain Michon <rmichon@ccrma.stanford.edu>";
1146
+ declare allpassn license "MIT-style STK-4.3 license";
1147
+ allpassn(0,sv) = _;
1148
+ allpassn(n,sv) = _ <: ((+ <: (allpassn(n-1,sv)),*(s))~(*(-s))) : _',_ :+
1149
+ with { s = ba.take(n,sv); };
1150
+
1151
+ //---------------`(fi.)allpassnn`-----------------
1152
+ // Normalized form - four multiplies and two adds per section,
1153
+ // but coefficients can be time varying and nonlinear without
1154
+ // "parametric amplification" (modulation of signal energy).
1155
+ //
1156
+ // #### Usage:
1157
+ //
1158
+ // ```
1159
+ // _ : allpassnn(n,tv) : _
1160
+ // ```
1161
+ //
1162
+ // Where:
1163
+ //
1164
+ // * `n`: the order of the filter
1165
+ // * `tv`: the reflection coefficients (-PI PI)
1166
+ //----------------------------------------------
1167
+ // power-normalized (reflection coefficients s = sin(t)):
1168
+ declare allpassnn author "Julius O. Smith III";
1169
+ declare allpassnn copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1170
+ declare allpassnn license "MIT-style STK-4.3 license";
1171
+ allpassnn(0,tv) = _;
1172
+ allpassnn(n,tv) = _ <: *(s), (*(c) : (+
1173
+ : allpassnn(n-1,tv))~(*(-s))) : _, mem*c : +
1174
+ with { c = cos(ba.take(n,tv)); s = sin(ba.take(n,tv)); };
1175
+
1176
+ //---------------`(fi.)allpassnkl`-----------------
1177
+ // Kelly-Lochbaum form - four multiplies and two adds per
1178
+ // section, but all signals have an immediate physical
1179
+ // interpretation as traveling pressure waves, etc.
1180
+ //
1181
+ // #### Usage:
1182
+ //
1183
+ // ```
1184
+ // _ : allpassnkl(n,sv) : _
1185
+ // ```
1186
+ //
1187
+ // Where:
1188
+ //
1189
+ // * `n`: the order of the filter
1190
+ // * `sv`: the reflection coefficients (-1 1)
1191
+ //----------------------------------------------
1192
+ // Kelly-Lochbaum:
1193
+ declare allpassnnkl author "Julius O. Smith III";
1194
+ declare allpassnnkl copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1195
+ declare allpassnnkl license "MIT-style STK-4.3 license";
1196
+ allpassnkl(0,sv) = _;
1197
+ allpassnkl(n,sv) = _ <: *(s),(*(1+s) : (+
1198
+ : allpassnkl(n-1,sv))~(*(-s))) : _, mem*(1-s) : +
1199
+ with { s = ba.take(n,sv); };
1200
+
1201
+ //---------------`(fi.)allpass1m`-----------------
1202
+ // One-multiply form - one multiply and three adds per section.
1203
+ // Normally the most efficient in special-purpose hardware.
1204
+ //
1205
+ // #### Usage:
1206
+ //
1207
+ // ```
1208
+ // _ : allpassn1m(n,sv) : _
1209
+ // ```
1210
+ //
1211
+ // Where:
1212
+ //
1213
+ // * `n`: the order of the filter
1214
+ // * `sv`: the reflection coefficients (-1 1)
1215
+ //----------------------------------------------
1216
+ // one-multiply:
1217
+ declare allpassn1m author "Julius O. Smith III";
1218
+ declare allpassn1m copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1219
+ declare allpassn1m license "MIT-style STK-4.3 license";
1220
+ allpassn1m(0,sv) = _;
1221
+ allpassn1m(n,sv) = _ <: _,_ : ((+:*(s) <: _,_),_ : _,+ : cross
1222
+ : allpassn1m(n-1,sv),_)~(*(-1)) : _',_ : +
1223
+ with { s = ba.take(n,sv); cross = _,_ <: !,_,_,!; };
1224
+
1225
+ //===========Digital Filter Sections Specified as Analog Filter Sections==================
1226
+ //========================================================================================
1227
+
1228
+ //-------------------------`(fi.)tf2s` and `(fi.)tf2snp`--------------------------------
1229
+ // Second-order direct-form digital filter,
1230
+ // specified by ANALOG transfer-function polynomials B(s)/A(s),
1231
+ // and a frequency-scaling parameter. Digitization via the
1232
+ // bilinear transform is built in.
1233
+ //
1234
+ // #### Usage
1235
+ //
1236
+ // ```
1237
+ // _ : tf2s(b2,b1,b0,a1,a0,w1) : _
1238
+ // ```
1239
+ // Where:
1240
+ //
1241
+ // ```
1242
+ // b2 s^2 + b1 s + b0
1243
+ // H(s) = --------------------
1244
+ // s^2 + a1 s + a0
1245
+ // ```
1246
+ //
1247
+ // and `w1` is the desired digital frequency (in radians/second)
1248
+ // corresponding to analog frequency 1 rad/sec (i.e., `s = j`).
1249
+ //
1250
+ // #### Example test program
1251
+ //
1252
+ // A second-order ANALOG Butterworth lowpass filter,
1253
+ // normalized to have cutoff frequency at 1 rad/sec,
1254
+ // has transfer function:
1255
+ //
1256
+ // ```
1257
+ // 1
1258
+ // H(s) = -----------------
1259
+ // s^2 + a1 s + 1
1260
+ // ```
1261
+ //
1262
+ // where `a1 = sqrt(2)`. Therefore, a DIGITAL Butterworth lowpass
1263
+ // cutting off at `SR/4` is specified as `tf2s(0,0,1,sqrt(2),1,PI*SR/2);`
1264
+ //
1265
+ // #### Method
1266
+ //
1267
+ // Bilinear transform scaled for exact mapping of w1.
1268
+ //
1269
+ // #### Reference
1270
+ // <https://ccrma.stanford.edu/~jos/pasp/Bilinear_Transformation.html>
1271
+ //----------------------------------------------
1272
+ declare tf2s author "Julius O. Smith III";
1273
+ declare tf2s copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1274
+ declare tf2s license "MIT-style STK-4.3 license";
1275
+ tf2s(b2,b1,b0,a1,a0,w1) = tf2(b0d,b1d,b2d,a1d,a2d)
1276
+ with {
1277
+ c = 1/tan(w1*0.5/ma.SR); // bilinear-transform scale-factor
1278
+ csq = c*c;
1279
+ d = a0 + a1 * c + csq;
1280
+ b0d = (b0 + b1 * c + b2 * csq)/d;
1281
+ b1d = 2 * (b0 - b2 * csq)/d;
1282
+ b2d = (b0 - b1 * c + b2 * csq)/d;
1283
+ a1d = 2 * (a0 - csq)/d;
1284
+ a2d = (a0 - a1*c + csq)/d;
1285
+ };
1286
+
1287
+ // tf2snp = tf2s but using a protected normalized ladder filter for tf2:
1288
+ tf2snp(b2,b1,b0,a1,a0,w1) = tf2np(b0d,b1d,b2d,a1d,a2d)
1289
+ with {
1290
+ c = 1/tan(w1*0.5/ma.SR); // bilinear-transform scale-factor
1291
+ csq = c*c;
1292
+ d = a0 + a1 * c + csq;
1293
+ b0d = (b0 + b1 * c + b2 * csq)/d;
1294
+ b1d = 2 * (b0 - b2 * csq)/d;
1295
+ b2d = (b0 - b1 * c + b2 * csq)/d;
1296
+ a1d = 2 * (a0 - csq)/d;
1297
+ a2d = (a0 - a1*c + csq)/d;
1298
+ };
1299
+
1300
+ //-----------------------------`(fi.)tf1snp`-------------------------------
1301
+ // First-order special case of tf2snp above.
1302
+ //
1303
+ // #### Usage
1304
+ //
1305
+ // ```
1306
+ // _ : tf1snp(b1,b0,a0) : _
1307
+ // ```
1308
+ //----------------------------------------------
1309
+ declare tf1snp author "Julius O. Smith III";
1310
+ declare tf1snp copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1311
+ declare tf1snp license "MIT-style STK-4.3 license";
1312
+ tf1snp(b1,b0,a0,w1) = fi.tf2snp(b1,b0,0,a0,0,w1); // FIXME: Faust compiler does not fully optimize - does C++?
1313
+
1314
+ //-----------------------------`(fi.)tf3slf`-------------------------------
1315
+ // Analogous to `tf2s` above, but third order, and using the typical
1316
+ // low-frequency-matching bilinear-transform constant 2/T ("lf" series)
1317
+ // instead of the specific-frequency-matching value used in `tf2s` and `tf1s`.
1318
+ // Note the lack of a "w1" argument.
1319
+ //
1320
+ // #### Usage
1321
+ //
1322
+ // ```
1323
+ // _ : tf3slf(b3,b2,b1,b0,a3,a2,a1,a0) : _
1324
+ // ```
1325
+ //----------------------------------------------
1326
+ declare tf3slf author "Julius O. Smith III";
1327
+ declare tf3slf copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1328
+ declare tf3slf license "MIT-style STK-4.3 license";
1329
+ tf3slf(b3,b2,b1,b0,a3,a2,a1,a0) = tf3(b0d,b1d,b2d,b3d,a1d,a2d,a3d) with {
1330
+ c = 2.0 * ma.SR; // bilinear-transform scale-factor ("lf" case)
1331
+ csq = c*c;
1332
+ cc = csq*c;
1333
+ // Thank you maxima:
1334
+ b3d = (b3*c^3-b2*c^2+b1*c-b0)/d;
1335
+ b2d = (-3*b3*c^3+b2*c^2+b1*c-3*b0)/d;
1336
+ b1d = (3*b3*c^3+b2*c^2-b1*c-3*b0)/d;
1337
+ b0d = (-b3*c^3-b2*c^2-b1*c-b0)/d;
1338
+ a3d = (a3*c^3-a2*c^2+a1*c-a0)/d;
1339
+ a2d = (-3*a3*c^3+a2*c^2+a1*c-3*a0)/d;
1340
+ a1d = (3*a3*c^3+a2*c^2-a1*c-3*a0)/d;
1341
+ d = (-a3*c^3-a2*c^2-a1*c-a0);
1342
+ };
1343
+
1344
+ //-----------------------------`(fi.)tf1s`--------------------------------
1345
+ // First-order direct-form digital filter,
1346
+ // specified by ANALOG transfer-function polynomials B(s)/A(s),
1347
+ // and a frequency-scaling parameter.
1348
+ //
1349
+ // #### Usage
1350
+ //
1351
+ // ```
1352
+ // _ : tf1s(b1,b0,a0,w1) : _
1353
+ // ```
1354
+ // Where:
1355
+ //
1356
+ // b1 s + b0
1357
+ // H(s) = ----------
1358
+ // s + a0
1359
+ //
1360
+ // and `w1` is the desired digital frequency (in radians/second)
1361
+ // corresponding to analog frequency 1 rad/sec (i.e., `s = j`).
1362
+ //
1363
+ // #### Example test program
1364
+ //
1365
+ // A first-order ANALOG Butterworth lowpass filter,
1366
+ // normalized to have cutoff frequency at 1 rad/sec,
1367
+ // has transfer function:
1368
+ //
1369
+ // 1
1370
+ // H(s) = -------
1371
+ // s + 1
1372
+ //
1373
+ // so `b0 = a0 = 1` and `b1 = 0`. Therefore, a DIGITAL first-order
1374
+ // Butterworth lowpass with gain -3dB at `SR/4` is specified as
1375
+ //
1376
+ // ```
1377
+ // tf1s(0,1,1,PI*SR/2); // digital half-band order 1 Butterworth
1378
+ // ```
1379
+ //
1380
+ // #### Method
1381
+ //
1382
+ // Bilinear transform scaled for exact mapping of w1.
1383
+ //
1384
+ // #### Reference
1385
+ // <https://ccrma.stanford.edu/~jos/pasp/Bilinear_Transformation.html>
1386
+ //----------------------------------------------
1387
+ declare tf1s author "Julius O. Smith III";
1388
+ declare tf1s copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1389
+ declare tf1s license "MIT-style STK-4.3 license";
1390
+ tf1s(b1,b0,a0,w1) = tf1(b0d,b1d,a1d)
1391
+ with {
1392
+ c = 1/tan(w1*0.5/ma.SR); // bilinear-transform scale-factor
1393
+ d = a0 + c;
1394
+ b1d = (b0 - b1*c) / d;
1395
+ b0d = (b0 + b1*c) / d;
1396
+ a1d = (a0 - c) / d;
1397
+ };
1398
+
1399
+ //-----------------------------`(fi.)tf2sb`--------------------------------
1400
+ // Bandpass mapping of `tf2s`: In addition to a frequency-scaling parameter
1401
+ // `w1` (set to HALF the desired passband width in rad/sec),
1402
+ // there is a desired center-frequency parameter wc (also in rad/s).
1403
+ // Thus, `tf2sb` implements a fourth-order digital bandpass filter section
1404
+ // specified by the coefficients of a second-order analog lowpass prototype
1405
+ // section. Such sections can be combined in series for higher orders.
1406
+ // The order of mappings is (1) frequency scaling (to set lowpass cutoff w1),
1407
+ // (2) bandpass mapping to wc, then (3) the bilinear transform, with the
1408
+ // usual scale parameter `2*SR`. Algebra carried out in maxima and pasted here.
1409
+ //
1410
+ // #### Usage
1411
+ //
1412
+ // ```
1413
+ // _ : tf2sb(b2,b1,b0,a1,a0,w1,wc) : _
1414
+ // ```
1415
+ //----------------------------------------------
1416
+ declare tf2sb author "Julius O. Smith III";
1417
+ declare tf2sb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1418
+ declare tf2sb license "MIT-style STK-4.3 license";
1419
+ tf2sb(b2,b1,b0,a1,a0,w1,wc) =
1420
+ iir((b0d/a0d,b1d/a0d,b2d/a0d,b3d/a0d,b4d/a0d),(a1d/a0d,a2d/a0d,a3d/a0d,a4d/a0d)) with {
1421
+ T = 1.0/float(ma.SR);
1422
+ b0d = (4*b0*w1^2+8*b2*wc^2)*T^2+8*b1*w1*T+16*b2;
1423
+ b1d = 4*b2*wc^4*T^4+4*b1*wc^2*w1*T^3-16*b1*w1*T-64*b2;
1424
+ b2d = 6*b2*wc^4*T^4+(-8*b0*w1^2-16*b2*wc^2)*T^2+96*b2;
1425
+ b3d = 4*b2*wc^4*T^4-4*b1*wc^2*w1*T^3+16*b1*w1*T-64*b2;
1426
+ b4d = (b2*wc^4*T^4-2*b1*wc^2*w1*T^3+(4*b0*w1^2+8*b2*wc^2)*T^2-8*b1*w1*T+16*b2)
1427
+ + b2*wc^4*T^4+2*b1*wc^2*w1*T^3;
1428
+ a0d = wc^4*T^4+2*a1*wc^2*w1*T^3+(4*a0*w1^2+8*wc^2)*T^2+8*a1*w1*T+16;
1429
+ a1d = 4*wc^4*T^4+4*a1*wc^2*w1*T^3-16*a1*w1*T-64;
1430
+ a2d = 6*wc^4*T^4+(-8*a0*w1^2-16*wc^2)*T^2+96;
1431
+ a3d = 4*wc^4*T^4-4*a1*wc^2*w1*T^3+16*a1*w1*T-64;
1432
+ a4d = wc^4*T^4-2*a1*wc^2*w1*T^3+(4*a0*w1^2+8*wc^2)*T^2-8*a1*w1*T+16;
1433
+ };
1434
+
1435
+ //-----------------------------`(fi.)tf1sb`--------------------------------
1436
+ // First-to-second-order lowpass-to-bandpass section mapping,
1437
+ // analogous to tf2sb above.
1438
+ //
1439
+ // #### Usage
1440
+ //
1441
+ // ```
1442
+ // _ : tf1sb(b1,b0,a0,w1,wc) : _
1443
+ // ```
1444
+ //----------------------------------------------
1445
+ declare tf1sb author "Julius O. Smith III";
1446
+ declare tf1sb copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1447
+ declare tf1sb license "MIT-style STK-4.3 license";
1448
+ tf1sb(b1,b0,a0,w1,wc) = tf2(b0d/a0d,b1d/a0d,b2d/a0d,a1d/a0d,a2d/a0d) with {
1449
+ T = 1.0/float(ma.SR);
1450
+ a0d = wc^2*T^2+2*a0*w1*T+4;
1451
+ b0d = b1*wc^2*T^2 +2*b0*w1*T+4*b1;
1452
+ b1d = 2*b1*wc^2*T^2-8*b1;
1453
+ b2d = b1*wc^2*T^2-2*b0*w1*T+4*b1;
1454
+ a1d = 2*wc^2*T^2-8;
1455
+ a2d = wc^2*T^2-2*a0*w1*T+4;
1456
+ };
1457
+
1458
+ //==============================Simple Resonator Filters==================================
1459
+ //========================================================================================
1460
+
1461
+ //------------------`(fi.)resonlp`-----------------
1462
+ // Simple resonant lowpass filter based on `tf2s` (virtual analog).
1463
+ // `resonlp` is a standard Faust function.
1464
+ //
1465
+ // #### Usage
1466
+ //
1467
+ // ```
1468
+ // _ : resonlp(fc,Q,gain) : _
1469
+ // _ : resonhp(fc,Q,gain) : _
1470
+ // _ : resonbp(fc,Q,gain) : _
1471
+ //
1472
+ // ```
1473
+ //
1474
+ // Where:
1475
+ //
1476
+ // * `fc`: center frequency (Hz)
1477
+ // * `Q`: q
1478
+ // * `gain`: gain (0-1)
1479
+ //---------------------------------------------------------------------
1480
+ // resonlp = 2nd-order lowpass with corner resonance:
1481
+ declare resonlp author "Julius O. Smith III";
1482
+ declare resonlp copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1483
+ declare resonlp license "MIT-style STK-4.3 license";
1484
+ resonlp(fc,Q,gain) = tf2s(b2,b1,b0,a1,a0,wc)
1485
+ with {
1486
+ wc = 2*ma.PI*fc;
1487
+ a1 = 1/Q;
1488
+ a0 = 1;
1489
+ b2 = 0;
1490
+ b1 = 0;
1491
+ b0 = gain;
1492
+ };
1493
+
1494
+
1495
+ //------------------`(fi.)resonhp`-----------------
1496
+ // Simple resonant highpass filters based on `tf2s` (virtual analog).
1497
+ // `resonhp` is a standard Faust function.
1498
+ //
1499
+ // #### Usage
1500
+ //
1501
+ // ```
1502
+ // _ : resonlp(fc,Q,gain) : _
1503
+ // _ : resonhp(fc,Q,gain) : _
1504
+ // _ : resonbp(fc,Q,gain) : _
1505
+ //
1506
+ // ```
1507
+ //
1508
+ // Where:
1509
+ //
1510
+ // * `fc`: center frequency (Hz)
1511
+ // * `Q`: q
1512
+ // * `gain`: gain (0-1)
1513
+ //---------------------------------------------------------------------
1514
+ // resonhp = 2nd-order highpass with corner resonance:
1515
+ declare resonhp author "Julius O. Smith III";
1516
+ declare resonhp copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1517
+ declare resonhp license "MIT-style STK-4.3 license";
1518
+ resonhp(fc,Q,gain,x) = gain*x-resonlp(fc,Q,gain,x);
1519
+
1520
+
1521
+ //------------------`(fi.)resonbp`-----------------
1522
+ // Simple resonant bandpass filters based on `tf2s` (virtual analog).
1523
+ // `resonbp` is a standard Faust function.
1524
+ //
1525
+ // #### Usage
1526
+ //
1527
+ // ```
1528
+ // _ : resonlp(fc,Q,gain) : _
1529
+ // _ : resonhp(fc,Q,gain) : _
1530
+ // _ : resonbp(fc,Q,gain) : _
1531
+ //
1532
+ // ```
1533
+ //
1534
+ // Where:
1535
+ //
1536
+ // * `fc`: center frequency (Hz)
1537
+ // * `Q`: q
1538
+ // * `gain`: gain (0-1)
1539
+ //---------------------------------------------------------------------
1540
+ // resonbp = 2nd-order bandpass
1541
+ declare resonbp author "Julius O. Smith III";
1542
+ declare resonbp copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1543
+ declare resonbp license "MIT-style STK-4.3 license";
1544
+ resonbp(fc,Q,gain) = tf2s(b2,b1,b0,a1,a0,wc)
1545
+ with {
1546
+ wc = 2*ma.PI*fc;
1547
+ a1 = 1/Q;
1548
+ a0 = 1;
1549
+ b2 = 0;
1550
+ b1 = gain;
1551
+ b0 = 0;
1552
+ };
1553
+
1554
+
1555
+ //======================Butterworth Lowpass/Highpass Filters==============================
1556
+ //========================================================================================
1557
+
1558
+ //----------------`(fi.)lowpass`--------------------
1559
+ // Nth-order Butterworth lowpass filter.
1560
+ // `lowpass` is a standard Faust function.
1561
+ //
1562
+ // #### Usage
1563
+ //
1564
+ // ```
1565
+ // _ : lowpass(N,fc) : _
1566
+ // ```
1567
+ //
1568
+ // Where:
1569
+ //
1570
+ // * `N`: filter order (number of poles), nonnegative constant numerical expression
1571
+ // * `fc`: desired cut-off frequency (-3dB frequency) in Hz
1572
+ //
1573
+ // #### References
1574
+ // * <https://ccrma.stanford.edu/~jos/filters/Butterworth_Lowpass_Design.html>
1575
+ // * `butter` function in Octave `("[z,p,g] = butter(N,1,'s');")`
1576
+ //------------------------------
1577
+ declare lowpass author "Julius O. Smith III";
1578
+ declare lowpass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1579
+ declare lowpass license "MIT-style STK-4.3 license";
1580
+ lowpass(N,fc) = lowpass0_highpass1(0,N,fc);
1581
+
1582
+
1583
+ //----------------`(fi.)highpass`--------------------
1584
+ // Nth-order Butterworth highpass filters.
1585
+ // `highpass` is a standard Faust function.
1586
+ //
1587
+ // #### Usage
1588
+ //
1589
+ // ```
1590
+ // _ : highpass(N,fc) : _
1591
+ // ```
1592
+ //
1593
+ // Where:
1594
+ //
1595
+ // * `N`: filter order (number of poles), nonnegative constant numerical expression
1596
+ // * `fc`: desired cut-off frequency (-3dB frequency) in Hz
1597
+ //
1598
+ // #### References
1599
+ // * <https://ccrma.stanford.edu/~jos/filters/Butterworth_Lowpass_Design.html>
1600
+ // * `butter` function in Octave `("[z,p,g] = butter(N,1,'s');")`
1601
+ //------------------------------
1602
+ declare highpass author "Julius O. Smith III";
1603
+ declare highpass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1604
+ declare higpass license "MIT-style STK-4.3 license";
1605
+ highpass(N,fc) = lowpass0_highpass1(1,N,fc);
1606
+
1607
+
1608
+ //-------------`(fi.)lowpass0_highpass1`--------------
1609
+ declare lowpass0_highpass1 author "Julius O. Smith III";
1610
+ declare lowpass0_highpass1 "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1611
+ declare lowpass0_highpass1 "MIT-style STK-4.3 license";
1612
+ lowpass0_highpass1(s,N,fc) = lphpr(s,N,N,fc)
1613
+ with {
1614
+ lphpr(s,0,N,fc) = _;
1615
+ lphpr(s,1,N,fc) = tf1s(s,1-s,1,2*ma.PI*fc);
1616
+ lphpr(s,O,N,fc) = lphpr(s,(O-2),N,fc) : tf2s(s,0,1-s,a1s,1,w1) with {
1617
+ parity = N % 2;
1618
+ S = (O-parity)/2; // current section number
1619
+ a1s = -2*cos((ma.PI)*-1 + (1-parity)*ma.PI/(2*N) + (S-1+parity)*ma.PI/N);
1620
+ w1 = 2*ma.PI*fc;
1621
+ };
1622
+ };
1623
+
1624
+
1625
+ //================Special Filter-Bank Delay-Equalizing Allpass Filters====================
1626
+ // These special allpass filters are needed by filterbank et al. below.
1627
+ // They are equivalent to (`lowpass(N,fc)` +|- `highpass(N,fc))/2`, but with
1628
+ // canceling pole-zero pairs removed (which occurs for odd N).
1629
+ //========================================================================================
1630
+
1631
+ //--------------------`(fi.)lowpass_plus`|`minus_highpass`----------------
1632
+ declare highpass_plus_lowpass author "Julius O. Smith III";
1633
+ declare highpass_plus_lowpass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1634
+ declare highpass_plus_lowpass license "MIT-style STK-4.3 license";
1635
+ highpass_plus_lowpass(1,fc) = _;
1636
+ highpass_plus_lowpass(3,fc) = tf2s(1,-1,1,1,1,w1) with { w1 = 2*ma.PI*fc; };
1637
+ highpass_plus_lowpass(5,fc) = tf2s(1,-a11,1,a11,1,w1)
1638
+ with {
1639
+ a11 = 1.618033988749895;
1640
+ w1 = 2*ma.PI*fc;
1641
+ };
1642
+
1643
+ // Catch-all definitions for generality - even order is done:
1644
+ highpass_plus_lowpass(N,fc) = _ <: switch_odd_even(N%2,N,fc) with {
1645
+ switch_odd_even(0,N,fc) = highpass_plus_lowpass_even(N,fc);
1646
+ switch_odd_even(1,N,fc) = highpass_plus_lowpass_odd(N,fc);
1647
+ };
1648
+
1649
+ declare highpass_minus_lowpass author "Julius O. Smith III";
1650
+ declare highpass_minus_lowpass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1651
+ declare highpass_minus_lowpass license "MIT-style STK-4.3 license";
1652
+ highpass_minus_lowpass(3,fc) = tf1s(-1,1,1,w1) with { w1 = 2*ma.PI*fc; };
1653
+ highpass_minus_lowpass(5,fc) = tf1s(1,-1,1,w1) : tf2s(1,-a12,1,a12,1,w1)
1654
+ with {
1655
+ a12 = 0.618033988749895;
1656
+ w1 = 2*ma.PI*fc;
1657
+ };
1658
+
1659
+ // Catch-all definitions for generality - even order is done:
1660
+ highpass_minus_lowpass(N,fc) = _ <: switch_odd_even(N%2,N,fc) with {
1661
+ switch_odd_even(0,N,fc) = highpass_minus_lowpass_even(N,fc);
1662
+ switch_odd_even(1,N,fc) = highpass_minus_lowpass_odd(N,fc);
1663
+ };
1664
+
1665
+ declare highpass_plus_lowpass_even author "Julius O. Smith III";
1666
+ declare highpass_plus_lowpass_even copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1667
+ declare highpass_plus_lowpass_even license "MIT-style STK-4.3 license";
1668
+ highpass_plus_lowpass_even(N,fc) = highpass(N,fc) + lowpass(N,fc);
1669
+
1670
+ declare highpass_minus_lowpass_even author "Julius O. Smith III";
1671
+ declare highpass_minus_lowpass_even copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1672
+ declare highpass_plus_lowpass_even license "MIT-style STK-4.3 license";
1673
+ highpass_minus_lowpass_even(N,fc) = highpass(N,fc) - lowpass(N,fc);
1674
+
1675
+ declare highpass_plus_lowpass_odd author "Julius O. Smith III";
1676
+ declare highpass_plus_lowpass_odd copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1677
+ declare highpass_plus_lowpass_odd license "MIT-style STK-4.3 license";
1678
+ // FIXME: Rewrite the following, as for orders 3 and 5 above,
1679
+ // to eliminate pole-zero cancellations:
1680
+ highpass_plus_lowpass_odd(N,fc) = highpass(N,fc) + lowpass(N,fc);
1681
+
1682
+ declare highpass_minus_lowpass_odd author "Julius O. Smith III";
1683
+ declare highpass_minus_lowpass_odd copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1684
+ declare highpass_plus_lowpass_odd license "MIT-style STK-4.3 license";
1685
+ // FIXME: Rewrite the following, as for orders 3 and 5 above,
1686
+ // to eliminate pole-zero cancellations:
1687
+ highpass_minus_lowpass_odd(N,fc) = highpass(N,fc) - lowpass(N,fc);
1688
+
1689
+
1690
+ //==========================Elliptic (Cauer) Lowpass Filters==============================
1691
+ // Elliptic (Cauer) Lowpass Filters
1692
+ //
1693
+ // #### References
1694
+ // * <http://en.wikipedia.org/wiki/Elliptic_filter>
1695
+ // * functions `ncauer` and `ellip` in Octave.
1696
+ //========================================================================================
1697
+
1698
+ //-----------------------------`(fi.)lowpass3e`-----------------------------
1699
+ // Third-order Elliptic (Cauer) lowpass filter.
1700
+ //
1701
+ // #### Usage
1702
+ //
1703
+ // ```
1704
+ // _ : lowpass3e(fc) : _
1705
+ // ```
1706
+ //
1707
+ // Where:
1708
+ //
1709
+ // * `fc`: -3dB frequency in Hz
1710
+ //
1711
+ // #### Design
1712
+ //
1713
+ // For spectral band-slice level display (see `octave_analyzer3e`):
1714
+ //
1715
+ // ```
1716
+ // [z,p,g] = ncauer(Rp,Rs,3); % analog zeros, poles, and gain, where
1717
+ // Rp = 60 % dB ripple in stopband
1718
+ // Rs = 0.2 % dB ripple in passband
1719
+ // ```
1720
+ //---------------------------------------------------------------------
1721
+ declare lowpass3e author "Julius O. Smith III";
1722
+ declare lowpass3e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1723
+ declare lowpass3e license "MIT-style STK-4.3 license";
1724
+ lowpass3e(fc) = tf2s(b21,b11,b01,a11,a01,w1) : tf1s(0,1,a02,w1)
1725
+ with {
1726
+ a11 = 0.802636764161030; // format long; poly(p(1:2)) % in octave
1727
+ a01 = 1.412270893774204;
1728
+ a02 = 0.822445908998816; // poly(p(3)) % in octave
1729
+ b21 = 0.019809144837789; // poly(z)
1730
+ b11 = 0;
1731
+ b01 = 1.161516418982696;
1732
+ w1 = 2*ma.PI*fc;
1733
+ };
1734
+
1735
+ //-----------------------------`(fi.)lowpass6e`-----------------------------
1736
+ // Sixth-order Elliptic/Cauer lowpass filter.
1737
+ //
1738
+ // #### Usage
1739
+ //
1740
+ // ```
1741
+ // _ : lowpass6e(fc) : _
1742
+ // ```
1743
+ //
1744
+ // Where:
1745
+ //
1746
+ // * `fc`: -3dB frequency in Hz
1747
+ //
1748
+ // #### Design
1749
+ //
1750
+ // For spectral band-slice level display (see octave_analyzer6e):
1751
+ //
1752
+ // ```
1753
+ // [z,p,g] = ncauer(Rp,Rs,6); % analog zeros, poles, and gain, where
1754
+ // Rp = 80 % dB ripple in stopband
1755
+ // Rs = 0.2 % dB ripple in passband
1756
+ // ```
1757
+ //----------------------------------------------------------------------
1758
+ declare lowpass6e author "Julius O. Smith III";
1759
+ declare lowpass6e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1760
+ declare lowpass6e license "MIT-style STK-4.3 license";
1761
+ lowpass6e(fc) =
1762
+ tf2s(b21,b11,b01,a11,a01,w1) :
1763
+ tf2s(b22,b12,b02,a12,a02,w1) :
1764
+ tf2s(b23,b13,b03,a13,a03,w1)
1765
+ with {
1766
+ b21 = 0.000099999997055;
1767
+ a21 = 1;
1768
+ b11 = 0;
1769
+ a11 = 0.782413046821645;
1770
+ b01 = 0.000433227200555;
1771
+ a01 = 0.245291508706160;
1772
+ b22 = 1;
1773
+ a22 = 1;
1774
+ b12 = 0;
1775
+ a12 = 0.512478641889141;
1776
+ b02 = 7.621731298870603;
1777
+ a02 = 0.689621364484675;
1778
+ b23 = 1;
1779
+ a23 = 1;
1780
+ b13 = 0;
1781
+ a13 = 0.168404871113589;
1782
+ b03 = 53.536152954556727;
1783
+ a03 = 1.069358407707312;
1784
+ w1 = 2*ma.PI*fc;
1785
+ };
1786
+
1787
+
1788
+ //=========================Elliptic Highpass Filters======================================
1789
+ //========================================================================================
1790
+
1791
+ //-----------------------------`(fi.)highpass3e`-----------------------------
1792
+ // Third-order Elliptic (Cauer) highpass filter. Inversion of `lowpass3e` wrt unit
1793
+ // circle in s plane (s <- 1/s).
1794
+ //
1795
+ // #### Usage
1796
+ //
1797
+ // ```
1798
+ // _ : highpass3e(fc) : _
1799
+ // ```
1800
+ //
1801
+ // Where:
1802
+ //
1803
+ // * `fc`: -3dB frequency in Hz
1804
+ //-------------------------------------------------------------------------
1805
+ declare highpass3e author "Julius O. Smith III";
1806
+ declare highpass3e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1807
+ declare highpass3e license "MIT-style STK-4.3 license";
1808
+ highpass3e(fc) = tf2s(b01/a01,b11/a01,b21/a01,a11/a01,1/a01,w1) :
1809
+ tf1s(1/a02,0,1/a02,w1)
1810
+ with {
1811
+ a11 = 0.802636764161030;
1812
+ a01 = 1.412270893774204;
1813
+ a02 = 0.822445908998816;
1814
+ b21 = 0.019809144837789;
1815
+ b11 = 0;
1816
+ b01 = 1.161516418982696;
1817
+ w1 = 2*ma.PI*fc;
1818
+ };
1819
+
1820
+ //-----------------------------`(fi.)highpass6e`-----------------------------
1821
+ // Sixth-order Elliptic/Cauer highpass filter. Inversion of `lowpass3e` wrt unit
1822
+ // circle in s plane (s <- 1/s).
1823
+ //
1824
+ // #### Usage
1825
+ //
1826
+ // ```
1827
+ // _ : highpass6e(fc) : _
1828
+ // ```
1829
+ //
1830
+ // Where:
1831
+ //
1832
+ // * `fc`: -3dB frequency in Hz
1833
+ //-------------------------------------------------------------------------
1834
+ declare highpass6e author "Julius O. Smith III";
1835
+ declare highpass6e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1836
+ declare highpass6e license "MIT-style STK-4.3 license";
1837
+ highpass6e(fc) =
1838
+ tf2s(b01/a01,b11/a01,b21/a01,a11/a01,1/a01,w1) :
1839
+ tf2s(b02/a02,b12/a02,b22/a02,a12/a02,1/a02,w1) :
1840
+ tf2s(b03/a03,b13/a03,b23/a03,a13/a03,1/a03,w1)
1841
+ with {
1842
+ b21 = 0.000099999997055;
1843
+ a21 = 1;
1844
+ b11 = 0;
1845
+ a11 = 0.782413046821645;
1846
+ b01 = 0.000433227200555;
1847
+ a01 = 0.245291508706160;
1848
+ b22 = 1;
1849
+ a22 = 1;
1850
+ b12 = 0;
1851
+ a12 = 0.512478641889141;
1852
+ b02 = 7.621731298870603;
1853
+ a02 = 0.689621364484675;
1854
+ b23 = 1;
1855
+ a23 = 1;
1856
+ b13 = 0;
1857
+ a13 = 0.168404871113589;
1858
+ b03 = 53.536152954556727;
1859
+ a03 = 1.069358407707312;
1860
+ w1 = 2*ma.PI*fc;
1861
+ };
1862
+
1863
+
1864
+ //========================Butterworth Bandpass/Bandstop Filters===========================
1865
+ //========================================================================================
1866
+
1867
+ //--------------------`(fi.)bandpass`----------------
1868
+ // Order 2*Nh Butterworth bandpass filter made using the transformation
1869
+ // `s <- s + wc^2/s` on `lowpass(Nh)`, where `wc` is the desired bandpass center
1870
+ // frequency. The `lowpass(Nh)` cutoff `w1` is half the desired bandpass width.
1871
+ // `bandpass` is a standard Faust function.
1872
+ //
1873
+ // #### Usage
1874
+ //
1875
+ // ```
1876
+ // _ : bandpass(Nh,fl,fu) : _
1877
+ // ```
1878
+ //
1879
+ // Where:
1880
+ //
1881
+ // * `Nh`: HALF the desired bandpass order (which is therefore even)
1882
+ // * `fl`: lower -3dB frequency in Hz
1883
+ // * `fu`: upper -3dB frequency in Hz
1884
+ // Thus, the passband width is `fu-fl`,
1885
+ // and its center frequency is `(fl+fu)/2`.
1886
+ //
1887
+ // #### Reference
1888
+ // <http://cnx.org/content/m16913/latest/>
1889
+ //-------------------------------------------------------------------------
1890
+ declare bandpass author "Julius O. Smith III";
1891
+ declare bandpass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1892
+ declare bandpass license "MIT-style STK-4.3 license";
1893
+ bandpass(Nh,fl,fu) = bandpass0_bandstop1(0,Nh,fl,fu);
1894
+
1895
+
1896
+ //--------------------`(fi.)bandstop`----------------
1897
+ // Order 2*Nh Butterworth bandstop filter made using the transformation
1898
+ // `s <- s + wc^2/s` on `highpass(Nh)`, where `wc` is the desired bandpass center
1899
+ // frequency. The `highpass(Nh)` cutoff `w1` is half the desired bandpass width.
1900
+ // `bandstop` is a standard Faust function.
1901
+ //
1902
+ // #### Usage
1903
+ //
1904
+ // ```
1905
+ // _ : bandstop(Nh,fl,fu) : _
1906
+ // ```
1907
+ // Where:
1908
+ //
1909
+ // * `Nh`: HALF the desired bandstop order (which is therefore even)
1910
+ // * `fl`: lower -3dB frequency in Hz
1911
+ // * `fu`: upper -3dB frequency in Hz
1912
+ // Thus, the passband (stopband) width is `fu-fl`,
1913
+ // and its center frequency is `(fl+fu)/2`.
1914
+ //
1915
+ // #### Reference
1916
+ // <http://cnx.org/content/m16913/latest/>
1917
+ //-------------------------------------------------------------------------
1918
+ declare bandstop author "Julius O. Smith III";
1919
+ declare bandstop copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1920
+ declare bandstop license "MIT-style STK-4.3 license";
1921
+ bandstop(Nh,fl,fu) = bandpass0_bandstop1(1,Nh,fl,fu);
1922
+
1923
+ declare bandpass0_bandstop1 author "Julius O. Smith III";
1924
+ declare bandpass0_bandstop1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1925
+ declare bandpass0_bandstop1 license "MIT-style STK-4.3 license";
1926
+ bandpass0_bandstop1(s,Nh,fl,fu) = bpbsr(s,Nh,Nh,fl,fu)
1927
+ with {
1928
+ wl = 2*ma.PI*fl; // digital (z-plane) lower passband edge
1929
+ wu = 2*ma.PI*fu; // digital (z-plane) upper passband edge
1930
+
1931
+ c = 2.0*ma.SR; // bilinear transform scaling used in tf2sb, tf1sb
1932
+ wla = c*tan(wl/c); // analog (s-plane) lower cutoff
1933
+ wua = c*tan(wu/c); // analog (s-plane) upper cutoff
1934
+
1935
+ wc = sqrt(wla*wua); // s-plane center frequency
1936
+ w1 = wua - wc^2/wua; // s-plane lowpass prototype cutoff
1937
+
1938
+ bpbsr(s,0,Nh,fl,fu) = _;
1939
+ bpbsr(s,1,Nh,fl,fu) = tf1sb(s,1-s,1,w1,wc);
1940
+ bpbsr(s,O,Nh,fl,fu) = bpbsr(s,O-2,Nh,fl,fu) : tf2sb(s,0,(1-s),a1s,1,w1,wc)
1941
+ with {
1942
+ parity = Nh % 2;
1943
+ S = (O-parity)/2; // current section number
1944
+ a1s = -2*cos(-1*ma.PI + (1-parity)*ma.PI/(2*Nh) + (S-1+parity)*ma.PI/Nh);
1945
+ };
1946
+ };
1947
+
1948
+
1949
+ //===========================Elliptic Bandpass Filters====================================
1950
+ //========================================================================================
1951
+
1952
+ //---------------------`(fi.)bandpass6e`-----------------------------
1953
+ // Order 12 elliptic bandpass filter analogous to `bandpass(6)`.
1954
+ //--------------------------------------------------------------
1955
+ declare bandpass6e author "Julius O. Smith III";
1956
+ declare bandpass6e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1957
+ declare bandpass6e license "MIT-style STK-4.3 license";
1958
+ bandpass6e(fl,fu) = tf2sb(b21,b11,b01,a11,a01,w1,wc) : tf1sb(0,1,a02,w1,wc)
1959
+ with {
1960
+ a11 = 0.802636764161030; // In octave: format long; poly(p(1:2))
1961
+ a01 = 1.412270893774204;
1962
+ a02 = 0.822445908998816; // poly(p(3))
1963
+ b21 = 0.019809144837789; // poly(z)
1964
+ b11 = 0;
1965
+ b01 = 1.161516418982696;
1966
+
1967
+ wl = 2*ma.PI*fl; // digital (z-plane) lower passband edge
1968
+ wu = 2*ma.PI*fu; // digital (z-plane) upper passband edge
1969
+
1970
+ c = 2.0*ma.SR; // bilinear transform scaling used in tf2sb, tf1sb
1971
+ wla = c*tan(wl/c); // analog (s-plane) lower cutoff
1972
+ wua = c*tan(wu/c); // analog (s-plane) upper cutoff
1973
+
1974
+ wc = sqrt(wla*wua); // s-plane center frequency
1975
+ w1 = wua - wc^2/wua; // s-plane lowpass cutoff
1976
+ };
1977
+
1978
+ //----------------------`(fi.)bandpass12e`---------------------------
1979
+ // Order 24 elliptic bandpass filter analogous to `bandpass(6)`.
1980
+ //--------------------------------------------------------------
1981
+ declare bandpass12e author "Julius O. Smith III";
1982
+ declare bandpass12e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
1983
+ declare bandpass12e license "MIT-style STK-4.3 license";
1984
+ bandpass12e(fl,fu) =
1985
+ tf2sb(b21,b11,b01,a11,a01,w1,wc) :
1986
+ tf2sb(b22,b12,b02,a12,a02,w1,wc) :
1987
+ tf2sb(b23,b13,b03,a13,a03,w1,wc)
1988
+ with { // octave script output:
1989
+ b21 = 0.000099999997055;
1990
+ a21 = 1;
1991
+ b11 = 0;
1992
+ a11 = 0.782413046821645;
1993
+ b01 = 0.000433227200555;
1994
+ a01 = 0.245291508706160;
1995
+ b22 = 1;
1996
+ a22 = 1;
1997
+ b12 = 0;
1998
+ a12 = 0.512478641889141;
1999
+ b02 = 7.621731298870603;
2000
+ a02 = 0.689621364484675;
2001
+ b23 = 1;
2002
+ a23 = 1;
2003
+ b13 = 0;
2004
+ a13 = 0.168404871113589;
2005
+ b03 = 53.536152954556727;
2006
+ a03 = 1.069358407707312;
2007
+
2008
+ wl = 2*ma.PI*fl; // digital (z-plane) lower passband edge
2009
+ wu = 2*ma.PI*fu; // digital (z-plane) upper passband edge
2010
+
2011
+ c = 2.0*ma.SR; // bilinear transform scaling used in tf2sb, tf1sb
2012
+ wla = c*tan(wl/c); // analog (s-plane) lower cutoff
2013
+ wua = c*tan(wu/c); // analog (s-plane) upper cutoff
2014
+
2015
+ wc = sqrt(wla*wua); // s-plane center frequency
2016
+ w1 = wua - wc^2/wua; // s-plane lowpass cutoff
2017
+ };
2018
+
2019
+ //------------------------`(fi.)pospass`---------------------------
2020
+ // Positive-Pass Filter (single-side-band filter).
2021
+ //
2022
+ // #### Usage
2023
+ //
2024
+ // ```
2025
+ // _ : pospass(N,fc) : _,_
2026
+ // ```
2027
+ //
2028
+ // where
2029
+ //
2030
+ // * `N`: filter order (Butterworth bandpass for positive frequencies).
2031
+ // * `fc`: lower bandpass cutoff frequency in Hz.
2032
+ // - Highpass cutoff frequency at ma.SR/2 - fc Hz.
2033
+ //
2034
+ // #### Example test program
2035
+ //
2036
+ // * See `dm.pospass_demo`
2037
+ // * Look at frequency response
2038
+ //
2039
+ // #### Method
2040
+ //
2041
+ // A filter passing only positive frequencies can be made from a
2042
+ // half-band lowpass by modulating it up to the positive-frequency range.
2043
+ // Equivalently, down-modulate the input signal using a complex sinusoid at -SR/4 Hz,
2044
+ // lowpass it with a half-band filter, and modulate back up by SR/4 Hz.
2045
+ // In Faust/math notation:
2046
+ // $$pospass(N) = \ast(e^{-j\frac{\pi}{2}n}) : \mbox{lowpass(N,SR/4)} : \ast(e^{j\frac{\pi}{2}n})$$
2047
+ //
2048
+ // An approximation to the Hilbert transform is given by the
2049
+ // imaginary output signal:
2050
+ //
2051
+ // ```
2052
+ // hilbert(N) = pospass(N) : !,*(2);
2053
+ // ```
2054
+ //
2055
+ // #### References
2056
+ // * <https://ccrma.stanford.edu/~jos/mdft/Analytic_Signals_Hilbert_Transform.html>
2057
+ // * <https://ccrma.stanford.edu/~jos/sasp/Comparison_Optimal_Chebyshev_FIR_I.html>
2058
+ // * <https://ccrma.stanford.edu/~jos/sasp/Hilbert_Transform.html>
2059
+ //------------------------------------------------------------
2060
+ declare pospass author "Julius O. Smith III";
2061
+ declare pospass copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2062
+ declare pospass license "MIT-style STK-4.3 license";
2063
+ pospass(N,fc) = fi.pospass0(lpf) with {
2064
+ fcs = ma.SR/4 - fc; // Upper lowpass cutoff = (SR/2 - fc) - SR/4
2065
+ lpf = fi.lowpass(N,fcs); // Butterworth lowpass
2066
+ };
2067
+
2068
+ declare pospass6e author "Julius O. Smith III";
2069
+ declare pospass6e copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2070
+ declare pospass6e license "MIT-style STK-4.3 license";
2071
+ pospass6e(fc) = fi.pospass0(lpf) with {
2072
+ lpf = fi.lowpass6e(ma.SR/4 - fc); // Elliptic lowpass, order 6
2073
+ };
2074
+
2075
+ declare pospass0 author "Julius O. Smith III";
2076
+ declare pospass0 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2077
+ declare pospass0 license "MIT-style STK-4.3 license";
2078
+ pospass0(lpf) = unmodulate : lpf, lpf : modulate with {
2079
+ c = 1-1' : +~(*(-1):mem); // complex sinusoid rotating at SR/4
2080
+ s = c'; // ||: 0, 1, 0, -1 :||
2081
+ unmodulate = _ <: *(c),*(-s); // subtract SR/4 from all input frequencies
2082
+ modulate(x,y) = c*x-s*y, c*y + s*x; // add SR/4 to all frequencies
2083
+ };
2084
+
2085
+
2086
+ //=================Parametric Equalizers (Shelf, Peaking)=================================
2087
+ // Parametric Equalizers (Shelf, Peaking).
2088
+ //
2089
+ // #### References
2090
+ // * <http://en.wikipedia.org/wiki/Equalization>
2091
+ // * <https://webaudio.github.io/Audio-EQ-Cookbook/Audio-EQ-Cookbook.txt>
2092
+ // * Digital Audio Signal Processing, Udo Zolzer, Wiley, 1999, p. 124
2093
+ // * <https://ccrma.stanford.edu/~jos/filters/Low_High_Shelving_Filters.html>
2094
+ // * <https://ccrma.stanford.edu/~jos/filters/Peaking_Equalizers.html>
2095
+ // * maxmsp.lib in the Faust distribution
2096
+ // * bandfilter.dsp in the faust2pd distribution
2097
+ //========================================================================================
2098
+
2099
+ //----------------------`(fi.)low_shelf`----------------------
2100
+ // First-order "low shelf" filter (gain boost|cut between dc and some frequency)
2101
+ // `low_shelf` is a standard Faust function.
2102
+ //
2103
+ // #### Usage
2104
+ //
2105
+ // ```
2106
+ // _ : lowshelf(N,L0,fx) : _
2107
+ // _ : low_shelf(L0,fx) : _ // default case (order 3)
2108
+ // _ : lowshelf_other_freq(N,L0,fx) : _
2109
+ // ```
2110
+ //
2111
+ // Where:
2112
+ // * `N`: filter order 1, 3, 5, ... (odd only, default should be 3, a constant numerical expression)
2113
+ // * `L0`: desired level (dB) between dc and fx (boost `L0>0` or cut `L0<0`)
2114
+ // * `fx`: -3dB frequency of lowpass band (`L0>0`) or upper band (`L0<0`)
2115
+ // (see "SHELF SHAPE" below).
2116
+ //
2117
+ // The gain at SR/2 is constrained to be 1.
2118
+ // The generalization to arbitrary odd orders is based on the well known
2119
+ // fact that odd-order Butterworth band-splits are allpass-complementary
2120
+ // (see filterbank documentation below for references).
2121
+ //
2122
+ // #### Shelf Shape
2123
+ // The magnitude frequency response is approximately piecewise-linear
2124
+ // on a log-log plot ("BODE PLOT"). The Bode "stick diagram" approximation
2125
+ // L(lf) is easy to state in dB versus dB-frequency lf = dB(f):
2126
+ //
2127
+ // * L0 > 0:
2128
+ // * L(lf) = L0, f between 0 and fx = 1st corner frequency;
2129
+ // * L(lf) = L0 - N * (lf - lfx), f between fx and f2 = 2nd corner frequency;
2130
+ // * L(lf) = 0, lf > lf2.
2131
+ // * lf2 = lfx + L0/N = dB-frequency at which level gets back to 0 dB.
2132
+ // * L0 < 0:
2133
+ // * L(lf) = L0, f between 0 and f1 = 1st corner frequency;
2134
+ // * L(lf) = - N * (lfx - lf), f between f1 and lfx = 2nd corner frequency;
2135
+ // * L(lf) = 0, lf > lfx.
2136
+ // * lf1 = lfx + L0/N = dB-frequency at which level goes up from L0.
2137
+ //
2138
+ // See `lowshelf_other_freq`.
2139
+ //
2140
+ // #### References
2141
+ // See "Parametric Equalizers" above for references regarding
2142
+ // `low_shelf`, `high_shelf`, and `peak_eq`.
2143
+ //
2144
+ //--------------------------------------------------------------
2145
+ declare lowshelf author "Julius O. Smith III";
2146
+ declare lowshelf copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2147
+ declare lowshelf license "MIT-style STK-4.3 license";
2148
+ lowshelf(N,L0,fx) = filterbank(N,(fx)) : _, *(ba.db2linear(L0)) :> _;
2149
+
2150
+ // Special cases and optimization:
2151
+ declare low_shelf author "Julius O. Smith III";
2152
+ declare low_shelf copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2153
+ declare low_shelf license "MIT-style STK-4.3 license";
2154
+ low_shelf = lowshelf(3); // default = 3rd order Butterworth
2155
+
2156
+ declare low_shelf1 author "Julius O. Smith III";
2157
+ declare low_shelf1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2158
+ declare low_shelf1 license "MIT-style STK-4.3 license";
2159
+ low_shelf1(L0,fx,x) = x + (ba.db2linear(L0)-1)*lowpass(1,fx,x); // optimized
2160
+
2161
+ declare low_shelf1_l author "Julius O. Smith III";
2162
+ declare low_shelf1_l copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2163
+ declare low_shelf1_l license "MIT-style STK-4.3 license";
2164
+ low_shelf1_l(G0,fx,x) = x + (G0-1)*lowpass(1,fx,x); // optimized
2165
+
2166
+ declare lowshelf_other_freq author "Julius O. Smith III";
2167
+ declare lowshelf_other_freq copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2168
+ declare lowshelf_other_freq license "MIT-style STK-4.3 license";
2169
+ lowshelf_other_freq(N, L0, fx) = ba.db2linear(ba.linear2db(fx) + L0/N); // convenience
2170
+
2171
+ //-------------`(fi.)high_shelf`--------------
2172
+ // First-order "high shelf" filter (gain boost|cut above some frequency).
2173
+ // `high_shelf` is a standard Faust function.
2174
+ //
2175
+ // #### Usage
2176
+ //
2177
+ // ```
2178
+ // _ : highshelf(N,Lpi,fx) : _
2179
+ // _ : high_shelf(L0,fx) : _ // default case (order 3)
2180
+ // _ : highshelf_other_freq(N,Lpi,fx) : _
2181
+ // ```
2182
+ //
2183
+ // Where:
2184
+ //
2185
+ // * `N`: filter order 1, 3, 5, ... (odd only, a constant numerical expression).
2186
+ // * `Lpi`: desired level (dB) between fx and SR/2 (boost Lpi>0 or cut Lpi<0)
2187
+ // * `fx`: -3dB frequency of highpass band (L0>0) or lower band (L0<0)
2188
+ // (Use highshelf_other_freq() below to find the other one.)
2189
+ //
2190
+ // The gain at dc is constrained to be 1.
2191
+ // See `lowshelf` documentation above for more details on shelf shape.
2192
+ //
2193
+ // #### References
2194
+ // See "Parametric Equalizers" above for references regarding
2195
+ // `low_shelf`, `high_shelf`, and `peak_eq`.
2196
+ //
2197
+ //--------------------------------------------------------------
2198
+ declare highshelf author "Julius O. Smith III";
2199
+ declare highshelf copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2200
+ declare highshelf license "MIT-style STK-4.3 license";
2201
+ highshelf(N,Lpi,fx) = filterbank(N,(fx)) : *(ba.db2linear(Lpi)), _ :> _;
2202
+ // Special cases and optimization:
2203
+ high_shelf = highshelf(3); // default = 3rd order Butterworth
2204
+
2205
+ declare high_shelf1 author "Julius O. Smith III";
2206
+ declare high_shelf1 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2207
+ declare high_shelf1 license "MIT-style STK-4.3 license";
2208
+ high_shelf1(Lpi,fx,x) = x + (ba.db2linear(Lpi)-1)*highpass(1,fx,x); // optimized
2209
+
2210
+ declare high_shelf1_l author "Julius O. Smith III";
2211
+ declare high_shelf1_l copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2212
+ declare high_shelf1_l license "MIT-style STK-4.3 license";
2213
+ high_shelf1_l(Gpi,fx,x) = x + (Gpi-1)*highpass(1,fx,x); //optimized
2214
+
2215
+ // shelf transitions between frequency fx and this one:
2216
+ declare highshelf_other_freq author "Julius O. Smith III";
2217
+ declare highshelf_other_freq copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2218
+ declare highshelf_other_freq license "MIT-style STK-4.3 license";
2219
+ highshelf_other_freq(N, Lpi, fx) = ba.db2linear(ba.linear2db(fx) - Lpi/N);
2220
+
2221
+
2222
+ //-------------------`(fi.)peak_eq`------------------------------
2223
+ // Second order "peaking equalizer" section (gain boost or cut near some frequency)
2224
+ // Also called a "parametric equalizer" section.
2225
+ // `peak_eq` is a standard Faust function.
2226
+ //
2227
+ // #### Usage
2228
+ //
2229
+ // ```
2230
+ // _ : peak_eq(Lfx,fx,B) : _
2231
+ // ```
2232
+ //
2233
+ // Where:
2234
+ //
2235
+ // * `Lfx`: level (dB) at fx (boost Lfx>0 or cut Lfx<0)
2236
+ // * `fx`: peak frequency (Hz)
2237
+ // * `B`: bandwidth (B) of peak in Hz
2238
+ //
2239
+ // #### References
2240
+ // See "Parametric Equalizers" above for references regarding
2241
+ // `low_shelf`, `high_shelf`, and `peak_eq`.
2242
+ //
2243
+ //--------------------------------------------------------------
2244
+ declare peak_eq author "Julius O. Smith III";
2245
+ declare peak_eq copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2246
+ declare peak_eq license "MIT-style STK-4.3 license";
2247
+ peak_eq(Lfx,fx,B) = tf2s(1,b1s,1,a1s,1,wx) with {
2248
+ T = float(1.0/ma.SR);
2249
+ Bw = B*T/sin(wx*T); // prewarp s-bandwidth for more accuracy in z-plane
2250
+ a1 = ma.PI*Bw;
2251
+ b1 = g*a1;
2252
+ g = ba.db2linear(abs(Lfx));
2253
+ b1s = select2(Lfx>0,a1,b1); // When Lfx>0, pole dominates bandwidth
2254
+ a1s = select2(Lfx>0,b1,a1); // When Lfx<0, zero dominates
2255
+ wx = 2*ma.PI*fx;
2256
+ };
2257
+
2258
+ //--------------------`(fi.)peak_eq_cq`----------------------------
2259
+ // Constant-Q second order peaking equalizer section.
2260
+ //
2261
+ // #### Usage
2262
+ //
2263
+ // ```
2264
+ // _ : peak_eq_cq(Lfx,fx,Q) : _
2265
+ // ```
2266
+ //
2267
+ // Where:
2268
+ //
2269
+ // * `Lfx`: level (dB) at fx
2270
+ // * `fx`: boost or cut frequency (Hz)
2271
+ // * `Q`: "Quality factor" = fx/B where B = bandwidth of peak in Hz
2272
+ //
2273
+ // #### References
2274
+ // See "Parametric Equalizers" above for references regarding
2275
+ // `low_shelf`, `high_shelf`, and `peak_eq`.
2276
+ //
2277
+ //------------------------------------------------------------
2278
+ declare peak_eq_cq author "Julius O. Smith III";
2279
+ declare peak_eq_cq copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2280
+ declare peak_eq_cq license "MIT-style STK-4.3 license";
2281
+ peak_eq_cq(Lfx,fx,Q) = peak_eq(Lfx,fx,fx/Q);
2282
+
2283
+ //-------------------`(fi.)peak_eq_rm`--------------------------
2284
+ // Regalia-Mitra second order peaking equalizer section.
2285
+ //
2286
+ // #### Usage
2287
+ //
2288
+ // ```
2289
+ // _ : peak_eq_rm(Lfx,fx,tanPiBT) : _
2290
+ // ```
2291
+ //
2292
+ // Where:
2293
+ //
2294
+ // * `Lfx`: level (dB) at fx
2295
+ // * `fx`: boost or cut frequency (Hz)
2296
+ // * `tanPiBT`: `tan(PI*B/SR)`, where B = -3dB bandwidth (Hz) when 10^(Lfx/20) = 0
2297
+ // ~ PI*B/SR for narrow bandwidths B
2298
+ //
2299
+ // #### Reference
2300
+ // P.A. Regalia, S.K. Mitra, and P.P. Vaidyanathan,
2301
+ // "The Digital All-Pass Filter: A Versatile Signal Processing Building Block"
2302
+ // Proceedings of the IEEE, 76(1):19-37, Jan. 1988. (See pp. 29-30.)
2303
+ // See also "Parametric Equalizers" above for references on shelf
2304
+ // and peaking equalizers in general.
2305
+ //
2306
+ //------------------------------------------------------------
2307
+ declare peak_eq_rm author "Julius O. Smith III";
2308
+ declare peak_eq_rm copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2309
+ declare peak_eq_rm license "MIT-style STK-4.3 license";
2310
+ peak_eq_rm(Lfx,fx,tanPiBT) = _ <: _,A,_ : +,- : *(0.5),*(K/2.0) : + with {
2311
+ A = tf2(k2, k1*(1+k2), 1, k1*(1+k2), k2) <: _,_; // allpass
2312
+ k1 = 0.0 - cos(2.0*ma.PI*fx/ma.SR);
2313
+ k2 = (1.0 - tanPiBT)/(1.0 + tanPiBT);
2314
+ K = ba.db2linear(Lfx);
2315
+ };
2316
+
2317
+
2318
+ //---------------------`(fi.)spectral_tilt`-------------------------
2319
+ // Spectral tilt filter, providing an arbitrary spectral rolloff factor
2320
+ // alpha in (-1,1), where
2321
+ // -1 corresponds to one pole (-6 dB per octave), and
2322
+ // +1 corresponds to one zero (+6 dB per octave).
2323
+ // In other words, alpha is the slope of the ln magnitude versus ln frequency.
2324
+ // For a "pinking filter" (e.g., to generate 1/f noise from white noise),
2325
+ // set alpha to -1/2.
2326
+ //
2327
+ // #### Usage
2328
+ //
2329
+ // ```
2330
+ // _ : spectral_tilt(N,f0,bw,alpha) : _
2331
+ // ```
2332
+ // Where:
2333
+ //
2334
+ // * `N`: desired integer filter order (fixed at compile time)
2335
+ // * `f0`: lower frequency limit for desired roll-off band > 0
2336
+ // * `bw`: bandwidth of desired roll-off band
2337
+ // * `alpha`: slope of roll-off desired in nepers per neper,
2338
+ // between -1 and 1 (ln mag / ln radian freq)
2339
+ //
2340
+ // #### Example test program
2341
+ //
2342
+ // See `dm.spectral_tilt_demo` and the documentation for `no.pink_noise`.
2343
+ //
2344
+ // #### Reference
2345
+ // J.O. Smith and H.F. Smith,
2346
+ // "Closed Form Fractional Integration and Differentiation via Real Exponentially Spaced Pole-Zero Pairs",
2347
+ // arXiv.org publication arXiv:1606.06154 [cs.CE], June 7, 2016,
2348
+ // <http://arxiv.org/abs/1606.06154>
2349
+ //
2350
+ //------------------------------------------------------------
2351
+ declare spectral_tilt author "Julius O. Smith III";
2352
+ declare spectral_tilt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2353
+ declare spectral_tilt license "MIT-style STK-4.3 license";
2354
+ spectral_tilt(N,f0,bw,alpha) = seq(i,N,sec(i)) with {
2355
+ sec(i) = g * tf1s(b1,b0,a0,1) with {
2356
+ g = a0/b0; // unity dc-gain scaling
2357
+ b1 = 1.0;
2358
+ b0 = mzh(i);
2359
+ a0 = mph(i);
2360
+ mzh(i) = prewarp(mz(i),ma.SR,w0); // prewarping for bilinear transform
2361
+ mph(i) = prewarp(mp(i),ma.SR,w0);
2362
+ prewarp(w,SR,wp) = wp * tan(w*T/2) / tan(wp*T/2) with { T = 1/ma.SR; };
2363
+ mz(i) = w0 * r ^ (-alpha+i); // minus zero i in s plane
2364
+ mp(i) = w0 * r ^ i; // minus pole i in s plane
2365
+ f0p = max(f0,ma.EPSILON); // cannot go to zero
2366
+ w0 = 2 * ma.PI * f0p; // radian frequency of first pole
2367
+ f1 = f0p + bw; // upper band limit
2368
+ r = (f1/f0p)^(1.0/float(N-1)); // pole ratio (2 => octave spacing)
2369
+ };
2370
+ };
2371
+
2372
+
2373
+ //----------------------`(fi.)levelfilter`----------------------
2374
+ // Dynamic level lowpass filter.
2375
+ // `levelfilter` is a standard Faust function.
2376
+ //
2377
+ // #### Usage
2378
+ //
2379
+ // ```
2380
+ // _ : levelfilter(L,freq) : _
2381
+ // ```
2382
+ //
2383
+ // Where:
2384
+ //
2385
+ // * `L`: desired level (in dB) at Nyquist limit (SR/2), e.g., -60
2386
+ // * `freq`: corner frequency (-3dB point) usually set to fundamental freq
2387
+ // * `N`: Number of filters in series where L = L/N
2388
+ //
2389
+ // #### Reference
2390
+ // <https://ccrma.stanford.edu/realsimple/faust_strings/Dynamic_Level_Lowpass_Filter.html>
2391
+ //------------------------------------------------------------
2392
+ declare levelfilter author "Julius O. Smith III";
2393
+ declare levelfilter copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2394
+ declare levelfilter license "MIT-style STK-4.3 license";
2395
+ levelfilter(L,freq,x) = (L * L0 * x) + ((1.0-L) * lp2out(x))
2396
+ with {
2397
+ L0 = pow(L,1/3);
2398
+ Lw = ma.PI*freq/ma.SR; // = w1 T / 2
2399
+ Lgain = Lw / (1.0 + Lw);
2400
+ Lpole2 = (1.0 - Lw) / (1.0 + Lw);
2401
+ lp2out = *(Lgain) : + ~ *(Lpole2);
2402
+ };
2403
+
2404
+
2405
+ //----------------------`(fi.)levelfilterN`----------------------
2406
+ // Dynamic level lowpass filter.
2407
+ //
2408
+ // #### Usage
2409
+ //
2410
+ // ```
2411
+ // _ : levelfilterN(N,freq,L) : _
2412
+ // ```
2413
+ //
2414
+ // Where:
2415
+ //
2416
+ // * `N`: Number of filters in series where L = L/N, a constant numerical expression
2417
+ // * `freq`: corner frequency (-3dB point) usually set to fundamental freq
2418
+ // * `L`: desired level (in dB) at Nyquist limit (SR/2), e.g., -60
2419
+ //
2420
+ // #### Reference
2421
+ // <https://ccrma.stanford.edu/realsimple/faust_strings/Dynamic_Level_Lowpass_Filter.html>
2422
+ //------------------------------------------------------------
2423
+ declare levelfilterN author "Julius O. Smith III";
2424
+ declare levelfilterN copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2425
+ declare levelfilterN license "MIT-style STK-4.3 license";
2426
+ levelfilterN(N,freq,L) = seq(i,N,levelfilter((L/N),freq));
2427
+
2428
+
2429
+ //=================================Mth-Octave Filter-Banks================================
2430
+ // Mth-octave filter-banks split the input signal into a bank of parallel signals, one
2431
+ // for each spectral band. They are related to the Mth-Octave Spectrum-Analyzers in
2432
+ // `analysis.lib`.
2433
+ // The documentation of this library contains more details about the implementation.
2434
+ // The parameters are:
2435
+ //
2436
+ // * `M`: number of band-slices per octave (>1), a constant numerical expression
2437
+ // * `N`: total number of bands (>2), a constant numerical expression
2438
+ // * `ftop`: upper bandlimit of the Mth-octave bands (<SR/2)
2439
+ //
2440
+ // In addition to the Mth-octave output signals, there is a highpass signal
2441
+ // containing frequencies from ftop to SR/2, and a "dc band" lowpass signal
2442
+ // containing frequencies from 0 (dc) up to the start of the Mth-octave bands.
2443
+ // Thus, the N output signals are
2444
+ //
2445
+ // ```
2446
+ // highpass(ftop), MthOctaveBands(M,N-2,ftop), dcBand(ftop*2^(-M*(N-1)))
2447
+ // ```
2448
+ //
2449
+ // A Filter-Bank is defined here as a signal bandsplitter having the
2450
+ // property that summing its output signals gives an allpass-filtered
2451
+ // version of the filter-bank input signal. A more conventional term for
2452
+ // this is an "allpass-complementary filter bank". If the allpass filter
2453
+ // is a pure delay (and possible scaling), the filter bank is said to be
2454
+ // a "perfect-reconstruction filter bank" (see Vaidyanathan-1993 cited
2455
+ // below for details). A "graphic equalizer", in which band signals
2456
+ // are scaled by gains and summed, should be based on a filter bank.
2457
+ //
2458
+ // The filter-banks below are implemented as Butterworth or Elliptic
2459
+ // spectrum-analyzers followed by delay equalizers that make them
2460
+ // allpass-complementary.
2461
+ //
2462
+ // #### Increasing Channel Isolation
2463
+ //
2464
+ // Go to higher filter orders - see Regalia et al. or Vaidyanathan (cited
2465
+ // below) regarding the construction of more aggressive recursive
2466
+ // filter-banks using elliptic or Chebyshev prototype filters.
2467
+ //
2468
+ // #### References
2469
+ // * "Tree-structured complementary filter banks using all-pass sections",
2470
+ // Regalia et al., IEEE Trans. Circuits & Systems, CAS-34:1470-1484, Dec. 1987
2471
+ // * "Multirate Systems and Filter Banks", P. Vaidyanathan, Prentice-Hall, 1993
2472
+ // * Elementary filter theory: <https://ccrma.stanford.edu/~jos/filters/>
2473
+ //========================================================================================
2474
+
2475
+ //------------------------`(fi.)mth_octave_filterbank[n]`-------------------------
2476
+ // Allpass-complementary filter banks based on Butterworth band-splitting.
2477
+ // For Butterworth band-splits, the needed delay equalizer is easily found.
2478
+ //
2479
+ // #### Usage
2480
+ //
2481
+ // ```
2482
+ // _ : mth_octave_filterbank(O,M,ftop,N) : par(i,N,_) // Oth-order
2483
+ // _ : mth_octave_filterbank_alt(O,M,ftop,N) : par(i,N,_) // dc-inverted version
2484
+ // ```
2485
+ //
2486
+ // Also for convenience:
2487
+ //
2488
+ // ```
2489
+ // _ : mth_octave_filterbank3(M,ftop,N) : par(i,N,_) // 3rd-order Butterworth
2490
+ // _ : mth_octave_filterbank5(M,ftop,N) : par(i,N,_) // 5th-order Butterworth
2491
+ // mth_octave_filterbank_default = mth_octave_filterbank5;
2492
+ // ```
2493
+ //
2494
+ // Where:
2495
+ //
2496
+ // * `O`: order of filter used to split each frequency band into two, a constant numerical expression
2497
+ // * `M`: number of band-slices per octave, a constant numerical expression
2498
+ // * `ftop`: highest band-split crossover frequency (e.g., 20 kHz)
2499
+ // * `N`: total number of bands (including dc and Nyquist), a constant numerical expression
2500
+ //------------------------------------------------------------
2501
+ declare mth_octave_filterbank author "Julius O. Smith III";
2502
+ declare mth_octave_filterbank copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2503
+ declare mth_octave_filterbank license "MIT-style STK-4.3 license";
2504
+ mth_octave_filterbank(O,M,ftop,N) = an.mth_octave_analyzer(O,M,ftop,N) : delayeq(N)
2505
+ with {
2506
+ fc(n) = ftop * 2^(float(n-N+1)/float(M)); // -3dB crossover frequencies
2507
+ ap(n) = highpass_plus_lowpass(O,fc(n)); // delay-equalizing allpass
2508
+ delayeq(N) = par(i,N-2,apchain(i+1)), _, _;
2509
+ apchain(i) = seq(j,N-1-i,ap(j+1));
2510
+ };
2511
+
2512
+ // dc-inverted version. This reduces the delay-equalizer order for odd O.
2513
+ // Negating the input signal makes the dc band noninverting
2514
+ // and all higher bands sign-inverted (if preferred).
2515
+ declare mth_octave_filterbank_alt author "Julius O. Smith III";
2516
+ declare mth_octave_filterbank_alt copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2517
+ declare mth_octave_filterbank_alt license "MIT-style STK-4.3 license";
2518
+ mth_octave_filterbank_alt(O,M,ftop,N) = an.mth_octave_analyzer(O,M,ftop,N) : delayeqi(O,N)
2519
+ with {
2520
+ fc(n) = ftop * 2^(float(n-N+1)/float(M)); // -3dB crossover frequencies
2521
+ ap(n) = highpass_minus_lowpass(O,fc(n)); // half the order of 'plus' case
2522
+ delayeqi(N) = par(i,N-2,apchain(i+1)), _, *(-1.0);
2523
+ apchain(i) = seq(j,N-1-i,ap(j+1));
2524
+ };
2525
+
2526
+ // Note that even-order cases require complex coefficients.
2527
+ // See Vaidyanathan 1993 and papers cited there for more info.
2528
+ declare mth_octave_filterbank3 author "Julius O. Smith III";
2529
+ declare mth_octave_filterbank3 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2530
+ declare mth_octave_filterbank3 license "MIT-style STK-4.3 license";
2531
+ mth_octave_filterbank3(M,ftop,N) = mth_octave_filterbank_alt(3,M,ftop,N);
2532
+
2533
+ declare mth_octave_filterbank5 author "Julius O. Smith III";
2534
+ declare mth_octave_filterbank5 copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2535
+ declare mth_octave_filterbank5 license "MIT-style STK-4.3 license";
2536
+ mth_octave_filterbank5(M,ftop,N) = mth_octave_filterbank(5,M,ftop,N);
2537
+
2538
+ declare mth_octave_filterbank_default author "Julius O. Smith III";
2539
+ declare mth_octave_filterbank_default copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2540
+ declare mth_octave_filterbank_default license "MIT-style STK-4.3 license";
2541
+ mth_octave_filterbank_default = mth_octave_filterbank5;
2542
+
2543
+
2544
+ //===============Arbitrary-Crossover Filter-Banks and Spectrum Analyzers==================
2545
+ // These are similar to the Mth-octave analyzers above, except that the
2546
+ // band-split frequencies are passed explicitly as arguments.
2547
+ //========================================================================================
2548
+
2549
+ // ACKNOWLEDGMENT
2550
+ // Technique for processing a variable number of signal arguments due
2551
+ // to Yann Orlarey (as is the entire Faust framework!)
2552
+
2553
+ //---------------`(fi.)filterbank`--------------------------
2554
+ // Filter bank.
2555
+ // `filterbank` is a standard Faust function.
2556
+ //
2557
+ // #### Usage
2558
+ //
2559
+ // ```
2560
+ // _ : filterbank (O,freqs) : par(i,N,_) // Butterworth band-splits
2561
+ // ```
2562
+ // Where:
2563
+ //
2564
+ // * `O`: band-split filter order (odd integer required for filterbank[i], a constant numerical expression)
2565
+ // * `freqs`: (fc1,fc2,...,fcNs) [in numerically ascending order], where
2566
+ // Ns=N-1 is the number of octave band-splits
2567
+ // (total number of bands N=Ns+1).
2568
+ //
2569
+ // If frequencies are listed explicitly as arguments, enclose them in parens:
2570
+ //
2571
+ // ```
2572
+ // _ : filterbank(3,(fc1,fc2)) : _,_,_
2573
+ // ```
2574
+ //---------------------------------------------------
2575
+ declare filterbank author "Julius O. Smith III";
2576
+ declare filterbank copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2577
+ declare filterbank license "MIT-style STK-4.3 license";
2578
+ filterbank(O,lfreqs) = an.analyzer(O,lfreqs) : delayeq(nb)
2579
+ with {
2580
+ nb = ba.count(lfreqs);
2581
+ fc(n) = ba.take(n, lfreqs);
2582
+ ap(n) = highpass_plus_lowpass(O,fc(n));
2583
+ delayeq(1) = _,_; // par(i,0,...) does not fly
2584
+ delayeq(nb) = par(i,nb-1,apchain(nb-1-i)),_,_;
2585
+ apchain(0) = _;
2586
+ apchain(i) = ap(i) : apchain(i-1);
2587
+ };
2588
+
2589
+ //-----------------`(fi.)filterbanki`----------------------
2590
+ // Inverted-dc filter bank.
2591
+ //
2592
+ // #### Usage
2593
+ //
2594
+ // ```
2595
+ // _ : filterbanki(O,freqs) : par(i,N,_) // Inverted-dc version
2596
+ // ```
2597
+ //
2598
+ // Where:
2599
+ //
2600
+ // * `O`: band-split filter order (odd integer required for `filterbank[i]`, a constant numerical expression)
2601
+ // * `freqs`: (fc1,fc2,...,fcNs) [in numerically ascending order], where
2602
+ // Ns=N-1 is the number of octave band-splits
2603
+ // (total number of bands N=Ns+1).
2604
+ //
2605
+ // If frequencies are listed explicitly as arguments, enclose them in parens:
2606
+ //
2607
+ // ```
2608
+ // _ : filterbanki(3,(fc1,fc2)) : _,_,_
2609
+ // ```
2610
+ //---------------------------------------------------
2611
+ declare filterbanki author "Julius O. Smith III";
2612
+ declare filterbanki copyright "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2613
+ declare filterbanki license "MIT-style STK-4.3 license";
2614
+ filterbanki(O,lfreqs) = _ <: bsplit(nb)
2615
+ with {
2616
+ nb = ba.count(lfreqs);
2617
+ fc(n) = ba.take(n, lfreqs);
2618
+ lp(n) = lowpass(O,fc(n));
2619
+ hp(n) = highpass(O,fc(n));
2620
+ ap(n) = highpass_minus_lowpass(O,fc(n));
2621
+ bsplit(0) = *(-1.0);
2622
+ bsplit(i) = (hp(i) : delayeq(i-1)), (lp(i) <: bsplit(i-1));
2623
+ delayeq(0) = _; // moving the *(-1) here inverts all outputs BUT dc
2624
+ delayeq(i) = ap(i) : delayeq(i-1);
2625
+ };
2626
+
2627
+
2628
+ //===============State Variable Filters=========================================================
2629
+ // #### References
2630
+ // Solving the continuous SVF equations using trapezoidal integration
2631
+ //
2632
+ // <https://cytomic.com/files/dsp/SvfLinearTrapOptimised2.pdf>
2633
+ //========================================================================================
2634
+
2635
+ //-----------------`(fi.)svf`----------------------
2636
+ // An environment with `lp`, `bp`, `hp`, `notch`, `peak`, `ap`, `bell`, `ls`, `hs` SVF based filters.
2637
+ // All filters have `freq` and `Q` parameters, the `bell`, `ls`, `hs` ones also have a `gain` third parameter.
2638
+ //
2639
+ // #### Usage
2640
+ //
2641
+ // ```
2642
+ // _ : svf.xx(freq, Q, [gain]) : _
2643
+ // ```
2644
+ //
2645
+ // Where:
2646
+ //
2647
+ // * `freq`: cut frequency
2648
+ // * `Q`: quality factor
2649
+ // * `[gain]`: gain in dB
2650
+ //
2651
+ /// ```
2652
+ //---------------------------------------------------
2653
+ declare svf author "Oleg Nesterov";
2654
+ declare svf copyright "Copyright (C) 2020 Oleg Nesterov <oleg@redhat.com>";
2655
+ declare svf license "MIT-style STK-4.3 license";
2656
+
2657
+ svf = environment {
2658
+
2659
+ // Internal implementation
2660
+ svf(T,F,Q,G) = tick ~ (_,_) : !,!,si.dot(3, mix)
2661
+ with {
2662
+ tick(ic1eq, ic2eq, v0) =
2663
+ 2*v1 - ic1eq,
2664
+ 2*v2 - ic2eq,
2665
+ v0, v1, v2
2666
+ with {
2667
+ v1 = ic1eq + g *(v0-ic2eq) : /(1 + g*(g+k));
2668
+ v2 = ic2eq + g * v1;
2669
+ };
2670
+
2671
+ A = pow(10.0, G/40.0);
2672
+
2673
+ g = tan(F * ma.PI/ma.SR) : case {
2674
+ (7) => /(sqrt(A));
2675
+ (8) => *(sqrt(A));
2676
+ (t) => _;
2677
+ } (T);
2678
+
2679
+ k = case {
2680
+ (6) => 1/(Q*A);
2681
+ (t) => 1/Q;
2682
+ } (T);
2683
+
2684
+ mix = case {
2685
+ (0) => 0, 0, 1;
2686
+ (1) => 0, 1, 0;
2687
+ (2) => 1, -k, -1;
2688
+ (3) => 1, -k, 0;
2689
+ (4) => 1, -k, -2;
2690
+ (5) => 1, -2*k, 0;
2691
+ (6) => 1, k*(A*A-1), 0;
2692
+ (7) => 1, k*(A-1), A*A-1;
2693
+ (8) => A*A, k*(1-A)*A, 1-A*A;
2694
+ } (T);
2695
+ };
2696
+
2697
+ // External API
2698
+ lp(f,q) = svf(0, f, q, 0);
2699
+ bp(f,q) = svf(1, f, q, 0);
2700
+ hp(f,q) = svf(2, f, q, 0);
2701
+ notch(f,q) = svf(3, f, q, 0);
2702
+ peak(f,q) = svf(4, f, q, 0);
2703
+ ap(f,q) = svf(5, f, q, 0);
2704
+ bell(f,q,g) = svf(6, f, q, g);
2705
+ ls(f,q,g) = svf(7, f, q, g);
2706
+ hs(f,q,g) = svf(8, f, q, g);
2707
+ };
2708
+
2709
+
2710
+ //===========Linkwitz-Riley 4th-order 2-way, 3-way, and 4-way crossovers=====
2711
+ //
2712
+ // The Linkwitz-Riley (LR) crossovers are designed to produce a fully-flat
2713
+ // magnitude response when their outputs are combined. The 4th-order
2714
+ // LR filters (LR4) have a 24dB/octave slope and they are rather popular audio
2715
+ // crossovers used in multi-band processing.
2716
+ //
2717
+ // The LR4 can be constructed by cascading two second-order Butterworth
2718
+ // filters. For the second-order Butterworth filters, we will use the SVF
2719
+ // filter implemented above by setting the Q-factor to 1.0 / sqrt(2.0).
2720
+ // These will be cascaded in pairs to build the LR4 highpass and lowpass.
2721
+ // For the phase correction, we will use the 2nd-order Butterworth allpass.
2722
+ //
2723
+ // #### Reference
2724
+ // Zavalishin, Vadim. "The art of VA filter design." Native Instruments, Berlin, Germany (2012).
2725
+ //=============================================================================
2726
+
2727
+
2728
+ //----------`(fi.)lowpassLR4`---------------------------------------------------
2729
+ // 4th-order Linkwitz-Riley lowpass.
2730
+ //
2731
+ // #### Usage
2732
+ //
2733
+ // ```
2734
+ // _ : lowpassLR4(cf) : _
2735
+ // ```
2736
+ //
2737
+ // Where:
2738
+ //
2739
+ // * `cf` is the lowpass cutoff in Hz
2740
+ //------------------------------------------------------------------------------
2741
+ declare lowpassLR4 author "Dario Sanfilippo";
2742
+ declare lowpassLR4 copyright
2743
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2744
+ declare lowpassLR4 license "MIT-style STK-4.3 license";
2745
+ lowpassLR4(cf, x) = x : seq(i, 2, svf.lp(cf, 1.0 / sqrt(2.0)));
2746
+
2747
+
2748
+ //----------`(fi.)highpassLR4`--------------------------------------------------
2749
+ // 4th-order Linkwitz-Riley highpass.
2750
+ //
2751
+ // #### Usage
2752
+ //
2753
+ // ```
2754
+ // _ : highpassLR4(cf) : _
2755
+ // ```
2756
+ //
2757
+ // Where:
2758
+ //
2759
+ // * `cf` is the highpass cutoff in Hz
2760
+ //------------------------------------------------------------------------------
2761
+ declare highpassLR4 author "Dario Sanfilippo";
2762
+ declare highpassLR4 copyright
2763
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2764
+ declare highpassLR4 license "MIT-style STK-4.3 license";
2765
+ highpassLR4(cf, x) = x : seq(i, 2, svf.hp(cf, 1.0 / sqrt(2.0)));
2766
+
2767
+
2768
+ //----------`(fi.)crossover2LR4`------------------------------------------------
2769
+ // Two-way 4th-order Linkwitz-Riley crossover.
2770
+ //
2771
+ // #### Usage
2772
+ //
2773
+ // ```
2774
+ // _ : crossover2LR4(cf) : si.bus(2)
2775
+ // ```
2776
+ //
2777
+ // Where:
2778
+ //
2779
+ // * `cf` is the crossover split cutoff in Hz
2780
+ //------------------------------------------------------------------------------
2781
+ declare crossover2LR4 author "Dario Sanfilippo";
2782
+ declare crossover2LR4 copyright
2783
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2784
+ declare crossover2LR4 license "MIT-style STK-4.3 license";
2785
+ crossover2LR4(cf, x) = lowpassLR4(cf, x) , highpassLR4(cf, x);
2786
+
2787
+
2788
+ //----------`(fi.)crossover3LR4`------------------------------------------------
2789
+ // Three-way 4th-order Linkwitz-Riley crossover.
2790
+ //
2791
+ // #### Usage
2792
+ //
2793
+ // ```
2794
+ // _ : crossover3LR4(cf1, cf2) : si.bus(3)
2795
+ // ```
2796
+ //
2797
+ // Where:
2798
+ //
2799
+ // * `cf1` is the crossover lower split cutoff in Hz
2800
+ // * `cf2` is the crossover upper split cutoff in Hz
2801
+ //------------------------------------------------------------------------------
2802
+ declare crossover3LR4 author "Dario Sanfilippo";
2803
+ declare crossover3LR4 copyright
2804
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2805
+ declare crossover3LR4 license "MIT-style STK-4.3 license";
2806
+ crossover3LR4(cf1, cf2, x) =
2807
+ crossover2LR4(cf1, x) : svf.ap(cf2, 1.0 / sqrt(2.0)) , crossover2LR4(cf2);
2808
+
2809
+
2810
+ //----------`(fi.)crossover4LR4`------------------------------------------------
2811
+ // Four-way 4th-order Linkwitz-Riley crossover.
2812
+ //
2813
+ // #### Usage
2814
+ //
2815
+ // ```
2816
+ // _ : crossover4LR4(cf1, cf2, cf3) : si.bus(4)
2817
+ // ```
2818
+ //
2819
+ // Where:
2820
+ //
2821
+ // * `cf1` is the crossover lower split cutoff in Hz
2822
+ // * `cf2` is the crossover mid split cutoff in Hz
2823
+ // * `cf3` is the crossover upper split cutoff in Hz
2824
+ //------------------------------------------------------------------------------
2825
+ declare crossover4LR4 author "Dario Sanfilippo";
2826
+ declare crossover4LR4 copyright
2827
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2828
+ declare crossover4LR4 license "MIT-style STK-4.3 license";
2829
+ crossover4LR4(cf1, cf2, cf3, x) =
2830
+ crossover2LR4(cf2, x) :
2831
+ svf.ap(cf3, 1.0 / sqrt(2.0)) ,
2832
+ svf.ap(cf1, 1.0 / sqrt(2.0)) :
2833
+ crossover2LR4(cf1) ,
2834
+ crossover2LR4(cf3);
2835
+
2836
+
2837
+ //----------`(fi.)crossover8LR4`------------------------------------------------
2838
+ // Eight-way 4th-order Linkwitz-Riley crossover.
2839
+ //
2840
+ // #### Usage
2841
+ //
2842
+ // ```
2843
+ // _ : crossover8LR4(cf1, cf2, cf3, cf4, cf5, cf6, cf7) : si.bus(8)
2844
+ // ```
2845
+ //
2846
+ // Where:
2847
+ //
2848
+ // * `cf1-cf7` are the crossover cutoff frequencies in Hz
2849
+ //------------------------------------------------------------------------------
2850
+ declare crossover8LR4 author "Dario Sanfilippo";
2851
+ declare crossover8LR4 copyright
2852
+ "Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
2853
+ declare crossover8LR4 license "MIT-style STK-4.3 license";
2854
+ crossover8LR4(cf1, cf2, cf3, cf4, cf5, cf6, cf7, x) =
2855
+ crossover2LR4(cf4, x) :
2856
+ (ap(cf6) : ap(cf5) : ap(cf7)) ,
2857
+ (ap(cf2) : ap(cf1) : ap(cf3)) :
2858
+ crossover2LR4(cf2) ,
2859
+ crossover2LR4(cf6) :
2860
+ ap(cf3) ,
2861
+ ap(cf1) ,
2862
+ ap(cf7) ,
2863
+ ap(cf5) :
2864
+ crossover2LR4(cf1) ,
2865
+ crossover2LR4(cf3) ,
2866
+ crossover2LR4(cf5) ,
2867
+ crossover2LR4(cf7)
2868
+ with {
2869
+ ap(cf) = svf.ap(cf, 1.0 / sqrt(2.0));
2870
+ };
2871
+
2872
+
2873
+ //=========================== Standardized Filters ============================
2874
+ //=============================================================================
2875
+ //
2876
+ // This section provides filters that are defined by national or
2877
+ // international standards, e.g. for measurement applications.
2878
+
2879
+ //----------------------`(fi.)itu_r_bs_1770_4_kfilter`-------------------------
2880
+ // The prefilter from Recommendation ITU-R BS.1770-4 for loudness
2881
+ // measurement. Also known as "K-filter". The recommendation defines
2882
+ // biquad filter coefficients for a fixed sample rate of 48kHz (page
2883
+ // 4-5). Here, we construct biquads for arbitrary samplerates. The
2884
+ // resulting filter is normalized, such that the magnitude at 997Hz is
2885
+ // unity gain 1.0.
2886
+ //
2887
+ // Please note, the ITU-recommendation handles the normalization in
2888
+ // equation (2) by subtracting 0.691dB, which is not needed with
2889
+ // `itu_r_bs_1770_4_kfilter`.
2890
+ //
2891
+ // One option for future improvement might be, to round those filter
2892
+ // coefficients, that are almost equal to one. Second, the maximum
2893
+ // magnitude difference at 48kHz between the ITU-defined filter and
2894
+ // `itu_r_bs_1770_4_kfilter` is 0.001dB, which obviously could be
2895
+ // less.
2896
+ //
2897
+ // #### Usage
2898
+ //
2899
+ // ```
2900
+ // _ : itu_r_bs_1770_4_kfilter : _
2901
+ // ```
2902
+ //
2903
+ // #### Reference
2904
+ // <https://www.itu.int/rec/R-REC-BS.1770>
2905
+ // <https://gist.github.com/jkbd/07521a98f7873a2dc3dbe16417930791>
2906
+ //-----------------------------------------------------------------------------
2907
+ declare itu_r_bs_1770_4_kfilter author "Jakob Dübel";
2908
+ declare itu_r_bs_1770_4_kfilter copyright "Copyright (C) 2022 Jakob Dübel";
2909
+ declare itu_r_bs_1770_4_kfilter license "ISC license";
2910
+
2911
+ itu_r_bs_1770_4_kfilter = stage1 : stage2 : normalize997Hz
2912
+ with {
2913
+ freq2k(f_c) = tan((ma.PI * f_c)/ma.SR);
2914
+
2915
+ stage1 = tf22t(b0,b1,b2,a1,a2)
2916
+ with {
2917
+ f_c = 1681.7632251028442; // Hertz
2918
+ gain = 3.9997778685513232; // Decibel
2919
+ K = freq2k(f_c);
2920
+ V_0 = pow(10, (gain/20.0));
2921
+
2922
+ denominator = 1.0 + sqrt(2.0)*K + K^2;
2923
+ b0 = (V_0 + sqrt((2.0*V_0))*K + K^2) / denominator;
2924
+ b1 = 2.0*(K^2 - V_0) / denominator;
2925
+ b2 = (V_0 - sqrt(2.0*V_0)*K + K^2) / denominator;
2926
+
2927
+ a1 = 2*(K^2 - 1) / denominator;
2928
+ a2 = (1 - sqrt(2.0)*K + K^2) / denominator;
2929
+ };
2930
+
2931
+ stage2 = tf22t(b0,b1,b2,a1,a2)
2932
+ with {
2933
+ f_c = 38.135470876002174; // Hertz
2934
+ Q = 0.5003270373223665;
2935
+ K = freq2k(f_c);
2936
+
2937
+ denominator = (K^2) * Q + K + Q;
2938
+ b0 = Q / denominator;
2939
+ b1 = -2*Q / denominator;
2940
+ b2 = b0;
2941
+
2942
+ a1 = (2*Q * (K^2 - 1)) / denominator;
2943
+ a2 = ((K^2) * Q - K + Q) / denominator;
2944
+ };
2945
+
2946
+ normalize997Hz = *(0.9273671710547968);
2947
+ };
2948
+
2949
+
2950
+ //============================Averaging Functions==============================
2951
+ //=============================================================================
2952
+ //
2953
+ // These are a set of samplerate independent averaging functions based on
2954
+ // moving-average and one-pole filters with specific response characteristics.
2955
+
2956
+ //----------------------------`(fi.)avg_rect`----------------------------------
2957
+ // Moving average.
2958
+ //
2959
+ // #### Usage
2960
+ //
2961
+ // ```
2962
+ // _ : avg_rect(period) : _
2963
+ // ```
2964
+ //
2965
+ // Where:
2966
+ //
2967
+ // * `period` is the averaging frame in seconds
2968
+ //-----------------------------------------------------------------------------
2969
+ declare avg_rect author "Dario Sanfilippo and Julius O. Smith III";
2970
+ declare avg_rect copyright "Copyright (C) 2020 Dario Sanfilippo
2971
+ <sanfilippo.dario@gmail.com> and
2972
+ 2003-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>";
2973
+ declare avg_rect license "MIT-style STK-4.3 license";
2974
+ avg_rect(period, x) = x : ba.slidingMean(rint(period * ma.SR));
2975
+
2976
+
2977
+ //----------------------------`(fi.)avg_tau`-------------------------------------
2978
+ // Averaging function based on a one-pole filter and the tau response time.
2979
+ // Tau represents the effective length of the one-pole impulse response,
2980
+ // that is, tau is the integral of the filter's impulse response. This
2981
+ // response is slower to reach the final value but has less ripples in
2982
+ // non-steady signals.
2983
+ //
2984
+ // #### Usage
2985
+ //
2986
+ // ```
2987
+ // _ : avg_tau(period) : _
2988
+ // ```
2989
+ //
2990
+ // Where:
2991
+ //
2992
+ // * `period` is the time, in seconds, for the system to decay by 1/e,
2993
+ // or to reach 1-1/e of its final value.
2994
+ //
2995
+ // #### Reference
2996
+ //
2997
+ // <https://ccrma.stanford.edu/~jos/mdft/Exponentials.html>
2998
+ //-----------------------------------------------------------------------------
2999
+ declare avg_tau author "Dario Sanfilippo and Julius O. Smith III";
3000
+ declare avg_tau copyright "Copyright (C) 2020 Dario Sanfilippo
3001
+ <sanfilippo.dario@gmail.com> and
3002
+ 2003-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>";
3003
+ declare avg_tau license "MIT-style STK-4.3 license";
3004
+ avg_tau(period, x) = fi.lptau(period, x);
3005
+
3006
+
3007
+ //----------------------------`(fi.)avg_t60`-------------------------------------
3008
+ // Averaging function based on a one-pole filter and the t60 response time.
3009
+ // This response is particularly useful when the system is required to
3010
+ // reach the final value after about `period` seconds.
3011
+ //
3012
+ // #### Usage
3013
+ //
3014
+ // ```
3015
+ // _ : avg_t60(period) : _
3016
+ // ```
3017
+ //
3018
+ // Where:
3019
+ //
3020
+ // * `period` is the time, in seconds, for the system to decay by 1/1000,
3021
+ // or to reach 1-1/1000 of its final value.
3022
+ //
3023
+ // #### Reference
3024
+ //
3025
+ // <https://ccrma.stanford.edu/~jos/mdft/Audio_Decay_Time_T60.html>
3026
+ //-----------------------------------------------------------------------------
3027
+ declare avg_t60 author "Dario Sanfilippo and Julius O. Smith III";
3028
+ declare avg_t60 copyright "Copyright (C) 2020 Dario Sanfilippo
3029
+ <sanfilippo.dario@gmail.com> and
3030
+ 2003-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>";
3031
+ declare avg_t60 license "MIT-style STK-4.3 license";
3032
+ avg_t60(period, x) = fi.lpt60(period, x);
3033
+
3034
+
3035
+ //----------------------------`(fi.)avg_t19`-------------------------------------
3036
+ // Averaging function based on a one-pole filter and the t19 response time.
3037
+ // This response is close to the moving-average algorithm as it roughly reaches
3038
+ // the final value after `period` seconds and shows about the same
3039
+ // oscillations for non-steady signals.
3040
+ //
3041
+ // #### Usage
3042
+ //
3043
+ // ```
3044
+ // _ : avg_t19(period) : _
3045
+ // ```
3046
+ //
3047
+ // Where:
3048
+ //
3049
+ // * `period` is the time, in seconds, for the system to decay by 1/e^2.2,
3050
+ // or to reach 1-1/e^2.2 of its final value.
3051
+ //
3052
+ // #### Reference
3053
+ // Zölzer, U. (2008). Digital audio signal processing (Vol. 9). New York: Wiley.
3054
+ //-----------------------------------------------------------------------------
3055
+ declare avg_t19 author "Dario Sanfilippo and Julius O. Smith III";
3056
+ declare avg_t19 copyright "Copyright (C) 2020 Dario Sanfilippo
3057
+ <sanfilippo.dario@gmail.com> and
3058
+ 2003-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>";
3059
+ declare avg_t19 license "MIT-style STK-4.3 license";
3060
+ avg_t19(period, x) = fi.lpt19(period, x);
3061
+
3062
+
3063
+ /*******************************************************************************
3064
+ # Licenses
3065
+
3066
+ ## STK 4.3 License
3067
+
3068
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
3069
+ this software and associated documentation files (the "Software"), to deal in
3070
+ the Software without restriction, including without limitation the rights to
3071
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
3072
+ of the Software, and to permit persons to whom the Software is furnished to do
3073
+ so, subject to the following conditions:
3074
+
3075
+ The above copyright notice and this permission notice shall be included in all
3076
+ copies or substantial portions of the Software.
3077
+
3078
+ Any person wishing to distribute modifications to the Software is asked to send
3079
+ the modifications to the original developer so that they can be incorporated
3080
+ into the canonical version. For software copyrighted by Julius O. Smith III,
3081
+ email your modifications to <jos@ccrma.stanford.edu>. This is, however, not a
3082
+ binding provision of this license.
3083
+
3084
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3085
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3086
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3087
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3088
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3089
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3090
+ SOFTWARE.
3091
+
3092
+ --------------------------------------------------------------------------------
3093
+
3094
+ ## LGPL License
3095
+
3096
+ This program is free software; you can redistribute it and/or modify it under
3097
+ the terms of the GNU Lesser General Public License as published by the Free
3098
+ Software Foundation; either version 2.1 of the License, or (at your option) any
3099
+ later version.
3100
+
3101
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY
3102
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
3103
+ PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
3104
+
3105
+ You should have received a copy of the GNU Lesser General Public License along
3106
+ with the GNU C Library; if not, write to the Free Software Foundation, Inc.,
3107
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
3108
+
3109
+ --------------------------------------------------------------------------------
3110
+
3111
+ ## ISC License
3112
+
3113
+ Permission to use, copy, modify, and/or distribute this software for any
3114
+ purpose with or without fee is hereby granted, provided that the above
3115
+ copyright notice and this permission notice appear in all copies.
3116
+
3117
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3118
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3119
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3120
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3121
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3122
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3123
+ PERFORMANCE OF THIS SOFTWARE.
3124
+
3125
+ *******************************************************************************/