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.
- cyfaust/CMakeLists.txt +93 -0
- cyfaust/__init__.py +0 -0
- cyfaust/__main__.py +819 -0
- cyfaust/box.pxd +46 -0
- cyfaust/box.pyx +2459 -0
- cyfaust/common.pxd +5 -0
- cyfaust/common.pyx +61 -0
- cyfaust/cyfaust.cpython-311-darwin.so +0 -0
- cyfaust/faust_box.pxd +298 -0
- cyfaust/faust_box_oo.pyx +66 -0
- cyfaust/faust_gui.pxd +261 -0
- cyfaust/faust_interp.pxd +160 -0
- cyfaust/faust_player.pxd +80 -0
- cyfaust/faust_signal.pxd +257 -0
- cyfaust/gui_statics.cpp +15 -0
- cyfaust/interp.pyx +673 -0
- cyfaust/player.cpp +32519 -0
- cyfaust/player.pyx +191 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUBase.cpp +2327 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUBase.h +1019 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUDispatch.cpp +423 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUDispatch.h +82 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUInputElement.cpp +151 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUInputElement.h +119 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUOutputElement.cpp +62 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUOutputElement.h +66 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUPlugInDispatch.cpp +615 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUPlugInDispatch.h +128 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUScopeElement.cpp +512 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/AUScopeElement.h +544 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/ComponentBase.cpp +370 -0
- cyfaust/resources/architecture/AU/AUPublic/AUBase/ComponentBase.h +340 -0
- cyfaust/resources/architecture/AU/AUPublic/AUEffectBase/AUEffectBase.cpp +463 -0
- cyfaust/resources/architecture/AU/AUPublic/AUEffectBase/AUEffectBase.h +391 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUInstrumentBase.cpp +837 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUInstrumentBase.h +267 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUMIDIBase.cpp +495 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/AUMIDIBase.h +213 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/LockFreeFIFO.h +168 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MIDIControlHandler.h +92 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MusicDeviceBase.cpp +354 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/MusicDeviceBase.h +126 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthElement.cpp +419 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthElement.h +227 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthEvent.h +145 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNote.cpp +138 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNote.h +186 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNoteList.cpp +93 -0
- cyfaust/resources/architecture/AU/AUPublic/AUInstrumentBase/SynthNoteList.h +232 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUBaseHelper.cpp +134 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUBaseHelper.h +80 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUBuffer.cpp +217 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUBuffer.h +267 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUMIDIDefs.h +136 -0
- cyfaust/resources/architecture/AU/AUPublic/Utility/AUSilentTimeout.h +93 -0
- cyfaust/resources/architecture/AU/English.lproj/InfoPlist.strings +0 -0
- cyfaust/resources/architecture/AU/FaustAU.exp +2 -0
- cyfaust/resources/architecture/AU/FaustAU.xcodeproj/project.pbxproj +968 -0
- cyfaust/resources/architecture/AU/FaustAU.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- cyfaust/resources/architecture/AU/FaustAUCustomView.plist +14 -0
- cyfaust/resources/architecture/AU/Info.plist +47 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAAtomic.h +305 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAAtomicStack.h +239 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAAudioChannelLayout.cpp +153 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAAudioChannelLayout.h +199 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAAutoDisposer.h +508 -0
- cyfaust/resources/architecture/AU/PublicUtility/CABufferList.cpp +264 -0
- cyfaust/resources/architecture/AU/PublicUtility/CABufferList.h +319 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAByteOrder.h +161 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugMacros.cpp +88 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugMacros.h +580 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugPrintf.cpp +89 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugPrintf.h +115 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugger.cpp +77 -0
- cyfaust/resources/architecture/AU/PublicUtility/CADebugger.h +56 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAException.h +83 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAGuard.cpp +339 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAGuard.h +133 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAHostTimeBase.cpp +110 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAHostTimeBase.h +231 -0
- cyfaust/resources/architecture/AU/PublicUtility/CALogMacros.h +140 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAMath.h +68 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAMutex.cpp +345 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAMutex.h +163 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAReferenceCounted.h +87 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAStreamBasicDescription.cpp +795 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAStreamBasicDescription.h +409 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAThreadSafeList.h +255 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnit.cpp +191 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnit.h +100 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAVectorUnitTypes.h +59 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAXException.cpp +49 -0
- cyfaust/resources/architecture/AU/PublicUtility/CAXException.h +338 -0
- cyfaust/resources/architecture/AU/SectionPatternLight.tiff +0 -0
- cyfaust/resources/architecture/AU/Source/AUSource/FaustAU.h +38 -0
- cyfaust/resources/architecture/AU/Source/AUSource/FaustAU.r +153 -0
- cyfaust/resources/architecture/AU/Source/AUSource/FaustAUVersion.h +64 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Bargraph.h +18 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Bargraph.m +21 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Button.h +20 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Button.m +56 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomView.h +87 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomView.m +834 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomViewFactory.h +13 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_CustomViewFactory.m +22 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Knob.h +81 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Knob.m +199 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Slider.h +18 -0
- cyfaust/resources/architecture/AU/Source/CocoaUI/FaustAU_Slider.m +21 -0
- cyfaust/resources/architecture/AU/version.plist +16 -0
- cyfaust/resources/architecture/VST/Info.plist +28 -0
- cyfaust/resources/architecture/VST/PkgInfo +1 -0
- cyfaust/resources/architecture/VST/README +11 -0
- cyfaust/resources/architecture/VST/VST.xcode/project.pbxproj +655 -0
- cyfaust/resources/architecture/alsa-console.cpp +246 -0
- cyfaust/resources/architecture/alsa-gtk.cpp +220 -0
- cyfaust/resources/architecture/alsa-qt.cpp +229 -0
- cyfaust/resources/architecture/api/DspFaust.cpp +612 -0
- cyfaust/resources/architecture/api/DspFaust.h +511 -0
- cyfaust/resources/architecture/api/README.md +237 -0
- cyfaust/resources/architecture/api/doc/Generic.md +38 -0
- cyfaust/resources/architecture/au-effect.cpp +487 -0
- cyfaust/resources/architecture/au-instrument.cpp +573 -0
- cyfaust/resources/architecture/bench.cpp +91 -0
- cyfaust/resources/architecture/c-jack-gtk.c +227 -0
- cyfaust/resources/architecture/ca-gtk.cpp +284 -0
- cyfaust/resources/architecture/ca-qt.cpp +424 -0
- cyfaust/resources/architecture/cpal.rs +195 -0
- cyfaust/resources/architecture/csound.cpp +245 -0
- cyfaust/resources/architecture/csvplot.cpp +227 -0
- cyfaust/resources/architecture/daisy/Makefile +14 -0
- cyfaust/resources/architecture/daisy/README.md +50 -0
- cyfaust/resources/architecture/daisy/ex_faust.cpp +173 -0
- cyfaust/resources/architecture/dssi.cpp +1262 -0
- cyfaust/resources/architecture/dummy-mem.cpp +186 -0
- cyfaust/resources/architecture/dummy.cpp +294 -0
- cyfaust/resources/architecture/faust/au/AUUI.h +404 -0
- cyfaust/resources/architecture/faust/audio/alsa-dsp.h +693 -0
- cyfaust/resources/architecture/faust/audio/android-dsp.h +583 -0
- cyfaust/resources/architecture/faust/audio/audio.h +115 -0
- cyfaust/resources/architecture/faust/audio/channels.h +122 -0
- cyfaust/resources/architecture/faust/audio/coreaudio-dsp.h +1543 -0
- cyfaust/resources/architecture/faust/audio/coreaudio-ios-dsp.h +743 -0
- cyfaust/resources/architecture/faust/audio/dummy-audio.h +255 -0
- cyfaust/resources/architecture/faust/audio/esp32-dsp.h +284 -0
- cyfaust/resources/architecture/faust/audio/fpe.h +164 -0
- cyfaust/resources/architecture/faust/audio/jack-dsp.h +534 -0
- cyfaust/resources/architecture/faust/audio/juce-dsp.h +119 -0
- cyfaust/resources/architecture/faust/audio/netjack-dsp.h +354 -0
- cyfaust/resources/architecture/faust/audio/oboe-dsp.h +308 -0
- cyfaust/resources/architecture/faust/audio/ofaudio-dsp.h +155 -0
- cyfaust/resources/architecture/faust/audio/opensles-android-dsp.h +631 -0
- cyfaust/resources/architecture/faust/audio/osc-dsp.h +120 -0
- cyfaust/resources/architecture/faust/audio/portaudio-dsp.h +236 -0
- cyfaust/resources/architecture/faust/audio/rtaudio-dsp.h +241 -0
- cyfaust/resources/architecture/faust/audio/samAudio.h +140 -0
- cyfaust/resources/architecture/faust/audio/teensy-dsp.h +171 -0
- cyfaust/resources/architecture/faust/dsp/cmajor-cpp-dsp.h +253 -0
- cyfaust/resources/architecture/faust/dsp/cmajorpatch-dsp.h +483 -0
- cyfaust/resources/architecture/faust/dsp/cpp-dsp-adapter.h +38 -0
- cyfaust/resources/architecture/faust/dsp/dsp-adapter.h +836 -0
- cyfaust/resources/architecture/faust/dsp/dsp-bench.h +611 -0
- cyfaust/resources/architecture/faust/dsp/dsp-checker.h +115 -0
- cyfaust/resources/architecture/faust/dsp/dsp-combiner.h +810 -0
- cyfaust/resources/architecture/faust/dsp/dsp-compute-adapter.h +159 -0
- cyfaust/resources/architecture/faust/dsp/dsp-multi.h +702 -0
- cyfaust/resources/architecture/faust/dsp/dsp-multifun.h +90 -0
- cyfaust/resources/architecture/faust/dsp/dsp-optimizer.h +511 -0
- cyfaust/resources/architecture/faust/dsp/dsp-tools.h +229 -0
- cyfaust/resources/architecture/faust/dsp/dsp.h +321 -0
- cyfaust/resources/architecture/faust/dsp/fastmath.cpp +301 -0
- cyfaust/resources/architecture/faust/dsp/faust-dynamic-engine.cpp +494 -0
- cyfaust/resources/architecture/faust/dsp/faust-dynamic-engine.h +386 -0
- cyfaust/resources/architecture/faust/dsp/faust-engine.h +75 -0
- cyfaust/resources/architecture/faust/dsp/faust-poly-engine.h +638 -0
- cyfaust/resources/architecture/faust/dsp/interpreter-dsp-c.h +288 -0
- cyfaust/resources/architecture/faust/dsp/interpreter-dsp.h +362 -0
- cyfaust/resources/architecture/faust/dsp/interpreter-machine-dsp.h +233 -0
- cyfaust/resources/architecture/faust/dsp/libfaust-box-c.h +817 -0
- cyfaust/resources/architecture/faust/dsp/libfaust-box.h +889 -0
- cyfaust/resources/architecture/faust/dsp/libfaust-c.h +116 -0
- cyfaust/resources/architecture/faust/dsp/libfaust-signal-c.h +649 -0
- cyfaust/resources/architecture/faust/dsp/libfaust-signal.h +731 -0
- cyfaust/resources/architecture/faust/dsp/llvm-dsp-adapter.h +160 -0
- cyfaust/resources/architecture/faust/dsp/llvm-dsp-c.h +524 -0
- cyfaust/resources/architecture/faust/dsp/llvm-dsp.h +575 -0
- cyfaust/resources/architecture/faust/dsp/llvm-machine-dsp.h +215 -0
- cyfaust/resources/architecture/faust/dsp/one-sample-dsp.h +477 -0
- cyfaust/resources/architecture/faust/dsp/poly-dsp.h +1079 -0
- cyfaust/resources/architecture/faust/dsp/poly-interpreter-dsp.h +143 -0
- cyfaust/resources/architecture/faust/dsp/poly-llvm-dsp.h +249 -0
- cyfaust/resources/architecture/faust/dsp/poly-wasm-dsp.h +257 -0
- cyfaust/resources/architecture/faust/dsp/proxy-dsp.h +108 -0
- cyfaust/resources/architecture/faust/dsp/proxy-osc-dsp.h +109 -0
- cyfaust/resources/architecture/faust/dsp/rnbo-dsp.h +187 -0
- cyfaust/resources/architecture/faust/dsp/sound-player.h +428 -0
- cyfaust/resources/architecture/faust/dsp/timed-dsp.h +279 -0
- cyfaust/resources/architecture/faust/dsp/wasm-dsp-imp.h +188 -0
- cyfaust/resources/architecture/faust/dsp/wasm-dsp.h +309 -0
- cyfaust/resources/architecture/faust/dsp/ysfx-dsp.h +188 -0
- cyfaust/resources/architecture/faust/export.h +61 -0
- cyfaust/resources/architecture/faust/gui/APIUI.h +726 -0
- cyfaust/resources/architecture/faust/gui/BelaOSCUI.h +170 -0
- cyfaust/resources/architecture/faust/gui/CGlue.h +667 -0
- cyfaust/resources/architecture/faust/gui/CInterface.h +142 -0
- cyfaust/resources/architecture/faust/gui/ControlSequenceUI.h +197 -0
- cyfaust/resources/architecture/faust/gui/ControlUI.h +137 -0
- cyfaust/resources/architecture/faust/gui/DaisyControlUI.h +283 -0
- cyfaust/resources/architecture/faust/gui/DaisyPatchInitControlUI.h +254 -0
- cyfaust/resources/architecture/faust/gui/DecoratorUI.h +115 -0
- cyfaust/resources/architecture/faust/gui/Esp32ControlUI.h +341 -0
- cyfaust/resources/architecture/faust/gui/Esp32Reader.h +102 -0
- cyfaust/resources/architecture/faust/gui/Esp32SensorUI.h +137 -0
- cyfaust/resources/architecture/faust/gui/FUI.h +147 -0
- cyfaust/resources/architecture/faust/gui/GTKUI.h +1414 -0
- cyfaust/resources/architecture/faust/gui/GUI.h +465 -0
- cyfaust/resources/architecture/faust/gui/JSONControl.h +48 -0
- cyfaust/resources/architecture/faust/gui/JSONUI.h +722 -0
- cyfaust/resources/architecture/faust/gui/JSONUIDecoder.h +589 -0
- cyfaust/resources/architecture/faust/gui/JuceGUI.h +2061 -0
- cyfaust/resources/architecture/faust/gui/JuceOSCUI.h +163 -0
- cyfaust/resources/architecture/faust/gui/JuceParameterUI.h +158 -0
- cyfaust/resources/architecture/faust/gui/JuceReader.h +103 -0
- cyfaust/resources/architecture/faust/gui/JuceStateUI.h +88 -0
- cyfaust/resources/architecture/faust/gui/LayoutUI.h +423 -0
- cyfaust/resources/architecture/faust/gui/LibsndfileReader.h +366 -0
- cyfaust/resources/architecture/faust/gui/MapUI.h +370 -0
- cyfaust/resources/architecture/faust/gui/MemoryReader.h +111 -0
- cyfaust/resources/architecture/faust/gui/MetaDataUI.h +357 -0
- cyfaust/resources/architecture/faust/gui/MidiUI.h +939 -0
- cyfaust/resources/architecture/faust/gui/OCVUI.h +688 -0
- cyfaust/resources/architecture/faust/gui/OSCUI.h +219 -0
- cyfaust/resources/architecture/faust/gui/PathBuilder.h +228 -0
- cyfaust/resources/architecture/faust/gui/PresetUI.h +337 -0
- cyfaust/resources/architecture/faust/gui/PrintCUI.h +152 -0
- cyfaust/resources/architecture/faust/gui/PrintUI.h +121 -0
- cyfaust/resources/architecture/faust/gui/QTUI.h +1891 -0
- cyfaust/resources/architecture/faust/gui/RosCI.h +493 -0
- cyfaust/resources/architecture/faust/gui/RosUI.h +488 -0
- cyfaust/resources/architecture/faust/gui/SaveUI.h +163 -0
- cyfaust/resources/architecture/faust/gui/SimpleParser.h +583 -0
- cyfaust/resources/architecture/faust/gui/SoundUI.h +217 -0
- cyfaust/resources/architecture/faust/gui/Soundfile.h +342 -0
- cyfaust/resources/architecture/faust/gui/Styles/Blue.qrc +5 -0
- cyfaust/resources/architecture/faust/gui/Styles/Blue.qss +177 -0
- cyfaust/resources/architecture/faust/gui/Styles/Default.qrc +5 -0
- cyfaust/resources/architecture/faust/gui/Styles/Default.qss +117 -0
- cyfaust/resources/architecture/faust/gui/Styles/Grey.qrc +5 -0
- cyfaust/resources/architecture/faust/gui/Styles/Grey.qss +174 -0
- cyfaust/resources/architecture/faust/gui/Styles/Salmon.qrc +5 -0
- cyfaust/resources/architecture/faust/gui/Styles/Salmon.qss +171 -0
- cyfaust/resources/architecture/faust/gui/UI.h +87 -0
- cyfaust/resources/architecture/faust/gui/ValueConverter.h +543 -0
- cyfaust/resources/architecture/faust/gui/WaveReader.h +364 -0
- cyfaust/resources/architecture/faust/gui/console.h +322 -0
- cyfaust/resources/architecture/faust/gui/httpdUI.h +372 -0
- cyfaust/resources/architecture/faust/gui/meta.h +39 -0
- cyfaust/resources/architecture/faust/gui/mspUI.h +580 -0
- cyfaust/resources/architecture/faust/gui/qrcodegen.h +269 -0
- cyfaust/resources/architecture/faust/gui/qrcodegen.impl.h +1025 -0
- cyfaust/resources/architecture/faust/gui/ring-buffer.h +414 -0
- cyfaust/resources/architecture/faust/midi/RtMidi.cpp +3054 -0
- cyfaust/resources/architecture/faust/midi/RtMidi.h +1034 -0
- cyfaust/resources/architecture/faust/midi/bela-midi.h +266 -0
- cyfaust/resources/architecture/faust/midi/daisy-midi.h +116 -0
- cyfaust/resources/architecture/faust/midi/esp32-midi.h +185 -0
- cyfaust/resources/architecture/faust/midi/gramophone-midi.h +107 -0
- cyfaust/resources/architecture/faust/midi/iplug2-midi.h +148 -0
- cyfaust/resources/architecture/faust/midi/jack-midi.h +247 -0
- cyfaust/resources/architecture/faust/midi/juce-midi.h +275 -0
- cyfaust/resources/architecture/faust/midi/midi.h +475 -0
- cyfaust/resources/architecture/faust/midi/rt-midi.h +315 -0
- cyfaust/resources/architecture/faust/midi/teensy-midi.h +89 -0
- cyfaust/resources/architecture/faust/misc.h +106 -0
- cyfaust/resources/architecture/faust/sound-file.h +132 -0
- cyfaust/resources/architecture/faust/unity/AudioPluginInterface.h +301 -0
- cyfaust/resources/architecture/faust/vst/faust.h +141 -0
- cyfaust/resources/architecture/faust/vst/voice.h +43 -0
- cyfaust/resources/architecture/faust/vst/vstui.h +524 -0
- cyfaust/resources/architecture/faustvst.cpp +3435 -0
- cyfaust/resources/architecture/faustvstqt.h +91 -0
- cyfaust/resources/architecture/gen-json.cpp +76 -0
- cyfaust/resources/architecture/jack-console.cpp +267 -0
- cyfaust/resources/architecture/jack-gtk-ros.cpp +139 -0
- cyfaust/resources/architecture/jack-gtk.cpp +282 -0
- cyfaust/resources/architecture/jack-internal.cpp +560 -0
- cyfaust/resources/architecture/jack-qt-chain-footer.cpp +87 -0
- cyfaust/resources/architecture/jack-qt-chain-header.cpp +92 -0
- cyfaust/resources/architecture/jack-qt.cpp +281 -0
- cyfaust/resources/architecture/jack.rs +171 -0
- cyfaust/resources/architecture/juce/README.md +84 -0
- cyfaust/resources/architecture/juce/juce-plugin.cpp +809 -0
- cyfaust/resources/architecture/juce/juce-standalone.cpp +413 -0
- cyfaust/resources/architecture/juce/plugin/plugin-llvm.jucer +184 -0
- cyfaust/resources/architecture/juce/plugin/plugin.jucer +159 -0
- cyfaust/resources/architecture/juce/standalone/standalone-llvm.jucer +216 -0
- cyfaust/resources/architecture/juce/standalone/standalone.jucer +191 -0
- cyfaust/resources/architecture/ladspa.cpp +543 -0
- cyfaust/resources/architecture/latexheader.tex +65 -0
- cyfaust/resources/architecture/lv2.cpp +2090 -0
- cyfaust/resources/architecture/lv2qtgui.h +62 -0
- cyfaust/resources/architecture/lv2ui.cpp +1966 -0
- cyfaust/resources/architecture/max-msp/README.md +109 -0
- cyfaust/resources/architecture/max-msp/faustgen-wrapper-poly.maxpat +184 -0
- cyfaust/resources/architecture/max-msp/faustgen-wrapper.maxpat +163 -0
- cyfaust/resources/architecture/max-msp/max-msp.cpp +734 -0
- cyfaust/resources/architecture/max-msp/max-msp64.cpp +789 -0
- cyfaust/resources/architecture/max-msp/py2max/README.md +277 -0
- cyfaust/resources/architecture/max-msp/py2max/py2max/__init__.py +3 -0
- cyfaust/resources/architecture/max-msp/py2max/py2max/common.py +7 -0
- cyfaust/resources/architecture/max-msp/py2max/py2max/core.py +1387 -0
- cyfaust/resources/architecture/max-msp/py2max/py2max/maxclassdb.py +318 -0
- cyfaust/resources/architecture/max-msp/py2max/py2max/utils.py +20 -0
- cyfaust/resources/architecture/max-msp/rnbo.py +1591 -0
- cyfaust/resources/architecture/max-msp/sndfile/sndfile.h +857 -0
- cyfaust/resources/architecture/max-msp/ui.js +230 -0
- cyfaust/resources/architecture/max-msp/wrapper-poly.maxpat +153 -0
- cyfaust/resources/architecture/max-msp/wrapper.maxpat +131 -0
- cyfaust/resources/architecture/minimal-bench.cpp +100 -0
- cyfaust/resources/architecture/minimal-effect.c +149 -0
- cyfaust/resources/architecture/minimal-effect.cpp +70 -0
- cyfaust/resources/architecture/minimal-fixed-point.cpp +195 -0
- cyfaust/resources/architecture/minimal-static.cpp +160 -0
- cyfaust/resources/architecture/minimal.c +103 -0
- cyfaust/resources/architecture/minimal.cpp +84 -0
- cyfaust/resources/architecture/minimal.rs +223 -0
- cyfaust/resources/architecture/module.cpp +91 -0
- cyfaust/resources/architecture/octave.cpp +471 -0
- cyfaust/resources/architecture/oscio-gtk.cpp +115 -0
- cyfaust/resources/architecture/oscio-qt.cpp +121 -0
- cyfaust/resources/architecture/owl.cpp +345 -0
- cyfaust/resources/architecture/pa-gtk.cpp +119 -0
- cyfaust/resources/architecture/pa-qt.cpp +261 -0
- cyfaust/resources/architecture/path-printer.cpp +100 -0
- cyfaust/resources/architecture/plot.cpp +128 -0
- cyfaust/resources/architecture/portaudio.rs +192 -0
- cyfaust/resources/architecture/puredata.cpp +636 -0
- cyfaust/resources/architecture/ra-qt.cpp +238 -0
- cyfaust/resources/architecture/sam/fast_pow2.h +69 -0
- cyfaust/resources/architecture/sam/fastexp.h +140 -0
- cyfaust/resources/architecture/sam/samFaustDSP.cpp +125 -0
- cyfaust/resources/architecture/sam/samFaustDSP.h +107 -0
- cyfaust/resources/architecture/scheduler.cpp +1391 -0
- cyfaust/resources/architecture/sndfile.cpp +291 -0
- cyfaust/resources/architecture/supercollider.cpp +611 -0
- cyfaust/resources/architecture/teensy/README.md +13 -0
- cyfaust/resources/architecture/teensy/teensy.cpp +214 -0
- cyfaust/resources/architecture/teensy/teensy.h +71 -0
- cyfaust/resources/architecture/thread.h +373 -0
- cyfaust/resources/architecture/vcvrack/README.md +78 -0
- cyfaust/resources/architecture/vcvrack/template/.gitignore +6 -0
- cyfaust/resources/architecture/vcvrack/template/Makefile +22 -0
- cyfaust/resources/architecture/vcvrack/template/res/FaustModule.svg +299 -0
- cyfaust/resources/architecture/vcvrack/template/src/FaustModule.cpp +942 -0
- cyfaust/resources/architecture/vst.cpp +947 -0
- cyfaust/resources/libraries/aanl.lib +900 -0
- cyfaust/resources/libraries/all.lib +36 -0
- cyfaust/resources/libraries/analyzers.lib +980 -0
- cyfaust/resources/libraries/basics.lib +2681 -0
- cyfaust/resources/libraries/compressors.lib +1341 -0
- cyfaust/resources/libraries/delays.lib +401 -0
- cyfaust/resources/libraries/demos.lib +1556 -0
- cyfaust/resources/libraries/dx7.lib +1036 -0
- cyfaust/resources/libraries/effect.lib +1645 -0
- cyfaust/resources/libraries/envelopes.lib +666 -0
- cyfaust/resources/libraries/examples/README.md +13 -0
- cyfaust/resources/libraries/examples/ambisonics/fourSourcesToOcto.dsp +20 -0
- cyfaust/resources/libraries/examples/ambisonics/oneSourceToStereo.dsp +12 -0
- cyfaust/resources/libraries/examples/analysis/FFT.dsp +26 -0
- cyfaust/resources/libraries/examples/analysis/dbmeter.dsp +19 -0
- cyfaust/resources/libraries/examples/analysis/spectralLevel.dsp +8 -0
- cyfaust/resources/libraries/examples/analysis/spectralTiltLab.dsp +20 -0
- cyfaust/resources/libraries/examples/analysis/vumeter.dsp +18 -0
- cyfaust/resources/libraries/examples/autodiff/delay/diff.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/delay/gt.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/gain/diff.dsp +7 -0
- cyfaust/resources/libraries/examples/autodiff/gain/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/gain_dc/diff.dsp +7 -0
- cyfaust/resources/libraries/examples/autodiff/gain_dc/gt.dsp +4 -0
- cyfaust/resources/libraries/examples/autodiff/gain_exp/diff.dsp +9 -0
- cyfaust/resources/libraries/examples/autodiff/gain_exp/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/gain_pow/diff.dsp +9 -0
- cyfaust/resources/libraries/examples/autodiff/gain_pow/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/gain_pow_trig/diff.dsp +12 -0
- cyfaust/resources/libraries/examples/autodiff/gain_pow_trig/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/gain_sq/diff.dsp +7 -0
- cyfaust/resources/libraries/examples/autodiff/gain_sq/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/mem/diff.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/mem/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/noise.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/noop.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/one_zero/diff.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/one_zero/gt.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/ramp.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/recursion/diff.dsp +2 -0
- cyfaust/resources/libraries/examples/autodiff/recursion/gt.dsp +1 -0
- cyfaust/resources/libraries/examples/autodiff/recursion/target.dsp +13 -0
- cyfaust/resources/libraries/examples/autodiff/tremolo/diff.dsp +14 -0
- cyfaust/resources/libraries/examples/autodiff/tremolo/diffable.lib +7 -0
- cyfaust/resources/libraries/examples/autodiff/tremolo/gt.dsp +11 -0
- cyfaust/resources/libraries/examples/delayEcho/echo.dsp +15 -0
- cyfaust/resources/libraries/examples/delayEcho/quadEcho.dsp +21 -0
- cyfaust/resources/libraries/examples/delayEcho/smoothDelay.dsp +26 -0
- cyfaust/resources/libraries/examples/delayEcho/stereoEcho.dsp +16 -0
- cyfaust/resources/libraries/examples/delayEcho/tapiir.dsp +44 -0
- cyfaust/resources/libraries/examples/dynamic/compressor.dsp +8 -0
- cyfaust/resources/libraries/examples/dynamic/distortion.dsp +8 -0
- cyfaust/resources/libraries/examples/dynamic/gateCompressor.dsp +10 -0
- cyfaust/resources/libraries/examples/dynamic/noiseGate.dsp +8 -0
- cyfaust/resources/libraries/examples/dynamic/volume.dsp +15 -0
- cyfaust/resources/libraries/examples/filtering/APF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/BPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/DNN.dsp +25 -0
- cyfaust/resources/libraries/examples/filtering/HPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/LPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/bandFilter.dsp +44 -0
- cyfaust/resources/libraries/examples/filtering/cryBaby.dsp +4 -0
- cyfaust/resources/libraries/examples/filtering/diodeLadder.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/filterBank.dsp +6 -0
- cyfaust/resources/libraries/examples/filtering/graphicEqLab.dsp +10 -0
- cyfaust/resources/libraries/examples/filtering/highShelf.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/korg35HPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/korg35LPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/lfBoost.dsp +40 -0
- cyfaust/resources/libraries/examples/filtering/lowBoost.dsp +40 -0
- cyfaust/resources/libraries/examples/filtering/lowCut.dsp +40 -0
- cyfaust/resources/libraries/examples/filtering/lowShelf.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/moogHalfLadder.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/moogLadder.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/moogVCF.dsp +6 -0
- cyfaust/resources/libraries/examples/filtering/multibandFilter.dsp +14 -0
- cyfaust/resources/libraries/examples/filtering/notch.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/oberheim.dsp +14 -0
- cyfaust/resources/libraries/examples/filtering/oberheimBPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/oberheimBSF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/oberheimHPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/oberheimLPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/parametricEqLab.dsp +10 -0
- cyfaust/resources/libraries/examples/filtering/parametricEqualizer.dsp +6 -0
- cyfaust/resources/libraries/examples/filtering/peakNotch.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/peakingEQ.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrder.dsp +14 -0
- cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderBPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderHPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/sallenKey2ndOrderLPF.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/sallenKeyOnePole.dsp +13 -0
- cyfaust/resources/libraries/examples/filtering/sallenKeyOnePoleHPF.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/sallenKeyOnePoleLPF.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/spectralTilt.dsp +8 -0
- cyfaust/resources/libraries/examples/filtering/vcfWahLab.dsp +12 -0
- cyfaust/resources/libraries/examples/filtering/vocoder.dsp +8 -0
- cyfaust/resources/libraries/examples/filtering/wahPedal.dsp +6 -0
- cyfaust/resources/libraries/examples/gameaudio/bubble.dsp +42 -0
- cyfaust/resources/libraries/examples/gameaudio/door.dsp +58 -0
- cyfaust/resources/libraries/examples/gameaudio/fire.dsp +46 -0
- cyfaust/resources/libraries/examples/gameaudio/insects.dsp +148 -0
- cyfaust/resources/libraries/examples/gameaudio/rain.dsp +27 -0
- cyfaust/resources/libraries/examples/gameaudio/wind.dsp +23 -0
- cyfaust/resources/libraries/examples/generator/filterOsc.dsp +8 -0
- cyfaust/resources/libraries/examples/generator/noise.dsp +52 -0
- cyfaust/resources/libraries/examples/generator/noiseMetadata.dsp +74 -0
- cyfaust/resources/libraries/examples/generator/osc.dsp +17 -0
- cyfaust/resources/libraries/examples/generator/osci.dsp +17 -0
- cyfaust/resources/libraries/examples/generator/sawtoothLab.dsp +8 -0
- cyfaust/resources/libraries/examples/generator/virtualAnalog.dsp +8 -0
- cyfaust/resources/libraries/examples/generator/virtualAnalogLab.dsp +10 -0
- cyfaust/resources/libraries/examples/misc/UITester.dsp +71 -0
- cyfaust/resources/libraries/examples/misc/autopan.dsp +59 -0
- cyfaust/resources/libraries/examples/misc/capture.dsp +24 -0
- cyfaust/resources/libraries/examples/misc/drumkit.dsp +36 -0
- cyfaust/resources/libraries/examples/misc/guitarix.dsp +184 -0
- cyfaust/resources/libraries/examples/misc/matrix.dsp +17 -0
- cyfaust/resources/libraries/examples/misc/midiTester.dsp +122 -0
- cyfaust/resources/libraries/examples/misc/mixer.dsp +27 -0
- cyfaust/resources/libraries/examples/misc/statespace.dsp +39 -0
- cyfaust/resources/libraries/examples/misc/switcher.dsp +20 -0
- cyfaust/resources/libraries/examples/misc/tester.dsp +32 -0
- cyfaust/resources/libraries/examples/misc/tester2.dsp +31 -0
- cyfaust/resources/libraries/examples/old/README.md +5 -0
- cyfaust/resources/libraries/examples/old/freeverb.dsp +109 -0
- cyfaust/resources/libraries/examples/old/rewriting/Makefile +21 -0
- cyfaust/resources/libraries/examples/old/rewriting/fact.dsp +3 -0
- cyfaust/resources/libraries/examples/old/rewriting/fold.dsp +61 -0
- cyfaust/resources/libraries/examples/old/rewriting/mesh.dsp +43 -0
- cyfaust/resources/libraries/examples/old/rewriting/mesh.pd +37 -0
- cyfaust/resources/libraries/examples/old/rewriting/sample.pd +12 -0
- cyfaust/resources/libraries/examples/old/rewriting/serial.dsp +7 -0
- cyfaust/resources/libraries/examples/old/rewriting/sum.dsp +55 -0
- cyfaust/resources/libraries/examples/old/rewriting/test.pd +48 -0
- cyfaust/resources/libraries/examples/phasing/flanger.dsp +8 -0
- cyfaust/resources/libraries/examples/phasing/phaser.dsp +8 -0
- cyfaust/resources/libraries/examples/phasing/phaserFlangerLab.dsp +12 -0
- cyfaust/resources/libraries/examples/physicalModeling/brass.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/brassMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/churchBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/clarinet.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/clarinetMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/djembeMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/elecGuitarMIDI.dsp +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/englishBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/NLFeks.dsp +91 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/NLFfm.dsp +70 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/README +125 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bass.dsp +84 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bass.h +91 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/blowBottle.dsp +102 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/bowed.dsp +114 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/brass.dsp +103 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/clarinet.dsp +110 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/flute.dsp +116 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/fluteStk.dsp +121 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/glassHarmonica.dsp +131 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/harpsi.dsp +90 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/harpsichord.h +185 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/instrument.h +114 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/modalBar.dsp +122 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/modalBar.h +48 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/bottle.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/clarinets.pd +15 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/bass.pd +162 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/canon.pd +55 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/flute.pd +343 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/canon/pachelbel.mid +0 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/daisy.mid +0 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/daisy.pd +45 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/piano.pd +205 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/daisy/voiceForm.pd +340 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/blowHole.pd +330 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/piano.pd +205 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/take5.mid +0 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/take5/take5.pd +45 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/harpsi.pd +204 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/turkish-march.mid +0 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/turkish-march/turkish-march.pd +31 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/audio-out.pd +33 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/bass.pd +162 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/modalBar.pd +258 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/piano.pd +205 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/what-a-friend.pd +52 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fancy/what-a-friend/what_a_friend.mid +0 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/flutes.pd +15 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/fm.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/glassBare.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/harpsichord-poly.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/ironBare.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/midi-in.pd +111 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/modal.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/osc.pd +26 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/piano-poly.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/plucked.pd +20 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/saxophone.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/tibetan.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/trumpet.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/violin.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/voiceSynth.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/pd-patches/woodenBare.pd +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/phonemes.h +189 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/piano.dsp +255 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/piano.h +751 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/saxophony.dsp +114 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/sitar.dsp +48 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/tibetanBowl.dsp +155 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/tunedBar.dsp +123 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/uniBar.dsp +100 -0
- cyfaust/resources/libraries/examples/physicalModeling/faust-stk/voiceForm.dsp +125 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/1dDampedWaveEquation.dsp +43 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/2dKirchhoffThinPlate.dsp +75 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/BowedString.dsp +61 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/ControllableNonPhysicalString.dsp +72 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/HammeredString.dsp +74 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/PianoHammeredString.dsp +85 -0
- cyfaust/resources/libraries/examples/physicalModeling/fds/StiffString.dsp +54 -0
- cyfaust/resources/libraries/examples/physicalModeling/flute.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/fluteMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/frenchBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/germanBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/guitarMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/karplus.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/marimbaMIDI.dsp +10 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator.dsp +58 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator2.dsp +62 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/00_BasicOscillator/harmonicOscillator3.dsp +65 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/01_ParamControl/paramOsc.dsp +63 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/02_AudioParamControl/audioParamOsc.dsp +63 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/03_HammerTime/hammerOsc.dsp +71 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/04_Gravity/bouncingOsc.dsp +64 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/05_PluckedOscillator/pluckedOsc.dsp +57 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/06_BowedOscillator/bowedOsc.dsp +65 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/07_NonLinearOscillator/nlOsc.dsp +78 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/08_TwoMassChain/2massChain.dsp +75 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/09_TinyString/tinyString.dsp +101 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/10_PluckedString/pluckedString.dsp +678 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/11_BowedString/bowedString.dsp +671 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/12_TriangleMesh/triangleMesh.dsp +448 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/13_Construction/construction.dsp +1036 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/14_Polyphonic/polyTriangle.dsp +79 -0
- cyfaust/resources/libraries/examples/physicalModeling/mi-faust/15_PhysicalLFO/physicalLFO.dsp +107 -0
- cyfaust/resources/libraries/examples/physicalModeling/modularInterpInstrMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/nylonGuitarMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/old/harpe.dsp +45 -0
- cyfaust/resources/libraries/examples/physicalModeling/old/karplus.dsp +34 -0
- cyfaust/resources/libraries/examples/physicalModeling/old/karplus32.dsp +47 -0
- cyfaust/resources/libraries/examples/physicalModeling/russianBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/standardBell.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/violin.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/violinMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/vocalBP.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/vocalBPMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/vocalFOF.dsp +8 -0
- cyfaust/resources/libraries/examples/physicalModeling/vocalFOFMIDI.dsp +8 -0
- cyfaust/resources/libraries/examples/pitchShifting/pitchShifter.dsp +20 -0
- cyfaust/resources/libraries/examples/psychoacoustic/harmonicExciter.dsp +10 -0
- cyfaust/resources/libraries/examples/quantizing/quantizedChords.dsp +49 -0
- cyfaust/resources/libraries/examples/reverb/dattorro.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/fdnRev.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/freeverb.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/greyhole.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/jprev.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/reverbDesigner.dsp +12 -0
- cyfaust/resources/libraries/examples/reverb/reverbTester.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/zitaRev.dsp +8 -0
- cyfaust/resources/libraries/examples/reverb/zitaRevFDN.dsp +8 -0
- cyfaust/resources/libraries/examples/smartKeyboard/acGuitar.dsp +100 -0
- cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/elecGuitarEffect.dsp +8 -0
- cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/myEffect.dsp +5 -0
- cyfaust/resources/libraries/examples/smartKeyboard/associatedEffects/reverb.dsp +5 -0
- cyfaust/resources/libraries/examples/smartKeyboard/bells.dsp +80 -0
- cyfaust/resources/libraries/examples/smartKeyboard/bowed.dsp +87 -0
- cyfaust/resources/libraries/examples/smartKeyboard/brass.dsp +82 -0
- cyfaust/resources/libraries/examples/smartKeyboard/clarinet.dsp +113 -0
- cyfaust/resources/libraries/examples/smartKeyboard/crazyGuiro.dsp +96 -0
- cyfaust/resources/libraries/examples/smartKeyboard/drums.dsp +74 -0
- cyfaust/resources/libraries/examples/smartKeyboard/dubDub.dsp +87 -0
- cyfaust/resources/libraries/examples/smartKeyboard/elecGuitar.dsp +67 -0
- cyfaust/resources/libraries/examples/smartKeyboard/fm.dsp +78 -0
- cyfaust/resources/libraries/examples/smartKeyboard/frog.dsp +74 -0
- cyfaust/resources/libraries/examples/smartKeyboard/harp.dsp +84 -0
- cyfaust/resources/libraries/examples/smartKeyboard/midiOnly.dsp +62 -0
- cyfaust/resources/libraries/examples/smartKeyboard/multiSynth.dsp +75 -0
- cyfaust/resources/libraries/examples/smartKeyboard/toy.dsp +71 -0
- cyfaust/resources/libraries/examples/smartKeyboard/trumpet.dsp +59 -0
- cyfaust/resources/libraries/examples/smartKeyboard/turenas.dsp +114 -0
- cyfaust/resources/libraries/examples/smartKeyboard/violin.dsp +91 -0
- cyfaust/resources/libraries/examples/smartKeyboard/violin2.dsp +84 -0
- cyfaust/resources/libraries/examples/smartKeyboard/vocal.dsp +43 -0
- cyfaust/resources/libraries/examples/spat/panpot.dsp +17 -0
- cyfaust/resources/libraries/examples/spat/spat.dsp +25 -0
- cyfaust/resources/libraries/fds.lib +535 -0
- cyfaust/resources/libraries/filter.lib +1710 -0
- cyfaust/resources/libraries/filters.lib +3125 -0
- cyfaust/resources/libraries/hoa.lib +1081 -0
- cyfaust/resources/libraries/instruments.lib +263 -0
- cyfaust/resources/libraries/interpolators.lib +675 -0
- cyfaust/resources/libraries/math.lib +602 -0
- cyfaust/resources/libraries/maths.lib +798 -0
- cyfaust/resources/libraries/maxmsp.lib +237 -0
- cyfaust/resources/libraries/mi.lib +528 -0
- cyfaust/resources/libraries/misceffects.lib +998 -0
- cyfaust/resources/libraries/music.lib +496 -0
- cyfaust/resources/libraries/noises.lib +487 -0
- cyfaust/resources/libraries/oscillator.lib +450 -0
- cyfaust/resources/libraries/oscillators.lib +1838 -0
- cyfaust/resources/libraries/phaflangers.lib +235 -0
- cyfaust/resources/libraries/physmodels.lib +3990 -0
- cyfaust/resources/libraries/platform.lib +59 -0
- cyfaust/resources/libraries/quantizers.lib +310 -0
- cyfaust/resources/libraries/reducemaps.lib +235 -0
- cyfaust/resources/libraries/reverbs.lib +686 -0
- cyfaust/resources/libraries/routes.lib +262 -0
- cyfaust/resources/libraries/sf.lib +53 -0
- cyfaust/resources/libraries/signals.lib +570 -0
- cyfaust/resources/libraries/soundfiles.lib +234 -0
- cyfaust/resources/libraries/spats.lib +173 -0
- cyfaust/resources/libraries/stdfaust.lib +38 -0
- cyfaust/resources/libraries/synths.lib +322 -0
- cyfaust/resources/libraries/tonestacks.lib +427 -0
- cyfaust/resources/libraries/tubes.lib +5039 -0
- cyfaust/resources/libraries/vaeffects.lib +984 -0
- cyfaust/resources/libraries/version.lib +22 -0
- cyfaust/resources/libraries/wdmodels.lib +2276 -0
- cyfaust/resources/libraries/webaudio.lib +402 -0
- cyfaust/signal.pxd +44 -0
- cyfaust/signal.pyx +1993 -0
- cyfaust-0.1.0.dist-info/METADATA +355 -0
- cyfaust-0.1.0.dist-info/RECORD +693 -0
- cyfaust-0.1.0.dist-info/WHEEL +5 -0
- cyfaust-0.1.0.dist-info/entry_points.txt +3 -0
- cyfaust-0.1.0.dist-info/licenses/LICENSE +26 -0
|
@@ -0,0 +1,2681 @@
|
|
|
1
|
+
//#################################### basics.lib ########################################
|
|
2
|
+
// A library of basic elements. Its official prefix is `ba`.
|
|
3
|
+
//
|
|
4
|
+
// #### References
|
|
5
|
+
// * <https://github.com/grame-cncm/faustlibraries/blob/master/basics.lib>
|
|
6
|
+
//########################################################################################
|
|
7
|
+
// A library of basic elements for Faust organized in 5 sections:
|
|
8
|
+
//
|
|
9
|
+
// * Conversion Tools
|
|
10
|
+
// * Counters and Time/Tempo Tools
|
|
11
|
+
// * Array Processing/Pattern Matching
|
|
12
|
+
// * Selectors (Conditions)
|
|
13
|
+
// * Other Tools (Misc)
|
|
14
|
+
|
|
15
|
+
//########################################################################################
|
|
16
|
+
|
|
17
|
+
/************************************************************************
|
|
18
|
+
************************************************************************
|
|
19
|
+
FAUST library file, GRAME section
|
|
20
|
+
|
|
21
|
+
Except where noted otherwise, Copyright (C) 2003-2017 by GRAME,
|
|
22
|
+
Centre National de Creation Musicale.
|
|
23
|
+
----------------------------------------------------------------------
|
|
24
|
+
GRAME LICENSE
|
|
25
|
+
|
|
26
|
+
This program is free software; you can redistribute it and/or modify
|
|
27
|
+
it under the terms of the GNU Lesser General Public License as
|
|
28
|
+
published by the Free Software Foundation; either version 2.1 of the
|
|
29
|
+
License, or (at your option) any later version.
|
|
30
|
+
|
|
31
|
+
This program is distributed in the hope that it will be useful,
|
|
32
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
33
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
34
|
+
GNU Lesser General Public License for more details.
|
|
35
|
+
|
|
36
|
+
You should have received a copy of the GNU Lesser General Public
|
|
37
|
+
License along with the GNU C Library; if not, write to the Free
|
|
38
|
+
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
39
|
+
02111-1307 USA.
|
|
40
|
+
|
|
41
|
+
EXCEPTION TO THE LGPL LICENSE : As a special exception, you may create a
|
|
42
|
+
larger FAUST program which directly or indirectly imports this library
|
|
43
|
+
file and still distribute the compiled code generated by the FAUST
|
|
44
|
+
compiler, or a modified version of this compiled code, under your own
|
|
45
|
+
copyright and license. This EXCEPTION TO THE LGPL LICENSE explicitly
|
|
46
|
+
grants you the right to freely choose the license for the resulting
|
|
47
|
+
compiled code. In particular the resulting compiled code has no obligation
|
|
48
|
+
to be LGPL or GPL. For example you are free to choose a commercial or
|
|
49
|
+
closed source license or any other license if you decide so.
|
|
50
|
+
************************************************************************
|
|
51
|
+
************************************************************************/
|
|
52
|
+
|
|
53
|
+
ma = library("maths.lib");
|
|
54
|
+
ro = library("routes.lib");
|
|
55
|
+
ba = library("basics.lib"); // for compatible copy/paste out of this file
|
|
56
|
+
fi = library("filters.lib");
|
|
57
|
+
it = library("interpolators.lib");
|
|
58
|
+
si = library("signals.lib");
|
|
59
|
+
|
|
60
|
+
declare name "Faust Basic Element Library";
|
|
61
|
+
declare version "1.11.1";
|
|
62
|
+
|
|
63
|
+
//=============================Conversion Tools===========================================
|
|
64
|
+
//========================================================================================
|
|
65
|
+
|
|
66
|
+
//-------`(ba.)samp2sec`----------
|
|
67
|
+
// Converts a number of samples to a duration in seconds at the current sampling rate (see `ma.SR`).
|
|
68
|
+
// `samp2sec` is a standard Faust function.
|
|
69
|
+
//
|
|
70
|
+
// #### Usage
|
|
71
|
+
//
|
|
72
|
+
// ```
|
|
73
|
+
// samp2sec(n) : _
|
|
74
|
+
// ```
|
|
75
|
+
//
|
|
76
|
+
// Where:
|
|
77
|
+
//
|
|
78
|
+
// * `n`: number of samples
|
|
79
|
+
//----------------------------
|
|
80
|
+
samp2sec(n) = n/ma.SR;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
//-------`(ba.)sec2samp`----------
|
|
84
|
+
// Converts a duration in seconds to a number of samples at the current sampling rate (see `ma.SR`).
|
|
85
|
+
// `samp2sec` is a standard Faust function.
|
|
86
|
+
//
|
|
87
|
+
// #### Usage
|
|
88
|
+
//
|
|
89
|
+
// ```
|
|
90
|
+
// sec2samp(d) : _
|
|
91
|
+
// ```
|
|
92
|
+
//
|
|
93
|
+
// Where:
|
|
94
|
+
//
|
|
95
|
+
// * `d`: duration in seconds
|
|
96
|
+
//----------------------------
|
|
97
|
+
sec2samp(d) = d*ma.SR;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
//-------`(ba.)db2linear`----------
|
|
101
|
+
// dB-to-linear value converter. It can be used to convert an amplitude in dB to a linear gain ]0-N].
|
|
102
|
+
// `db2linear` is a standard Faust function.
|
|
103
|
+
//
|
|
104
|
+
// #### Usage
|
|
105
|
+
//
|
|
106
|
+
// ```
|
|
107
|
+
// db2linear(l) : _
|
|
108
|
+
// ```
|
|
109
|
+
//
|
|
110
|
+
// Where:
|
|
111
|
+
//
|
|
112
|
+
// * `l`: amplitude in dB
|
|
113
|
+
//-----------------------------
|
|
114
|
+
db2linear(l) = pow(10.0, l/20.0);
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
//-------`(ba.)linear2db`----------
|
|
118
|
+
// linea-to-dB value converter. It can be used to convert a linear gain ]0-N] to an amplitude in dB.
|
|
119
|
+
// `linear2db` is a standard Faust function.
|
|
120
|
+
//
|
|
121
|
+
// #### Usage
|
|
122
|
+
//
|
|
123
|
+
// ```
|
|
124
|
+
// linear2db(g) : _
|
|
125
|
+
// ```
|
|
126
|
+
//
|
|
127
|
+
// Where:
|
|
128
|
+
//
|
|
129
|
+
// * `g`: a linear gain
|
|
130
|
+
//-----------------------------
|
|
131
|
+
linear2db(g) = 20.0*log10(max(ma.MIN, g));
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
//----------`(ba.)lin2LogGain`------------------
|
|
135
|
+
// Converts a linear gain (0-1) to a log gain (0-1).
|
|
136
|
+
//
|
|
137
|
+
// #### Usage
|
|
138
|
+
//
|
|
139
|
+
// ```
|
|
140
|
+
// lin2LogGain(n) : _
|
|
141
|
+
// ```
|
|
142
|
+
//
|
|
143
|
+
// Where:
|
|
144
|
+
//
|
|
145
|
+
// * `n`: the linear gain
|
|
146
|
+
//---------------------------------------------
|
|
147
|
+
lin2LogGain(n) = n*n;
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
//----------`(ba.)log2LinGain`------------------
|
|
151
|
+
// Converts a log gain (0-1) to a linear gain (0-1).
|
|
152
|
+
//
|
|
153
|
+
// #### Usage
|
|
154
|
+
//
|
|
155
|
+
// ```
|
|
156
|
+
// log2LinGain(n) : _
|
|
157
|
+
// ```
|
|
158
|
+
//
|
|
159
|
+
// Where:
|
|
160
|
+
//
|
|
161
|
+
// * `n`: the log gain
|
|
162
|
+
//---------------------------------------------
|
|
163
|
+
log2LinGain(n) = sqrt(n);
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
// end GRAME section
|
|
167
|
+
//########################################################################################
|
|
168
|
+
/************************************************************************
|
|
169
|
+
FAUST library file, jos section
|
|
170
|
+
|
|
171
|
+
Except where noted otherwise, The Faust functions below in this
|
|
172
|
+
section are Copyright (C) 2003-2017 by Julius O. Smith III <jos@ccrma.stanford.edu>
|
|
173
|
+
([jos](http://ccrma.stanford.edu/~jos/)), and released under the
|
|
174
|
+
(MIT-style) [STK-4.3](#stk-4.3-license) license.
|
|
175
|
+
|
|
176
|
+
The MarkDown comments in this section are Copyright 2016-2017 by Romain
|
|
177
|
+
Michon and Julius O. Smith III, and are released under the
|
|
178
|
+
[CCA4I](https://creativecommons.org/licenses/by/4.0/) license (TODO: if/when Romain agrees)
|
|
179
|
+
|
|
180
|
+
************************************************************************/
|
|
181
|
+
|
|
182
|
+
//-------`(ba.)tau2pole`----------
|
|
183
|
+
// Returns a real pole giving exponential decay.
|
|
184
|
+
// Note that t60 (time to decay 60 dB) is ~6.91 time constants.
|
|
185
|
+
// `tau2pole` is a standard Faust function.
|
|
186
|
+
//
|
|
187
|
+
// #### Usage
|
|
188
|
+
//
|
|
189
|
+
// ```
|
|
190
|
+
// _ : smooth(tau2pole(tau)) : _
|
|
191
|
+
// ```
|
|
192
|
+
//
|
|
193
|
+
// Where:
|
|
194
|
+
//
|
|
195
|
+
// * `tau`: time-constant in seconds
|
|
196
|
+
//-----------------------------
|
|
197
|
+
// tau2pole(tau) = exp(-1.0/(tau*ma.SR));
|
|
198
|
+
|
|
199
|
+
tau2pole(tau) = ba.if(clipCond, 0.0, exp(-1.0/(tauCenterClipped*float(ma.SR))))
|
|
200
|
+
with {
|
|
201
|
+
clipCond = abs(tau)<ma.EPSILON;
|
|
202
|
+
tauCenterClipped = ba.if(clipCond, 1.0, tau); // 1.0 can be any nonzero value (not used)
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
//-------`(ba.)pole2tau`----------
|
|
207
|
+
// Returns the time-constant, in seconds, corresponding to the given real,
|
|
208
|
+
// positive pole in (0-1).
|
|
209
|
+
// `pole2tau` is a standard Faust function.
|
|
210
|
+
//
|
|
211
|
+
// #### Usage
|
|
212
|
+
//
|
|
213
|
+
// ```
|
|
214
|
+
// pole2tau(pole) : _
|
|
215
|
+
// ```
|
|
216
|
+
//
|
|
217
|
+
// Where:
|
|
218
|
+
//
|
|
219
|
+
// * `pole`: the pole
|
|
220
|
+
//-----------------------------
|
|
221
|
+
pole2tau(pole) = -1.0/(log(max(ma.MIN, pole))*ma.SR);
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
//-------`(ba.)midikey2hz`----------
|
|
225
|
+
// Converts a MIDI key number to a frequency in Hz (MIDI key 69 = A440).
|
|
226
|
+
// `midikey2hz` is a standard Faust function.
|
|
227
|
+
//
|
|
228
|
+
// #### Usage
|
|
229
|
+
//
|
|
230
|
+
// ```
|
|
231
|
+
// midikey2hz(mk) : _
|
|
232
|
+
// ```
|
|
233
|
+
//
|
|
234
|
+
// Where:
|
|
235
|
+
//
|
|
236
|
+
// * `mk`: the MIDI key number
|
|
237
|
+
//-----------------------------
|
|
238
|
+
midikey2hz(mk) = 440.0*pow(2.0, (mk-69.0)/12.0);
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
//-------`(ba.)hz2midikey`----------
|
|
242
|
+
// Converts a frequency in Hz to a MIDI key number (MIDI key 69 = A440).
|
|
243
|
+
// `hz2midikey` is a standard Faust function.
|
|
244
|
+
//
|
|
245
|
+
// #### Usage
|
|
246
|
+
//
|
|
247
|
+
// ```
|
|
248
|
+
// hz2midikey(freq) : _
|
|
249
|
+
// ```
|
|
250
|
+
//
|
|
251
|
+
// Where:
|
|
252
|
+
//
|
|
253
|
+
// * `freq`: frequency in Hz
|
|
254
|
+
//-----------------------------
|
|
255
|
+
hz2midikey(freq) = 12.0*ma.log2(freq/440.0) + 69.0;
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
//-------`(ba.)semi2ratio`----------
|
|
259
|
+
// Converts semitones in a frequency multiplicative ratio.
|
|
260
|
+
// `semi2ratio` is a standard Faust function.
|
|
261
|
+
//
|
|
262
|
+
// #### Usage
|
|
263
|
+
//
|
|
264
|
+
// ```
|
|
265
|
+
// semi2ratio(semi) : _
|
|
266
|
+
// ```
|
|
267
|
+
//
|
|
268
|
+
// Where:
|
|
269
|
+
//
|
|
270
|
+
// * `semi`: number of semitone
|
|
271
|
+
//-----------------------------
|
|
272
|
+
semi2ratio(semi) = pow(2.0, semi/12.0);
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
//-------`(ba.)ratio2semi`----------
|
|
276
|
+
// Converts a frequency multiplicative ratio in semitones.
|
|
277
|
+
// `ratio2semi` is a standard Faust function.
|
|
278
|
+
//
|
|
279
|
+
// #### Usage
|
|
280
|
+
//
|
|
281
|
+
// ```
|
|
282
|
+
// ratio2semi(ratio) : _
|
|
283
|
+
// ```
|
|
284
|
+
//
|
|
285
|
+
// Where:
|
|
286
|
+
//
|
|
287
|
+
// * `ratio`: frequency multiplicative ratio
|
|
288
|
+
//-----------------------------
|
|
289
|
+
ratio2semi(ratio) = 12.0*log(ratio)/log(2.0);
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
//-------`(ba.)cent2ratio`----------
|
|
293
|
+
// Converts cents in a frequency multiplicative ratio.
|
|
294
|
+
//
|
|
295
|
+
// #### Usage
|
|
296
|
+
//
|
|
297
|
+
// ```
|
|
298
|
+
// cent2ratio(cent) : _
|
|
299
|
+
// ```
|
|
300
|
+
//
|
|
301
|
+
// Where:
|
|
302
|
+
//
|
|
303
|
+
// * `cent`: number of cents
|
|
304
|
+
//-----------------------------
|
|
305
|
+
cent2ratio(cent) = pow(2.0, cent/1200.0);
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
//-------`(ba.)ratio2cent`----------
|
|
309
|
+
// Converts a frequency multiplicative ratio in cents.
|
|
310
|
+
//
|
|
311
|
+
// #### Usage
|
|
312
|
+
//
|
|
313
|
+
// ```
|
|
314
|
+
// ratio2cent(ratio) : _
|
|
315
|
+
// ```
|
|
316
|
+
//
|
|
317
|
+
// Where:
|
|
318
|
+
//
|
|
319
|
+
// * `ratio`: frequency multiplicative ratio
|
|
320
|
+
//-----------------------------
|
|
321
|
+
ratio2cent(ratio) = 1200.0*log(ratio)/log(2.0);
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
//-------`(ba.)pianokey2hz`----------
|
|
325
|
+
// Converts a piano key number to a frequency in Hz (piano key 49 = A440).
|
|
326
|
+
//
|
|
327
|
+
// #### Usage
|
|
328
|
+
//
|
|
329
|
+
// ```
|
|
330
|
+
// pianokey2hz(pk) : _
|
|
331
|
+
// ```
|
|
332
|
+
//
|
|
333
|
+
// Where:
|
|
334
|
+
//
|
|
335
|
+
// * `pk`: the piano key number
|
|
336
|
+
//-----------------------------
|
|
337
|
+
pianokey2hz(pk) = 440.0*pow(2.0, (pk-49.0)/12.0);
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
//-------`(ba.)hz2pianokey`----------
|
|
341
|
+
// Converts a frequency in Hz to a piano key number (piano key 49 = A440).
|
|
342
|
+
//
|
|
343
|
+
// #### Usage
|
|
344
|
+
//
|
|
345
|
+
// ```
|
|
346
|
+
// hz2pianokey(freq) : _
|
|
347
|
+
// ```
|
|
348
|
+
//
|
|
349
|
+
// Where:
|
|
350
|
+
//
|
|
351
|
+
// * `freq`: frequency in Hz
|
|
352
|
+
//-----------------------------
|
|
353
|
+
hz2pianokey(freq) = 12.0*ma.log2(freq/440.0) + 49.0;
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
// end jos section
|
|
357
|
+
//########################################################################################
|
|
358
|
+
/************************************************************************
|
|
359
|
+
FAUST library file, GRAME section 2
|
|
360
|
+
************************************************************************/
|
|
361
|
+
|
|
362
|
+
//==============================Counters and Time/Tempo Tools=============================
|
|
363
|
+
//========================================================================================
|
|
364
|
+
|
|
365
|
+
//----------------------------`(ba.)counter`------------------------------
|
|
366
|
+
// Starts counting 0, 1, 2, 3..., and raise the current integer value
|
|
367
|
+
// at each upfront of the trigger.
|
|
368
|
+
//
|
|
369
|
+
// #### Usage
|
|
370
|
+
//
|
|
371
|
+
// ```
|
|
372
|
+
// counter(trig) : _
|
|
373
|
+
// ```
|
|
374
|
+
//
|
|
375
|
+
// Where:
|
|
376
|
+
//
|
|
377
|
+
// * `trig`: the trigger signal, each upfront will move the counter to the next integer
|
|
378
|
+
//-----------------------------------------------------------------------------
|
|
379
|
+
declare counter author "Stephane Letz";
|
|
380
|
+
|
|
381
|
+
counter(trig) = upfront(trig) : + ~ _ with { upfront(x) = x > x'; };
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
//----------------------------`(ba.)countdown`------------------------------
|
|
385
|
+
// Starts counting down from n included to 0. While trig is 1 the output is n.
|
|
386
|
+
// The countdown starts with the transition of trig from 1 to 0. At the end
|
|
387
|
+
// of the countdown the output value will remain at 0 until the next trig.
|
|
388
|
+
// `countdown` is a standard Faust function.
|
|
389
|
+
//
|
|
390
|
+
// #### Usage
|
|
391
|
+
//
|
|
392
|
+
// ```
|
|
393
|
+
// countdown(n,trig) : _
|
|
394
|
+
// ```
|
|
395
|
+
//
|
|
396
|
+
// Where:
|
|
397
|
+
//
|
|
398
|
+
// * `n`: the starting point of the countdown
|
|
399
|
+
// * `trig`: the trigger signal (1: start at `n`; 0: decrease until 0)
|
|
400
|
+
//-----------------------------------------------------------------------------
|
|
401
|
+
countdown(n, trig) = \(c).(if(trig>0, n, max(0, c-1))) ~ _;
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
//----------------------------`(ba.)countup`--------------------------------
|
|
405
|
+
// Starts counting up from 0 to n included. While trig is 1 the output is 0.
|
|
406
|
+
// The countup starts with the transition of trig from 1 to 0. At the end
|
|
407
|
+
// of the countup the output value will remain at n until the next trig.
|
|
408
|
+
// `countup` is a standard Faust function.
|
|
409
|
+
//
|
|
410
|
+
// #### Usage
|
|
411
|
+
//
|
|
412
|
+
// ```
|
|
413
|
+
// countup(n,trig) : _
|
|
414
|
+
// ```
|
|
415
|
+
//
|
|
416
|
+
// Where:
|
|
417
|
+
//
|
|
418
|
+
// * `n`: the maximum count value
|
|
419
|
+
// * `trig`: the trigger signal (1: start at 0; 0: increase until `n`)
|
|
420
|
+
//-----------------------------------------------------------------------------
|
|
421
|
+
countup(n, trig) = \(c).(if(trig>0, 0, min(n, c+1))) ~ _;
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
//--------------------`(ba.)sweep`--------------------------
|
|
425
|
+
// Counts from 0 to `period-1` repeatedly, generating a
|
|
426
|
+
// sawtooth waveform, like `os.lf_rawsaw`,
|
|
427
|
+
// starting at 1 when `run` transitions from 0 to 1.
|
|
428
|
+
// Outputs zero while `run` is 0.
|
|
429
|
+
//
|
|
430
|
+
// #### Usage
|
|
431
|
+
//
|
|
432
|
+
// ```
|
|
433
|
+
// sweep(period,run) : _
|
|
434
|
+
// ```
|
|
435
|
+
//-----------------------------------------------------------------
|
|
436
|
+
declare sweep author "Jonatan Liljedahl";
|
|
437
|
+
|
|
438
|
+
sweep = %(int(*:max(1)))~+(1);
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
//-------`(ba.)time`----------
|
|
442
|
+
// A simple timer that counts every samples from the beginning of the process.
|
|
443
|
+
// `time` is a standard Faust function.
|
|
444
|
+
//
|
|
445
|
+
// #### Usage
|
|
446
|
+
//
|
|
447
|
+
// ```
|
|
448
|
+
// time : _
|
|
449
|
+
// ```
|
|
450
|
+
//------------------------
|
|
451
|
+
time = (+(1)~_) - 1;
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
//-------`(ba.)ramp`----------
|
|
455
|
+
// A linear ramp with a slope of '(+/-)1/n' samples to reach the next target value.
|
|
456
|
+
//
|
|
457
|
+
// #### Usage
|
|
458
|
+
//
|
|
459
|
+
// ```
|
|
460
|
+
// _ : ramp(n) : _
|
|
461
|
+
// ```
|
|
462
|
+
// Where:
|
|
463
|
+
//
|
|
464
|
+
// * `n`: number of samples to increment/decrement the value by one
|
|
465
|
+
//------------------------
|
|
466
|
+
ramp = case {
|
|
467
|
+
(0) => _;
|
|
468
|
+
(n) => \(y,x).(if(y+1.0/n < x, y+1.0/n, if(y-1.0/n > x, y-1.0/n, x))) ~ _;
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
//-------`(ba.)line`----------
|
|
473
|
+
// A ramp interpolator that generates a linear transition to reach a target value:
|
|
474
|
+
//
|
|
475
|
+
// - the interpolation process restarts each time a new and distinct input value is received
|
|
476
|
+
// - it utilizes 'n' samples to achieve the transition to the target value
|
|
477
|
+
// - after reaching the target value, the output value is maintained.
|
|
478
|
+
//
|
|
479
|
+
// #### Usage
|
|
480
|
+
//
|
|
481
|
+
// ```
|
|
482
|
+
// _ : line(n) : _
|
|
483
|
+
// ```
|
|
484
|
+
// Where:
|
|
485
|
+
//
|
|
486
|
+
// * `n`: number of samples to reach the new target received at its input
|
|
487
|
+
//------------------------
|
|
488
|
+
line(n, x) = state ~ (_,_) : !,_
|
|
489
|
+
with {
|
|
490
|
+
state(t, c) = nt,nc
|
|
491
|
+
with {
|
|
492
|
+
nt = ba.if(x != x', n, t-1);
|
|
493
|
+
nc = ba.if(nt > 0, c + (x - c)/nt, x);
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
//-------`(ba.)tempo`----------
|
|
499
|
+
// Converts a tempo in BPM into a number of samples.
|
|
500
|
+
//
|
|
501
|
+
// #### Usage
|
|
502
|
+
//
|
|
503
|
+
// ```
|
|
504
|
+
// tempo(t) : _
|
|
505
|
+
// ```
|
|
506
|
+
//
|
|
507
|
+
// Where:
|
|
508
|
+
//
|
|
509
|
+
// * `t`: tempo in BPM
|
|
510
|
+
//------------------------
|
|
511
|
+
tempo(t) = (60*ma.SR)/t;
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
//-------`(ba.)period`----------
|
|
515
|
+
// Basic sawtooth wave of period `p`.
|
|
516
|
+
//
|
|
517
|
+
// #### Usage
|
|
518
|
+
//
|
|
519
|
+
// ```
|
|
520
|
+
// period(p) : _
|
|
521
|
+
// ```
|
|
522
|
+
//
|
|
523
|
+
// Where:
|
|
524
|
+
//
|
|
525
|
+
// * `p`: period as a number of samples
|
|
526
|
+
//------------------------
|
|
527
|
+
// NOTE: may be this should go in oscillators.lib
|
|
528
|
+
period(p) = %(int(p))~+(1');
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
//-------`(ba.)pulse`----------
|
|
532
|
+
// Pulses (like 10000) generated at period `p`.
|
|
533
|
+
//
|
|
534
|
+
// #### Usage
|
|
535
|
+
//
|
|
536
|
+
// ```
|
|
537
|
+
// pulse(p) : _
|
|
538
|
+
// ```
|
|
539
|
+
//
|
|
540
|
+
// Where:
|
|
541
|
+
//
|
|
542
|
+
// * `p`: period as a number of samples
|
|
543
|
+
//------------------------
|
|
544
|
+
// NOTE: may be this should go in oscillators.lib
|
|
545
|
+
pulse(p) = period(p) : \(x).(x <= x');
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
//-------`(ba.)pulsen`----------
|
|
549
|
+
// Pulses (like 11110000) of length `n` generated at period `p`.
|
|
550
|
+
//
|
|
551
|
+
// #### Usage
|
|
552
|
+
//
|
|
553
|
+
// ```
|
|
554
|
+
// pulsen(n,p) : _
|
|
555
|
+
// ```
|
|
556
|
+
//
|
|
557
|
+
// Where:
|
|
558
|
+
//
|
|
559
|
+
// * `n`: pulse length as a number of samples
|
|
560
|
+
// * `p`: period as a number of samples
|
|
561
|
+
//------------------------
|
|
562
|
+
// NOTE: may be this should go in oscillators.lib
|
|
563
|
+
pulsen(n,p) = period(p)<n;
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
//-----------------------`(ba.)cycle`---------------------------
|
|
567
|
+
// Split nonzero input values into `n` cycles.
|
|
568
|
+
//
|
|
569
|
+
// #### Usage
|
|
570
|
+
//
|
|
571
|
+
// ```
|
|
572
|
+
// _ : cycle(n) : si.bus(n)
|
|
573
|
+
// ```
|
|
574
|
+
//
|
|
575
|
+
// Where:
|
|
576
|
+
//
|
|
577
|
+
// * `n`: the number of cycles/output signals
|
|
578
|
+
//---------------------------------------------------------
|
|
579
|
+
declare cycle author "Mike Olsen";
|
|
580
|
+
|
|
581
|
+
cycle(n) = _ <: par(i,n,resetCtr(n,(i+1)));
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
//-------`(ba.)beat`----------
|
|
585
|
+
// Pulses at tempo `t`.
|
|
586
|
+
// `beat` is a standard Faust function.
|
|
587
|
+
//
|
|
588
|
+
// #### Usage
|
|
589
|
+
//
|
|
590
|
+
// ```
|
|
591
|
+
// beat(t) : _
|
|
592
|
+
// ```
|
|
593
|
+
//
|
|
594
|
+
// Where:
|
|
595
|
+
//
|
|
596
|
+
// * `t`: tempo in BPM
|
|
597
|
+
//------------------------
|
|
598
|
+
beat(t) = pulse(tempo(t));
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
//----------------------------`(ba.)pulse_countup`-----------------------------------
|
|
602
|
+
// Starts counting up pulses. While trig is 1 the output is
|
|
603
|
+
// counting up, while trig is 0 the counter is reset to 0.
|
|
604
|
+
//
|
|
605
|
+
// #### Usage
|
|
606
|
+
//
|
|
607
|
+
// ```
|
|
608
|
+
// _ : pulse_countup(trig) : _
|
|
609
|
+
// ```
|
|
610
|
+
//
|
|
611
|
+
// Where:
|
|
612
|
+
//
|
|
613
|
+
// * `trig`: the trigger signal (1: start at next pulse; 0: reset to 0)
|
|
614
|
+
//------------------------------------------------------------------------------
|
|
615
|
+
declare pulse_countup author "Vince";
|
|
616
|
+
|
|
617
|
+
pulse_countup(trig) = + ~ _ * trig;
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
//----------------------------`(ba.)pulse_countdown`---------------------------------
|
|
621
|
+
// Starts counting down pulses. While trig is 1 the output is
|
|
622
|
+
// counting down, while trig is 0 the counter is reset to 0.
|
|
623
|
+
//
|
|
624
|
+
// #### Usage
|
|
625
|
+
//
|
|
626
|
+
// ```
|
|
627
|
+
// _ : pulse_countdown(trig) : _
|
|
628
|
+
// ```
|
|
629
|
+
//
|
|
630
|
+
// Where:
|
|
631
|
+
//
|
|
632
|
+
// * `trig`: the trigger signal (1: start at next pulse; 0: reset to 0)
|
|
633
|
+
//------------------------------------------------------------------------------
|
|
634
|
+
declare pulse_countdown author "Vince";
|
|
635
|
+
|
|
636
|
+
pulse_countdown(trig) = - ~ _ * trig;
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
//----------------------------`(ba.)pulse_countup_loop`------------------------------
|
|
640
|
+
// Starts counting up pulses from 0 to n included. While trig is 1 the output is
|
|
641
|
+
// counting up, while trig is 0 the counter is reset to 0. At the end
|
|
642
|
+
// of the countup (n) the output value will be reset to 0.
|
|
643
|
+
//
|
|
644
|
+
// #### Usage
|
|
645
|
+
//
|
|
646
|
+
// ```
|
|
647
|
+
// _ : pulse_countup_loop(n,trig) : _
|
|
648
|
+
// ```
|
|
649
|
+
//
|
|
650
|
+
// Where:
|
|
651
|
+
//
|
|
652
|
+
// * `n`: the highest number of the countup (included) before reset to 0
|
|
653
|
+
// * `trig`: the trigger signal (1: start at next pulse; 0: reset to 0)
|
|
654
|
+
//------------------------------------------------------------------------------
|
|
655
|
+
declare pulse_countup_loop author "Vince";
|
|
656
|
+
|
|
657
|
+
pulse_countup_loop(n, trig) = + ~ cond(n)*trig
|
|
658
|
+
with {
|
|
659
|
+
cond(n, x) = x * (x <= n);
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
//----------------------------`(ba.)pulse_countdown_loop`----------------------------
|
|
664
|
+
// Starts counting down pulses from 0 to n included. While trig is 1 the output
|
|
665
|
+
// is counting down, while trig is 0 the counter is reset to 0. At the end
|
|
666
|
+
// of the countdown (n) the output value will be reset to 0.
|
|
667
|
+
//
|
|
668
|
+
// #### Usage
|
|
669
|
+
//
|
|
670
|
+
// ```
|
|
671
|
+
// _ : pulse_countdown_loop(n,trig) : _
|
|
672
|
+
// ```
|
|
673
|
+
//
|
|
674
|
+
// Where:
|
|
675
|
+
//
|
|
676
|
+
// * `n`: the highest number of the countup (included) before reset to 0
|
|
677
|
+
// * `trig`: the trigger signal (1: start at next pulse; 0: reset to 0)
|
|
678
|
+
//------------------------------------------------------------------------------
|
|
679
|
+
declare pulse_countdown_loop author "Vince";
|
|
680
|
+
|
|
681
|
+
pulse_countdown_loop(n, trig) = - ~ cond(n)*trig
|
|
682
|
+
with {
|
|
683
|
+
cond(n, x) = x * (x >= n);
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
//-----------------------`(ba.)resetCtr`------------------------
|
|
688
|
+
// Function that lets through the mth impulse out of
|
|
689
|
+
// each consecutive group of `n` impulses.
|
|
690
|
+
//
|
|
691
|
+
// #### Usage
|
|
692
|
+
//
|
|
693
|
+
// ```
|
|
694
|
+
// _ : resetCtr(n,m) : _
|
|
695
|
+
// ```
|
|
696
|
+
//
|
|
697
|
+
// Where:
|
|
698
|
+
//
|
|
699
|
+
// * `n`: the total number of impulses being split
|
|
700
|
+
// * `m`: index of impulse to allow to be output
|
|
701
|
+
//---------------------------------------------------------
|
|
702
|
+
declare resetCtr author "Mike Olsen";
|
|
703
|
+
|
|
704
|
+
resetCtr(n,m) = _ <: (_,pulse_countup_loop(n-1,1)) : (_,(_==m)) : *;
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
//===============================Array Processing/Pattern Matching========================
|
|
708
|
+
//========================================================================================
|
|
709
|
+
|
|
710
|
+
//---------------------------------`(ba.)count`---------------------------------
|
|
711
|
+
// Count the number of elements of list l.
|
|
712
|
+
// `count` is a standard Faust function.
|
|
713
|
+
//
|
|
714
|
+
// #### Usage
|
|
715
|
+
//
|
|
716
|
+
// ```
|
|
717
|
+
// count(l)
|
|
718
|
+
// count((10,20,30,40)) -> 4
|
|
719
|
+
// ```
|
|
720
|
+
//
|
|
721
|
+
// Where:
|
|
722
|
+
//
|
|
723
|
+
// * `l`: list of elements
|
|
724
|
+
//-----------------------------------------------------------------------------
|
|
725
|
+
count((xs, xxs)) = 1 + count(xxs);
|
|
726
|
+
count(xx) = 1;
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
//-------------------------------`(ba.)take`-----------------------------------
|
|
730
|
+
// Take an element from a list.
|
|
731
|
+
// `take` is a standard Faust function.
|
|
732
|
+
//
|
|
733
|
+
// #### Usage
|
|
734
|
+
//
|
|
735
|
+
// ```
|
|
736
|
+
// take(P,l)
|
|
737
|
+
// take(3,(10,20,30,40)) -> 30
|
|
738
|
+
// ```
|
|
739
|
+
//
|
|
740
|
+
// Where:
|
|
741
|
+
//
|
|
742
|
+
// * `P`: position (int, known at compile time, P > 0)
|
|
743
|
+
// * `l`: list of elements
|
|
744
|
+
//-----------------------------------------------------------------------------
|
|
745
|
+
take(1, (xs, xxs)) = xs;
|
|
746
|
+
take(1, xs) = xs;
|
|
747
|
+
take(N, (xs, xxs)) = take(N-1, xxs);
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
//----------------------------`(ba.)subseq`--------------------------------
|
|
751
|
+
// Extract a part of a list.
|
|
752
|
+
//
|
|
753
|
+
// #### Usage
|
|
754
|
+
//
|
|
755
|
+
// ```
|
|
756
|
+
// subseq(l, P, N)
|
|
757
|
+
// subseq((10,20,30,40,50,60), 1, 3) -> (20,30,40)
|
|
758
|
+
// subseq((10,20,30,40,50,60), 4, 1) -> 50
|
|
759
|
+
// ```
|
|
760
|
+
//
|
|
761
|
+
// Where:
|
|
762
|
+
//
|
|
763
|
+
// * `l`: list
|
|
764
|
+
// * `P`: start point (int, known at compile time, 0: begin of list)
|
|
765
|
+
// * `N`: number of elements (int, known at compile time)
|
|
766
|
+
//
|
|
767
|
+
// #### Note:
|
|
768
|
+
//
|
|
769
|
+
// Faust doesn't have proper lists. Lists are simulated with parallel
|
|
770
|
+
// compositions and there is no empty list.
|
|
771
|
+
//-----------------------------------------------------------------------------
|
|
772
|
+
subseq((head, tail), 0, 1) = head;
|
|
773
|
+
subseq((head, tail), 0, N) = head, subseq(tail, 0, N-1);
|
|
774
|
+
subseq((head, tail), P, N) = subseq(tail, P-1, N);
|
|
775
|
+
subseq(head, 0, N) = head;
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
//============================Function tabulation=========================================
|
|
779
|
+
// The purpose of function tabulation is to speed up the computation of heavy functions over an interval,
|
|
780
|
+
// so that the computation at runtime can be faster than directly using the function.
|
|
781
|
+
// Two techniques are implemented:
|
|
782
|
+
//
|
|
783
|
+
// * `tabulate` computes the function in a table and read the points using interpolation. `tabulateNd` is the N dimensions version of `tabulate`
|
|
784
|
+
//
|
|
785
|
+
// * `tabulate_chebychev` uses Chebyshev polynomial approximation
|
|
786
|
+
//
|
|
787
|
+
// #### Comparison program example
|
|
788
|
+
// ```
|
|
789
|
+
///* Both tabulate() and tabulate_chebychev() create rdtable of size = 200, both use */
|
|
790
|
+
///* cubic polynomials, so this comparison is more or less fair. */
|
|
791
|
+
// process = line(50000, r0, r1) <: FX-tb,FX-ch : par(i, 2, maxerr)
|
|
792
|
+
// with {
|
|
793
|
+
// C = 0;
|
|
794
|
+
// FX = sin;
|
|
795
|
+
// NX = 50;
|
|
796
|
+
// CD = 3;
|
|
797
|
+
// r0 = 0;
|
|
798
|
+
// r1 = ma.PI;
|
|
799
|
+
// tb(x) = ba.tabulate(C, FX, NX*(CD+1), r0, r1, x).cub;
|
|
800
|
+
// ch(x) = ba.tabulate_chebychev(C, FX, NX, CD, r0, r1, x);
|
|
801
|
+
// maxerr = abs : max ~ _;
|
|
802
|
+
// line(n, x0, x1) = x0 + (ba.time%n)/n * (x1-x0);
|
|
803
|
+
// };
|
|
804
|
+
// ```
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
//-------`(ba.)tabulate`----------
|
|
808
|
+
// Tabulate a 1D function over the range [r0, r1] for access via nearest-value, linear, cubic interpolation.
|
|
809
|
+
// In other words, the uniformly tabulated function can be evaluated using interpolation of order 0 (none), 1 (linear), or 3 (cubic).
|
|
810
|
+
//
|
|
811
|
+
// #### Usage
|
|
812
|
+
//
|
|
813
|
+
// ```
|
|
814
|
+
// tabulate(C, FX, S, r0, r1, x).(val|lin|cub) : _
|
|
815
|
+
// ```
|
|
816
|
+
//
|
|
817
|
+
// * `C`: whether to dynamically force the `x` value to the range [r0, r1]: 1 forces the check, 0 deactivates it (constant numerical expression)
|
|
818
|
+
// * `FX`: unary function Y=F(X) with one output (scalar function of one variable)
|
|
819
|
+
// * `S`: size of the table in samples (constant numerical expression)
|
|
820
|
+
// * `r0`: minimum value of argument x
|
|
821
|
+
// * `r1`: maximum value of argument x
|
|
822
|
+
//
|
|
823
|
+
// ```
|
|
824
|
+
// tabulate(C, FX, S, r0, r1, x).val uses the value in the table closest to x
|
|
825
|
+
// ```
|
|
826
|
+
//
|
|
827
|
+
// ```
|
|
828
|
+
// tabulate(C, FX, S, r0, r1, x).lin evaluates at x using linear interpolation between the closest stored values
|
|
829
|
+
// ```
|
|
830
|
+
//
|
|
831
|
+
// ```
|
|
832
|
+
// tabulate(C, FX, S, r0, r1, x).cub evaluates at x using cubic interpolation between the closest stored values
|
|
833
|
+
// ```
|
|
834
|
+
//
|
|
835
|
+
// #### Example test program
|
|
836
|
+
//
|
|
837
|
+
// ```
|
|
838
|
+
// midikey2hz(mk) = ba.tabulate(1, ba.midikey2hz, 512, 0, 127, mk).lin;
|
|
839
|
+
// process = midikey2hz(ba.time), ba.midikey2hz(ba.time);
|
|
840
|
+
// ```
|
|
841
|
+
//
|
|
842
|
+
//--------------------------------------------
|
|
843
|
+
tabulate(C, FX, S, r0, r1, x) = environment {
|
|
844
|
+
|
|
845
|
+
// Maximum index to access
|
|
846
|
+
mid = S-1;
|
|
847
|
+
|
|
848
|
+
// Create the table
|
|
849
|
+
wf = r0 + float(ba.time)*(r1-r0)/float(mid) : FX;
|
|
850
|
+
|
|
851
|
+
// Prepare the 'float' table read index
|
|
852
|
+
id = (x-r0)/(r1-r0)*mid;
|
|
853
|
+
|
|
854
|
+
// Limit the table read index in [0, mid] if C = 1
|
|
855
|
+
rid(x, 0) = x;
|
|
856
|
+
rid(x, 1) = max(0, min(x, mid));
|
|
857
|
+
|
|
858
|
+
// Tabulate an unary 'FX' function on a range [r0, r1]
|
|
859
|
+
val = y0 with { y0 = rdtable(S, wf, rid(int(id+0.5), C)); };
|
|
860
|
+
|
|
861
|
+
// Tabulate an unary 'FX' function over the range [r0, r1] with linear interpolation
|
|
862
|
+
lin = it.interpolate_linear(d,y0,y1)
|
|
863
|
+
with {
|
|
864
|
+
x0 = int(id);
|
|
865
|
+
x1 = x0+1;
|
|
866
|
+
d = id-x0;
|
|
867
|
+
y0 = rdtable(S, wf, rid(x0, C));
|
|
868
|
+
y1 = rdtable(S, wf, rid(x1, C));
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
// Tabulate an unary 'FX' function over the range [r0, r1] with cubic interpolation
|
|
872
|
+
cub = it.interpolate_cubic(d,y0,y1,y2,y3)
|
|
873
|
+
with {
|
|
874
|
+
x0 = x1-1;
|
|
875
|
+
x1 = int(id);
|
|
876
|
+
x2 = x1+1;
|
|
877
|
+
x3 = x2+1;
|
|
878
|
+
d = id-x1;
|
|
879
|
+
y0 = rdtable(S, wf, rid(x0, C));
|
|
880
|
+
y1 = rdtable(S, wf, rid(x1, C));
|
|
881
|
+
y2 = rdtable(S, wf, rid(x2, C));
|
|
882
|
+
y3 = rdtable(S, wf, rid(x3, C));
|
|
883
|
+
};
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
declare tabulate author "Stephane Letz";
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
//-------`(ba.)tabulate_chebychev`----------
|
|
890
|
+
// Tabulate a 1D function over the range [r0, r1] for access via Chebyshev polynomial approximation.
|
|
891
|
+
// In contrast to `(ba.)tabulate`, which interpolates only between tabulated samples, `(ba.)tabulate_chebychev`
|
|
892
|
+
// stores coefficients of Chebyshev polynomials that are evaluated to provide better approximations in many cases.
|
|
893
|
+
// Two new arguments controlling this are NX, the number of segments into which [r0, r1] is divided, and CD,
|
|
894
|
+
// the maximum Chebyshev polynomial degree to use for each segment. A `rdtable` of size NX*(CD+1) is internally used.
|
|
895
|
+
//
|
|
896
|
+
// Note that processing `r1` the last point in the interval is not safe. So either be sure the input stays in [r0, r1[
|
|
897
|
+
// or use `C = 1`.
|
|
898
|
+
//
|
|
899
|
+
// #### Usage
|
|
900
|
+
//
|
|
901
|
+
// ```
|
|
902
|
+
// _ : tabulate_chebychev(C, FX, NX, CD, r0, r1) : _
|
|
903
|
+
// ```
|
|
904
|
+
//
|
|
905
|
+
// * `C`: whether to dynamically force the value to the range [r0, r1]: 1 forces the check, 0 deactivates it (constant numerical expression)
|
|
906
|
+
// * `FX`: unary function Y=F(X) with one output (scalar function of one variable)
|
|
907
|
+
// * `NX`: number of segments for uniformly partitioning [r0, r1] (constant numerical expression)
|
|
908
|
+
// * `CD`: maximum polynomial degree for each Chebyshev polynomial (constant numerical expression)
|
|
909
|
+
// * `r0`: minimum value of argument x
|
|
910
|
+
// * `r1`: maximum value of argument x
|
|
911
|
+
//
|
|
912
|
+
// #### Example test program
|
|
913
|
+
//
|
|
914
|
+
// ```
|
|
915
|
+
// midikey2hz_chebychev(mk) = ba.tabulate_chebychev(1, ba.midikey2hz, 100, 4, 0, 127, mk);
|
|
916
|
+
// process = midikey2hz_chebychev(ba.time), ba.midikey2hz(ba.time);
|
|
917
|
+
// ```
|
|
918
|
+
//
|
|
919
|
+
//--------------------------------------------
|
|
920
|
+
tabulate_chebychev(C, FX, NX, CD, r0, r1, x) = y with {
|
|
921
|
+
ck(0) = _;
|
|
922
|
+
ck(1) = max(0) : min(NX-1);
|
|
923
|
+
|
|
924
|
+
// number of chebyshev coefficients
|
|
925
|
+
NC = CD + 1;
|
|
926
|
+
// length of the segments
|
|
927
|
+
DX = (r1 - r0) / NX;
|
|
928
|
+
// number of segment 'x' falls in
|
|
929
|
+
nx = (x - r0) / DX : int : ck(C);
|
|
930
|
+
// center of n's segment
|
|
931
|
+
xc(n) = r0 + DX * (n + 1/2);
|
|
932
|
+
// so ch(0) .. ch(NC) are the coeffs we use for approximation
|
|
933
|
+
// on nx's segment
|
|
934
|
+
ch(i) = chtab(NC * nx + i);
|
|
935
|
+
|
|
936
|
+
// map the input in segment [nx*DX, (nx+1)*DX] to [-1,1]
|
|
937
|
+
y = (x - xc(nx)) * 2/DX <: sum(i, NC, ch(i) * ma.chebychev(i));
|
|
938
|
+
|
|
939
|
+
// map [-1,1] to the segment [nx*DX, (nx+1)*DX] so mapfx(nx)
|
|
940
|
+
// is simply the "renormalized" FX defined on [-1,1]
|
|
941
|
+
mapfx(nx, x) = FX(xc(nx) + DX/2 * x);
|
|
942
|
+
|
|
943
|
+
// calculate the nc's chebyshev coefficient we use on nx's segment
|
|
944
|
+
gench(nx, nc) = (1+(nc!=0))/NC * sum(k,NC,
|
|
945
|
+
mapfx(nx, cos(ma.PI*(k+1/2)/NC)) * cos(ma.PI*nc*(k+1/2)/NC));
|
|
946
|
+
|
|
947
|
+
// record gench(nx, nc) in rdtable() to avoid the run-time calculations
|
|
948
|
+
chtab = rdtable(NX*NC, (ba.time <: int(/(NC)), %(NC) : gench));
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
declare tabulate_chebychev author "Oleg Nesterov";
|
|
952
|
+
declare tabulate_chebychev copyright "Copyright (C) 2022 Oleg Nesterov <oleg@redhat.com>";
|
|
953
|
+
declare tabulate_chebychev license "MIT-style STK-4.3 license";
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
//-------`(ba.)tabulateNd`----------
|
|
957
|
+
// Tabulate an nD function for access via nearest-value or linear or cubic interpolation. In other words, the tabulated function can be evaluated using interpolation of order 0 (none), 1 (linear), or 3 (cubic).
|
|
958
|
+
//
|
|
959
|
+
// The table size and parameter range of each dimension can and must be separately specified. You can use it anywhere you have an expensive function with multiple parameters with known ranges. You could use it to build a wavetable synth, for example.
|
|
960
|
+
//
|
|
961
|
+
// The number of dimensions is deduced from the number of parameters you give, see below.
|
|
962
|
+
//
|
|
963
|
+
// Note that processing the last point in each interval is not safe. So either be sure the inputs stay in their respective ranges, or use `C = 1`. Similarly for the first point when doing cubic interpolation.
|
|
964
|
+
//
|
|
965
|
+
// #### Usage
|
|
966
|
+
//
|
|
967
|
+
// ```
|
|
968
|
+
// tabulateNd(C, function, (parameters) ).(val|lin|cub) : _
|
|
969
|
+
// ```
|
|
970
|
+
//
|
|
971
|
+
// * `C`: whether to dynamically force the parameter values for each dimension to the ranges specified in parameters: 1 forces the check, 0 deactivates it (constant numerical expression)
|
|
972
|
+
// * `function`: the function we want to tabulate. Can have any number of inputs, but needs to have just one output.
|
|
973
|
+
// * `(parameters)`: sizes, ranges and read values. Note: these need to be in brackets, to make them one entity.
|
|
974
|
+
//
|
|
975
|
+
// If N is the number of dimensions, we need:
|
|
976
|
+
//
|
|
977
|
+
// * N times `S`: number of values to store for this dimension (constant numerical expression)
|
|
978
|
+
// * N times `r0`: minimum value of this dimension
|
|
979
|
+
// * N times `r1`: maximum value of this dimension
|
|
980
|
+
// * N times `x`: read value of this dimension
|
|
981
|
+
//
|
|
982
|
+
// By providing these parameters, you indirectly specify the number of dimensions; it's the number of parameters divided by 4.
|
|
983
|
+
//
|
|
984
|
+
// The user facing functions are:
|
|
985
|
+
// ```
|
|
986
|
+
// tabulateNd(C, function, S, parameters).val
|
|
987
|
+
// ```
|
|
988
|
+
// - Uses the value in the table closest to x.
|
|
989
|
+
// ```
|
|
990
|
+
// tabulateNd(C, function, S, parameters).lin
|
|
991
|
+
// ```
|
|
992
|
+
// - Evaluates at x using linear interpolation between the closest stored values.
|
|
993
|
+
// ```
|
|
994
|
+
// tabulateNd(C, function, S, parameters).cub
|
|
995
|
+
// ```
|
|
996
|
+
// - Evaluates at x using cubic interpolation between the closest stored values.
|
|
997
|
+
//
|
|
998
|
+
//
|
|
999
|
+
// #### Example test program
|
|
1000
|
+
//
|
|
1001
|
+
// ```faust
|
|
1002
|
+
// powSin(x,y) = sin(pow(x,y)); // The function we want to tabulate
|
|
1003
|
+
// powSinTable(x,y) = ba.tabulateNd(1, powSin, (sizeX,sizeY, rx0,ry0, rx1,ry1, x,y) ).lin;
|
|
1004
|
+
// sizeX = 512; // table size of the first parameter
|
|
1005
|
+
// sizeY = 512; // table size of the second parameter
|
|
1006
|
+
// rx0 = 2; // start of the range of the first parameter
|
|
1007
|
+
// ry0 = 2; // start of the range of the second parameter
|
|
1008
|
+
// rx1 = 10; // end of the range of the first parameter
|
|
1009
|
+
// ry1 = 10; // end of the range of the second parameter
|
|
1010
|
+
// x = hslider("x", rx0, rx0, rx1, 0.001):si.smoo;
|
|
1011
|
+
// y = hslider("y", ry0, ry0, ry1, 0.001):si.smoo;
|
|
1012
|
+
// process = powSinTable(x,y), powSin(x,y);
|
|
1013
|
+
// ```
|
|
1014
|
+
//
|
|
1015
|
+
// #### Working principle
|
|
1016
|
+
//
|
|
1017
|
+
// The ``.val`` function just outputs the closest stored value.
|
|
1018
|
+
// The ``.lin`` and ``.cub`` functions interpolate in N dimensions.
|
|
1019
|
+
//
|
|
1020
|
+
// ##### Multi dimensional interpolation
|
|
1021
|
+
//
|
|
1022
|
+
// To understand what it means to interpolate in N dimensions, here's a quick reminder on the general principle of 2D linear interpolation:
|
|
1023
|
+
//
|
|
1024
|
+
// * We have a grid of values, and we want to find the value at a point (x, y) within this grid.
|
|
1025
|
+
// * We first find the four closest points (A, B, C, D) in the grid surrounding the point (x, y).
|
|
1026
|
+
//
|
|
1027
|
+
// Then, we perform linear interpolation in the x-direction between points A and B, and between points C and D. This gives us two new points E and F. Finally, we perform linear interpolation in the y-direction between points E and F to get our value.
|
|
1028
|
+
//
|
|
1029
|
+
// To implement this in Faust, we need N sequential groups of interpolators, where N is the number of dimensions.
|
|
1030
|
+
// Each group feeds into the next, with the last "group" being a single interpolator, and the group before it containing one interpolator for each input of the group it's feeding.
|
|
1031
|
+
//
|
|
1032
|
+
// Some examples:
|
|
1033
|
+
//
|
|
1034
|
+
// * Our 2D linear example has two interpolators feeding into one.
|
|
1035
|
+
// * A 3D linear interpolator has four interpolators feeding into two, feeding into one.
|
|
1036
|
+
// * A 2D cubic interpolater has four interpolators feeding into one.
|
|
1037
|
+
// * A 3D cubic interpolator has sixteen interpolators feeding into four, feeding into one.
|
|
1038
|
+
//
|
|
1039
|
+
// To understand which values we need to look up, let's consider the 2D linear example again.
|
|
1040
|
+
// The four values going into the first group represent the four closest points (A, B, C, D) mentioned above.
|
|
1041
|
+
//
|
|
1042
|
+
// 1) The first interpolator gets:
|
|
1043
|
+
//
|
|
1044
|
+
// * The closest value that is stored (A)
|
|
1045
|
+
// * The next value in the x dimension, keeping y fixed (B)
|
|
1046
|
+
//
|
|
1047
|
+
// 2) The second interpolator gets:
|
|
1048
|
+
//
|
|
1049
|
+
// * One step over in the y dimension, keeping x fixed (C)
|
|
1050
|
+
// * One step over in both the x dimension and the y dimension (D)
|
|
1051
|
+
//
|
|
1052
|
+
// The outputs of these two interpolators are points E and F.
|
|
1053
|
+
// In other words: the interpolated x values and, respectively, the following y values:
|
|
1054
|
+
//
|
|
1055
|
+
// * The closest stored value of the y dimension
|
|
1056
|
+
// * One step forward in the y dimension
|
|
1057
|
+
//
|
|
1058
|
+
// The last interpolator takes these two values and interpolates them in the y dimension.
|
|
1059
|
+
//
|
|
1060
|
+
// To generalize for N dimensions and linear interpolation:
|
|
1061
|
+
//
|
|
1062
|
+
// * The first group has 2^(n-1) parallel interpolators interpolating in the first dimension.
|
|
1063
|
+
// * The second group has 2^(n-2) parallel interpolators interpolating in the second dimension.
|
|
1064
|
+
// * The process continues until the n-th group, which has a single interpolator interpolating in the n-th dimension.
|
|
1065
|
+
//
|
|
1066
|
+
// The same principle applies to the cubic interpolation in nD. The only difference is that there would be 4^(n-1) parallel interpolators in the first group, compared to 2^(n-1) for linear interpolation.
|
|
1067
|
+
//
|
|
1068
|
+
// This is what the ``mixers`` function does.
|
|
1069
|
+
//
|
|
1070
|
+
// Besides the values, each interpolator also needs to know the weight of each value in it's output.
|
|
1071
|
+
// Let's call this `d`, like in ``ba.interpolate``. It is the same for each group of interpolators, since it correlates to a dimension.
|
|
1072
|
+
// It's value is calculated the similarly to ``ba.interpolate``:
|
|
1073
|
+
//
|
|
1074
|
+
// * First we prepare a "float table read-index" for that dimension (``id`` in ``ba.tabulate``)
|
|
1075
|
+
// * If the table only had that dimension and it could read a float index, what would it be.
|
|
1076
|
+
// * Then we ``int`` the float index to get the value we have stored that is closest to, but lower than the input value; the actual index for that dimension.
|
|
1077
|
+
// Our ``d`` is the difference between the float index and the actual index.
|
|
1078
|
+
//
|
|
1079
|
+
// The ``ids`` function calculates the ``id`` for each dimension and inside the ``mixer`` function they get turned into ``d``s.
|
|
1080
|
+
//
|
|
1081
|
+
// ##### Storage method
|
|
1082
|
+
//
|
|
1083
|
+
// The elephant in the room is: how do we get these indexes? For that we need to know how the values are stored.
|
|
1084
|
+
// We use one big table to store everything.
|
|
1085
|
+
//
|
|
1086
|
+
// To understand the concept, let's look at the 2D example again, and then we'll extend it to 3d and the general nD case.
|
|
1087
|
+
//
|
|
1088
|
+
// Let's say we have a 2D table with dimensions A and B where:
|
|
1089
|
+
// A has 3 values between 0 and 5 and B has 4 values between 0 and 1.
|
|
1090
|
+
// The 1D array representation of this 2D table will have a size of 3 * 4 = 12.
|
|
1091
|
+
//
|
|
1092
|
+
// The values are stored in the following way:
|
|
1093
|
+
//
|
|
1094
|
+
// * First 3 values: A is 0, then 3, then 5 while B is at 0.
|
|
1095
|
+
// * Next 3 values: A changes from 0 to 5 while B is at 1/3.
|
|
1096
|
+
// * Next 3 values: A changes from 0 to 5 while B is at 2/3.
|
|
1097
|
+
// * Last 3 values: A changes from 0 to 5 while B is at 1.
|
|
1098
|
+
//
|
|
1099
|
+
// For the 3D example, let's extend the 2D example with an additional dimension C having 2 values between 0 and 2.
|
|
1100
|
+
// The total size will be 3 * 4 * 2 = 24.
|
|
1101
|
+
//
|
|
1102
|
+
// The values are stored like so:
|
|
1103
|
+
//
|
|
1104
|
+
// * First 3 values: A changes from 0 to 5, B is at 0, and C is at 0.
|
|
1105
|
+
// * Next 3 values: A changes from 0 to 5, B is at 1/3, and C is at 0.
|
|
1106
|
+
// * Next 3 values: A changes from 0 to 5, B is at 2/3, and C is at 0.
|
|
1107
|
+
// * Next 3 values: A changes from 0 to 5, B is at 1, and C is at 0.
|
|
1108
|
+
//
|
|
1109
|
+
// The last 12 values are the same as the first 12, but with C at 2.
|
|
1110
|
+
//
|
|
1111
|
+
// For the general n-dimensional case, we iterate through all dimensions, changing the values of the innermost dimension first, then moving towards the outer dimensions.
|
|
1112
|
+
//
|
|
1113
|
+
// ##### Read indexes
|
|
1114
|
+
//
|
|
1115
|
+
// To get the float read index (``id``) corresponding to a particular dimension, we scale the function input value to be between 0 and 1, and multiply it by the size of that dimension minus one.
|
|
1116
|
+
//
|
|
1117
|
+
// To understand how we get the ``readIndex``for ``.val``, let's work trough how we'd do it in our 2D linear example.
|
|
1118
|
+
// For simplicity's sake, the ranges of the inputs to our ``function`` are both 0 to 1.
|
|
1119
|
+
// Say we wanted to read the value closest to ``x=0.5`` and ``y=0``, so the ``id`` of ``x`` is ``1`` (the second value) and the ``id`` of ``y`` is 0 (first value). In this case, the read index is just the ``id`` of ``x``, rounded to the nearest integer, just like in ``ba.tabulate``.
|
|
1120
|
+
//
|
|
1121
|
+
// If we want to read the value belonging to ``x=0.5`` and ``y=2/3``, things get more complicated. The ``id`` for ``y`` is now ``2``, the third value. For each step in the ``y`` direction, we need to increase the index by ``3``, the number of values that are stored for ``x``. So the influence of the ``y`` is: the size of ``x`` times the rounded ``id`` of ``y``. The final read index is the rounded ``id`` of ``x`` plus the influence of ``y``.
|
|
1122
|
+
//
|
|
1123
|
+
// For the general nD case, we need to do the same operation N times, each feeding into the next. This operation is the ``riN`` function. We take four parameters: the size of the dimension before it ``prevSize``, the index of the previous dimension ``prevIX``, the current size ``sizeX`` and the current id ``idX``. ``riN`` has 2 outputs, the size, for feeding into the next dimension's ``prevSize``, and the read index feeding into the next dimension's ``prevIX``.
|
|
1124
|
+
// The size is the ``sizeX`` times ``prevSize``. The read index is the rounded ``idX`` times ``prevSize`` added to the ``prevIX``. Our final ``readIndex`` is the read index output of the last dimension.
|
|
1125
|
+
//
|
|
1126
|
+
// To get the read values for the interpolators need a pattern of offsets in each dimension, since we are looking for the read indexes surrounding the point of interest. These offsets are best explained by looking at the code of ``tabulate2d``, the hardcoded 2D version:
|
|
1127
|
+
//
|
|
1128
|
+
// ```faust
|
|
1129
|
+
// tabulate2d(C,function, sizeX,sizeY, rx0,ry0, rx1,ry1, x,y) =
|
|
1130
|
+
// environment {
|
|
1131
|
+
// size = sizeX*sizeY;
|
|
1132
|
+
// // Maximum X index to access
|
|
1133
|
+
// midX = sizeX-1;
|
|
1134
|
+
// // Maximum Y index to access
|
|
1135
|
+
// midY = sizeY-1;
|
|
1136
|
+
// // Maximum total index to access
|
|
1137
|
+
// mid = size-1;
|
|
1138
|
+
// // Create the table
|
|
1139
|
+
// wf = function(wfX,wfY);
|
|
1140
|
+
// // Prepare the 'float' table read index for X
|
|
1141
|
+
// idX = (x-rx0)/(rx1-rx0)*midX;
|
|
1142
|
+
// // Prepare the 'float' table read index for Y
|
|
1143
|
+
// idY = ((y-ry0)/(ry1-ry0))*midY;
|
|
1144
|
+
// // table creation X:
|
|
1145
|
+
// wfX =
|
|
1146
|
+
// rx0+float(ba.time%sizeX)*(rx1-rx0)
|
|
1147
|
+
// /float(midX);
|
|
1148
|
+
// // table creation Y:
|
|
1149
|
+
// wfY =
|
|
1150
|
+
// ry0+
|
|
1151
|
+
// ((float(ba.time-(ba.time%sizeX))
|
|
1152
|
+
// /float(sizeX))
|
|
1153
|
+
// *(ry1-ry0))
|
|
1154
|
+
// /float(midY);
|
|
1155
|
+
//
|
|
1156
|
+
// // Limit the table read index in [0, mid] if C = 1
|
|
1157
|
+
// rid(x,mid, 0) = x;
|
|
1158
|
+
// rid(x,mid, 1) = max(0, min(x, mid));
|
|
1159
|
+
//
|
|
1160
|
+
// // Tabulate a binary 'FX' function on a range [rx0, rx1] [ry0, ry1]
|
|
1161
|
+
// val(x,y) =
|
|
1162
|
+
// rdtable(size, wf, readIndex);
|
|
1163
|
+
// readIndex =
|
|
1164
|
+
// rid(
|
|
1165
|
+
// rid(int(idX+0.5),midX, C)
|
|
1166
|
+
// +yOffset
|
|
1167
|
+
// , mid, C);
|
|
1168
|
+
// yOffset = sizeX*rid(int(idY),midY,C);
|
|
1169
|
+
//
|
|
1170
|
+
// // Tabulate a binary 'FX' function over the range [rx0, rx1] [ry0, ry1] with linear interpolation
|
|
1171
|
+
// lin =
|
|
1172
|
+
// it.interpolate_linear(
|
|
1173
|
+
// dy
|
|
1174
|
+
// , it.interpolate_linear(dx,v0,v1)
|
|
1175
|
+
// , it.interpolate_linear(dx,v2,v3))
|
|
1176
|
+
// with {
|
|
1177
|
+
// i0 = rid(int(idX), midX, C)+yOffset;
|
|
1178
|
+
// i1 = i0+1;
|
|
1179
|
+
// i2 = i0+sizeX;
|
|
1180
|
+
// i3 = i1+sizeX;
|
|
1181
|
+
// dx = idX-int(idX);
|
|
1182
|
+
// dy = idY-int(idY);
|
|
1183
|
+
// v0 = rdtable(size, wf, rid(i0, mid, C));
|
|
1184
|
+
// v1 = rdtable(size, wf, rid(i1, mid, C));
|
|
1185
|
+
// v2 = rdtable(size, wf, rid(i2, mid, C));
|
|
1186
|
+
// v3 = rdtable(size, wf, rid(i3, mid, C));
|
|
1187
|
+
// };
|
|
1188
|
+
//
|
|
1189
|
+
// // Tabulate a binary 'FX' function over the range [rx0, rx1] [ry0, ry1] with cubic interpolation
|
|
1190
|
+
// cub =
|
|
1191
|
+
// it.interpolate_cubic(
|
|
1192
|
+
// dy
|
|
1193
|
+
// , it.interpolate_cubic(dx,v0,v1,v2,v3)
|
|
1194
|
+
// , it.interpolate_cubic(dx,v4,v5,v6,v7)
|
|
1195
|
+
// , it.interpolate_cubic(dx,v8,v9,v10,v11)
|
|
1196
|
+
// , it.interpolate_cubic(dx,v12,v13,v14,v15)
|
|
1197
|
+
// )
|
|
1198
|
+
// with {
|
|
1199
|
+
// i0 = i4-sizeX;
|
|
1200
|
+
// i1 = i5-sizeX;
|
|
1201
|
+
// i2 = i6-sizeX;
|
|
1202
|
+
// i3 = i7-sizeX;
|
|
1203
|
+
//
|
|
1204
|
+
// i4 = i5-1;
|
|
1205
|
+
// i5 = rid(int(idX), midX, C)+yOffset;
|
|
1206
|
+
// i6 = i5+1;
|
|
1207
|
+
// i7 = i6+1;
|
|
1208
|
+
//
|
|
1209
|
+
// i8 = i4+sizeX;
|
|
1210
|
+
// i9 = i5+sizeX;
|
|
1211
|
+
// i10 = i6+sizeX;
|
|
1212
|
+
// i11 = i7+sizeX;
|
|
1213
|
+
//
|
|
1214
|
+
// i12 = i4+(2*sizeX);
|
|
1215
|
+
// i13 = i5+(2*sizeX);
|
|
1216
|
+
// i14 = i6+(2*sizeX);
|
|
1217
|
+
// i15 = i7+(2*sizeX);
|
|
1218
|
+
//
|
|
1219
|
+
// dx = idX-int(idX);
|
|
1220
|
+
// dy = idY-int(idY);
|
|
1221
|
+
// v0 = rdtable(size, wf, rid(i0 , mid, C));
|
|
1222
|
+
// v1 = rdtable(size, wf, rid(i1 , mid, C));
|
|
1223
|
+
// v2 = rdtable(size, wf, rid(i2 , mid, C));
|
|
1224
|
+
// v3 = rdtable(size, wf, rid(i3 , mid, C));
|
|
1225
|
+
// v4 = rdtable(size, wf, rid(i4 , mid, C));
|
|
1226
|
+
// v5 = rdtable(size, wf, rid(i5 , mid, C));
|
|
1227
|
+
// v6 = rdtable(size, wf, rid(i6 , mid, C));
|
|
1228
|
+
// v7 = rdtable(size, wf, rid(i7 , mid, C));
|
|
1229
|
+
// v8 = rdtable(size, wf, rid(i8 , mid, C));
|
|
1230
|
+
// v9 = rdtable(size, wf, rid(i9 , mid, C));
|
|
1231
|
+
// v10 = rdtable(size, wf, rid(i10, mid, C));
|
|
1232
|
+
// v11 = rdtable(size, wf, rid(i11, mid, C));
|
|
1233
|
+
// v12 = rdtable(size, wf, rid(i12, mid, C));
|
|
1234
|
+
// v13 = rdtable(size, wf, rid(i13, mid, C));
|
|
1235
|
+
// v14 = rdtable(size, wf, rid(i14, mid, C));
|
|
1236
|
+
// v15 = rdtable(size, wf, rid(i15, mid, C));
|
|
1237
|
+
// };
|
|
1238
|
+
// };
|
|
1239
|
+
// ```
|
|
1240
|
+
//
|
|
1241
|
+
// In the interest of brevity, we'll stop explaining here. If you have any more questions, feel free to open an issue on [faustlibraries](https://github.com/grame-cncm/faustlibraries) and tag @magnetophon.
|
|
1242
|
+
//
|
|
1243
|
+
//--------------------------------------------
|
|
1244
|
+
tabulateNd(C,function,parameters) =
|
|
1245
|
+
environment {
|
|
1246
|
+
val =
|
|
1247
|
+
parameters
|
|
1248
|
+
// our sizes can be int, should be faster to calculate
|
|
1249
|
+
: (par(i, N, int),si.bus(N*3))
|
|
1250
|
+
// table size, waveform, read index
|
|
1251
|
+
<: (tableSize,wf,readIndex(idsGetRoundedNotFloored))
|
|
1252
|
+
: rdtable
|
|
1253
|
+
with {
|
|
1254
|
+
// for val we want the rounded version of id, the interpolators need the rounded down version
|
|
1255
|
+
// see: https://github.com/grame-cncm/faustlibraries/pull/152
|
|
1256
|
+
idsGetRoundedNotFloored =
|
|
1257
|
+
// table sizes and ids for each dimension
|
|
1258
|
+
sizesIds:
|
|
1259
|
+
(bs,par(i, N, _+0.5));
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
lin =
|
|
1263
|
+
parameters
|
|
1264
|
+
// our sizes can be int, should be faster to calculate
|
|
1265
|
+
: (par(i, N, int),si.bus(N*3))
|
|
1266
|
+
// the mixers need the float indexes and the values read from the tables
|
|
1267
|
+
<: (ids,tables(nrReadIndexes,readIndexes))
|
|
1268
|
+
// the actual interpolation
|
|
1269
|
+
:mixers(0,nrReadIndexes)
|
|
1270
|
+
with {
|
|
1271
|
+
// the read indexes to form the closest points in the grid surrounding the point of interest.
|
|
1272
|
+
readIndexes =
|
|
1273
|
+
// for cleaner block diagrams
|
|
1274
|
+
si.bus(nParams) <:
|
|
1275
|
+
// the closest stored value at or below the point of interest
|
|
1276
|
+
((readIndex(sizesIds) <:si.bus(nrReadIndexes))
|
|
1277
|
+
// the offsets to get to the points around it
|
|
1278
|
+
, offsets)
|
|
1279
|
+
// add them up
|
|
1280
|
+
: ro.interleave(nrReadIndexes,2) : par(i, nrReadIndexes, +) ;
|
|
1281
|
+
offsets =
|
|
1282
|
+
// the size of a step for each dimension
|
|
1283
|
+
stepSizes
|
|
1284
|
+
// for each read index
|
|
1285
|
+
<: par(i, nrReadIndexes,
|
|
1286
|
+
// sum up the N components that determine the final offset
|
|
1287
|
+
par(j, N, switch(i,j)):>_)
|
|
1288
|
+
with {
|
|
1289
|
+
// the truth table of which step size to use is a binary counting table
|
|
1290
|
+
// so we use a variant on a function I wrote for slidingReduce
|
|
1291
|
+
switch(i,j) = _*int2bin(j,i,nrReadIndexes);
|
|
1292
|
+
};
|
|
1293
|
+
// since each interpolator has 2 inputs
|
|
1294
|
+
nrReadIndexes = pow(2,N);
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
cub =
|
|
1298
|
+
// same as .lin so far
|
|
1299
|
+
parameters
|
|
1300
|
+
: (par(i, N, int),si.bus(N*3))
|
|
1301
|
+
<: (ids,tables(nrReadIndexes,readIndexes))
|
|
1302
|
+
:mixers(1,nrReadIndexes)
|
|
1303
|
+
with {
|
|
1304
|
+
readIndexes =
|
|
1305
|
+
si.bus(nParams) <:
|
|
1306
|
+
((stepSizes:ro.cross(N))
|
|
1307
|
+
, readIndex(sizesIds))
|
|
1308
|
+
// calculate the offsets for each interpolation read index and add them to the "base" readindex
|
|
1309
|
+
:cubifiers;
|
|
1310
|
+
// since each interpolator has 4 inputs
|
|
1311
|
+
nrReadIndexes = pow(4,N);
|
|
1312
|
+
// calculate the offsets and add them to the "base" readindex
|
|
1313
|
+
// we do this by creating a tree, where each branch has 4 sub-branches
|
|
1314
|
+
// there are N splits, so we end up with nrReadIndexes "leaves"
|
|
1315
|
+
cubifiers =
|
|
1316
|
+
// iterate trough the dimensions, each feeding into the next
|
|
1317
|
+
seq(i, N,
|
|
1318
|
+
si.bus(N-i-1),cubifier(pow(4,i)));
|
|
1319
|
+
// take a step size and ``len`` input indexes and create 4*len output indexes
|
|
1320
|
+
// offset the input index(es) with the amount needed for that dimension
|
|
1321
|
+
cubifier(len) =
|
|
1322
|
+
((_<:si.bus(len*4))
|
|
1323
|
+
, (si.bus(len)<:si.bus(len*4)))
|
|
1324
|
+
: ro.interleave(len*4,2)
|
|
1325
|
+
:par(i, 4,
|
|
1326
|
+
par(j, len, off(i)+_))
|
|
1327
|
+
with {
|
|
1328
|
+
// the hardcoded numbers are the same offsets as in ``ba.tabulate``
|
|
1329
|
+
// but they get multiplied by the step size of the current dimension
|
|
1330
|
+
off(0,stepSize) = -1*stepSize;
|
|
1331
|
+
off(1,stepSize) = 0;
|
|
1332
|
+
off(2,stepSize) = 1*stepSize;
|
|
1333
|
+
off(3,stepSize) = 2*stepSize;
|
|
1334
|
+
};
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
// how many parameters have we been given?
|
|
1338
|
+
nParams = outputs(parameters);
|
|
1339
|
+
// the number of dimensions
|
|
1340
|
+
N = int(nParams/4);
|
|
1341
|
+
// the values we read from the tables
|
|
1342
|
+
tables(nrReadIndexes,readIndexes) =
|
|
1343
|
+
si.bus(nParams)<:
|
|
1344
|
+
// table size, waveform, read index for each table
|
|
1345
|
+
((tableSize<:si.bus(nrReadIndexes))
|
|
1346
|
+
, (wf<:si.bus(nrReadIndexes))
|
|
1347
|
+
, readIndexes)
|
|
1348
|
+
:ro.interleave(nrReadIndexes,3)
|
|
1349
|
+
// the actual tables
|
|
1350
|
+
:par(i, nrReadIndexes, rdtable);
|
|
1351
|
+
|
|
1352
|
+
// the interpolators
|
|
1353
|
+
mixers(linCub,nrReadIndexes)=
|
|
1354
|
+
(ro.cross(N),si.bus(nrReadIndexes))
|
|
1355
|
+
: seq(i, N, mixer(linCub,i));
|
|
1356
|
+
|
|
1357
|
+
// the interpolator for a single dimension
|
|
1358
|
+
// linear version
|
|
1359
|
+
mixer(0,i) =
|
|
1360
|
+
mixerUniversal(i,2,(_,!,_),it.interpolate_linear) ;
|
|
1361
|
+
// cubic version
|
|
1362
|
+
mixer(1,i) =
|
|
1363
|
+
mixerUniversal(i,4,(_,!,_,!,_,!,_),it.interpolate_cubic) ;
|
|
1364
|
+
|
|
1365
|
+
// i is the current dimension
|
|
1366
|
+
// mult is the number of inputs of each interpolator
|
|
1367
|
+
// sieve tells us which outputs to let trough and which to block, more on this soon
|
|
1368
|
+
mixerUniversal(i,mult,sieve,it) =
|
|
1369
|
+
// bypass the weights needed for the next dimension
|
|
1370
|
+
si.bus(N-i-1),
|
|
1371
|
+
// split our own weight
|
|
1372
|
+
// in the end we need one weight per interpolator
|
|
1373
|
+
// but since we need to interleave these with nrInterpolators*mult read values, we split it into as many busses as we have read values
|
|
1374
|
+
(((_<:si.bus(nrInterpolators(i)*mult))
|
|
1375
|
+
// the read values bypass this step
|
|
1376
|
+
, (si.bus(nrInterpolators(i)*mult)))
|
|
1377
|
+
// interleave the weights with the read values
|
|
1378
|
+
: ro.interleave(nrInterpolators(i)*mult,2)
|
|
1379
|
+
// the actual interpolators
|
|
1380
|
+
: par(i, nrInterpolators(i),
|
|
1381
|
+
// take the id and turn it into the weight for this dimension
|
|
1382
|
+
((_<:(_-int(_)))
|
|
1383
|
+
// throw away the extra weights we created for the interleave
|
|
1384
|
+
,sieve)
|
|
1385
|
+
// a single interpolator
|
|
1386
|
+
:it))
|
|
1387
|
+
with {
|
|
1388
|
+
// the number of interpolators for this dimension
|
|
1389
|
+
nrInterpolators(i) = pow(mult,N-i-1);
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
// total size of the table: s(0) * s(1) ... * s(N-2) * s(N-1)
|
|
1393
|
+
// N in, 1 out
|
|
1394
|
+
size(1) = _;
|
|
1395
|
+
size(N) = _*size(N-1);
|
|
1396
|
+
tableSize = size(N),par(i, N*3, !);
|
|
1397
|
+
// the size of a step for each dimension.
|
|
1398
|
+
// the first is 1, the second is the size of the first dimension times one
|
|
1399
|
+
// the third is the second number, times the size of the second dimension
|
|
1400
|
+
stepSizes =
|
|
1401
|
+
(int(1),si.bus(N-1),par(i, 3*N+1, !))
|
|
1402
|
+
: seq(i, N-1,
|
|
1403
|
+
((si.bus(i),(_<:(_,_)), si.bus(N-i-1))
|
|
1404
|
+
:(si.bus(i+1),*,si.bus(N-i-2))));
|
|
1405
|
+
// Prepare the 'float' table read index for one parameter
|
|
1406
|
+
id(sizeX,r0,r1,x) = (x-r0)/(r1-r0)*(sizeX-1);
|
|
1407
|
+
// Prepare the 'float' table read index for all parameters
|
|
1408
|
+
ids =
|
|
1409
|
+
ro.interleave(N,4)
|
|
1410
|
+
: par(i, N, id) ;
|
|
1411
|
+
|
|
1412
|
+
// one waveform parameter write value:
|
|
1413
|
+
wfp(prevSize,sizeX,r0,r1) =
|
|
1414
|
+
r0+
|
|
1415
|
+
((float(int(ba.time%(prevSize*sizeX)/prevSize))*(r1-r0))
|
|
1416
|
+
/float(sizeX-1))
|
|
1417
|
+
,(prevSize*sizeX);
|
|
1418
|
+
|
|
1419
|
+
// all waveform parameters write values:
|
|
1420
|
+
wfps =
|
|
1421
|
+
ro.interleave(N,3)
|
|
1422
|
+
: (1,si.bus(3*N))
|
|
1423
|
+
: seq(i, N, si.bus(i),wfp, si.bus(3*N-(3*(i+1))))
|
|
1424
|
+
: (si.bus(N),!);
|
|
1425
|
+
|
|
1426
|
+
// Create the table
|
|
1427
|
+
wf = (wfps,par(i, N, !)):function;
|
|
1428
|
+
|
|
1429
|
+
// Limit the table read index in [0, mid] if C = 1
|
|
1430
|
+
// we do this both for the total table and per dimension
|
|
1431
|
+
rid(x,mid, 0) = int(x);
|
|
1432
|
+
rid(x,mid, 1) = max(int(0), min(int(x), mid));
|
|
1433
|
+
|
|
1434
|
+
// for ``.val`` this is the stored value closest to the point of interest
|
|
1435
|
+
// for ``.lin`` and ``cub`` it's the closest stored value at or below the point of interest
|
|
1436
|
+
readIndex(sizesIds) =
|
|
1437
|
+
// table sizes and ids for each dimension
|
|
1438
|
+
sizesIds
|
|
1439
|
+
// get the raw read index
|
|
1440
|
+
: ri
|
|
1441
|
+
// limit it and make it an int
|
|
1442
|
+
: riPost ;
|
|
1443
|
+
// helper function to route the arguments of rid
|
|
1444
|
+
riPost(size,ri) =
|
|
1445
|
+
rid(ri,size-int(1),C);
|
|
1446
|
+
// the raw read index
|
|
1447
|
+
ri =
|
|
1448
|
+
// interleave the sizes and the ids
|
|
1449
|
+
ro.interleave(N,2)
|
|
1450
|
+
// the first iteration gets:
|
|
1451
|
+
// 1 as the size of the previous dimension and 0 as the read index of the previous dimension
|
|
1452
|
+
: (1,0
|
|
1453
|
+
// pass trough the sizes and ids
|
|
1454
|
+
,si.bus(2*N))
|
|
1455
|
+
// for each dimension
|
|
1456
|
+
: seq(i, N,
|
|
1457
|
+
// get the step size and the partial index for the next dimension
|
|
1458
|
+
riN
|
|
1459
|
+
// pass trough the sizes and ids for the next dimensions
|
|
1460
|
+
, si.bus(2*(N-i-1))) ;
|
|
1461
|
+
|
|
1462
|
+
// get the step size and the partial index for the next dimension
|
|
1463
|
+
riN(prevSize,prevIX,sizeX,idX) =
|
|
1464
|
+
// each step size is the previous step size times the current
|
|
1465
|
+
(prevSize*sizeX)
|
|
1466
|
+
// but the step we actually take in this dimension is the stepsize we calculated in the previous dimension
|
|
1467
|
+
, ( (prevSize*
|
|
1468
|
+
// round down and limit the id for this dimension to get the number of steps
|
|
1469
|
+
rid(int(idX),(sizeX-int(1)),C))
|
|
1470
|
+
// add the result of that to the one we calculated in the previous dimension
|
|
1471
|
+
+prevIX) ;
|
|
1472
|
+
|
|
1473
|
+
// table sizes and ids for each dimension
|
|
1474
|
+
// just a helper function to simplify routing
|
|
1475
|
+
sizesIds =
|
|
1476
|
+
(
|
|
1477
|
+
// from sizes
|
|
1478
|
+
( bs<:si.bus(N*2) )
|
|
1479
|
+
// from r0s,r1s,xs
|
|
1480
|
+
, si.bus(N*3)
|
|
1481
|
+
) :
|
|
1482
|
+
// from sizes
|
|
1483
|
+
(si.bus(N)
|
|
1484
|
+
// takes (midX,r0,r1,x)
|
|
1485
|
+
,ids);
|
|
1486
|
+
|
|
1487
|
+
// the value of a single bit when binary counting
|
|
1488
|
+
int2bin(i,n,maxN) = int(int((n)/(1<<i))%int(2));
|
|
1489
|
+
// shortcut
|
|
1490
|
+
bs = si.bus(N);
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1493
|
+
declare tabulateNd author "Bart Brouns";
|
|
1494
|
+
declare tabulateNd "Copyright (C) 2023 Bart Brouns <bart@magnetophon.nl>";
|
|
1495
|
+
declare tabulateNd license "AGPL-3.0";
|
|
1496
|
+
|
|
1497
|
+
//============================Selectors (Conditions)======================================
|
|
1498
|
+
//========================================================================================
|
|
1499
|
+
|
|
1500
|
+
//-----------------------------`(ba.)if`-----------------------------------
|
|
1501
|
+
// if-then-else implemented with a select2. WARNING: since `select2` is strict (always evaluating both branches),
|
|
1502
|
+
// the resulting if does not have the usual "lazy" semantic of the C if form, and thus cannot be used to
|
|
1503
|
+
// protect against forbidden computations like division-by-zero for instance.
|
|
1504
|
+
//
|
|
1505
|
+
// #### Usage
|
|
1506
|
+
//
|
|
1507
|
+
// * `if(cond, then, else) : _`
|
|
1508
|
+
//
|
|
1509
|
+
// Where:
|
|
1510
|
+
//
|
|
1511
|
+
// * `cond`: condition
|
|
1512
|
+
// * `then`: signal selected while cond is true
|
|
1513
|
+
// * `else`: signal selected while cond is false
|
|
1514
|
+
//-----------------------------------------------------------------------------
|
|
1515
|
+
if(cond,then,else) = select2(cond,else,then);
|
|
1516
|
+
// TODO: perhaps it would make more sense to have an if(a,b) and an ifelse(a,b,c)?
|
|
1517
|
+
|
|
1518
|
+
//-----------------------------`(ba.)ifNc`--------------------------------------
|
|
1519
|
+
// if-then-elseif-then-...elsif-then-else implemented on top of `ba.if`.
|
|
1520
|
+
//
|
|
1521
|
+
// #### Usage
|
|
1522
|
+
//
|
|
1523
|
+
// ```
|
|
1524
|
+
// ifNc((cond1,then1, cond2,then2, ... condN,thenN, else)) : _
|
|
1525
|
+
// or
|
|
1526
|
+
// ifNc(Nc, cond1,then1, cond2,then2, ... condN,thenN, else) : _
|
|
1527
|
+
// or
|
|
1528
|
+
// cond1,then1, cond2,then2, ... condN,thenN, else : ifNc(Nc) : _
|
|
1529
|
+
// ```
|
|
1530
|
+
//
|
|
1531
|
+
// Where:
|
|
1532
|
+
//
|
|
1533
|
+
// * `Nc` : number of branches/conditions (constant numerical expression)
|
|
1534
|
+
// * `condX`: condition
|
|
1535
|
+
// * `thenX`: signal selected if condX is the 1st true condition
|
|
1536
|
+
// * `else`: signal selected if all the cond1-condN conditions are false
|
|
1537
|
+
//
|
|
1538
|
+
// #### Example test program
|
|
1539
|
+
//
|
|
1540
|
+
// ```
|
|
1541
|
+
// process(x,y) = ifNc((x<y,-1, x>y,+1, 0));
|
|
1542
|
+
// or
|
|
1543
|
+
// process(x,y) = ifNc(2, x<y,-1, x>y,+1, 0);
|
|
1544
|
+
// or
|
|
1545
|
+
// process(x,y) = x<y,-1, x>y,+1, 0 : ifNc(2);
|
|
1546
|
+
// ```
|
|
1547
|
+
//
|
|
1548
|
+
// outputs `-1` if `x<y`, `+1` if `x>y`, `0` otherwise.
|
|
1549
|
+
//-----------------------------------------------------------------------------
|
|
1550
|
+
ifNc((c,r)) = c,r : ifNc(outputs(r)/2);
|
|
1551
|
+
ifNc(1) = if;
|
|
1552
|
+
ifNc(n) = _,_,ifNc(n-1) : ifNc(1);
|
|
1553
|
+
|
|
1554
|
+
declare ifNc author "Oleg Nesterov";
|
|
1555
|
+
declare ifNc copyright "Copyright (C) 2023 Oleg Nesterov <oleg@redhat.com>";
|
|
1556
|
+
declare ifNc license "MIT-style STK-4.3 license";
|
|
1557
|
+
|
|
1558
|
+
//-----------------------------`(ba.)ifNcNo`-------------------------------------
|
|
1559
|
+
// `ifNcNo(Nc,No)` is similar to `ifNc(Nc)` above but then/else branches have `No` outputs.
|
|
1560
|
+
//
|
|
1561
|
+
// #### Usage
|
|
1562
|
+
//
|
|
1563
|
+
// ```
|
|
1564
|
+
// ifNcNo(Nc,No, cond1,then1, cond2,then2, ... condN,thenN, else) : sig.bus(No)
|
|
1565
|
+
// ```
|
|
1566
|
+
//
|
|
1567
|
+
// Where:
|
|
1568
|
+
//
|
|
1569
|
+
// * `Nc` : number of branches/conditions (constant numerical expression)
|
|
1570
|
+
// * `No` : number of outputs (constant numerical expression)
|
|
1571
|
+
// * `condX`: condition
|
|
1572
|
+
// * `thenX`: list of No signals selected if condX is the 1st true condition
|
|
1573
|
+
// * `else`: list of No signals selected if all the cond1-condN conditions are false
|
|
1574
|
+
//
|
|
1575
|
+
// #### Example test program
|
|
1576
|
+
//
|
|
1577
|
+
// ```
|
|
1578
|
+
// process(x) = ifNcNo(2,3, x<0, -1,-1,-1, x>0, 1,1,1, 0,0,0);
|
|
1579
|
+
// ```
|
|
1580
|
+
//
|
|
1581
|
+
// outputs `-1,-1,-1` if `x<0`, `1,1,1` if `x>0`, `0,0,0` otherwise.
|
|
1582
|
+
//-----------------------------------------------------------------------------
|
|
1583
|
+
ifNcNo(Nc,No) = si.bus(Ni) <: par(no,No, slice(no) : ifNc(Nc))
|
|
1584
|
+
with {
|
|
1585
|
+
Ni = Nc*No + Nc+No;
|
|
1586
|
+
slice(no) = route(Ni,2*Nc+1, (par(nc,Nc, ct(nc,no)),else(no)));
|
|
1587
|
+
ct(nc,no) = nc*(No+1)+1, 2*nc+1, // cond[nc]
|
|
1588
|
+
nc*(No+1)+2+no, 2*nc+2; // then[nc][no]
|
|
1589
|
+
else(no) = Nc*(No+1)+1+no, 2*Nc+1; // else[no]
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
declare ifNcNo author "Oleg Nesterov";
|
|
1593
|
+
declare ifNcNo copyright "Copyright (C) 2023 Oleg Nesterov <oleg@redhat.com>";
|
|
1594
|
+
declare ifNcNo license "MIT-style STK-4.3 license";
|
|
1595
|
+
|
|
1596
|
+
//-----------------------------`(ba.)selector`---------------------------------
|
|
1597
|
+
// Selects the ith input among n at compile time.
|
|
1598
|
+
//
|
|
1599
|
+
// #### Usage
|
|
1600
|
+
//
|
|
1601
|
+
// ```
|
|
1602
|
+
// selector(I,N)
|
|
1603
|
+
// _,_,_,_ : selector(2,4) : _ // selects the 3rd input among 4
|
|
1604
|
+
// ```
|
|
1605
|
+
//
|
|
1606
|
+
// Where:
|
|
1607
|
+
//
|
|
1608
|
+
// * `I`: input to select (int, numbered from 0, known at compile time)
|
|
1609
|
+
// * `N`: number of inputs (int, known at compile time, N > I)
|
|
1610
|
+
//
|
|
1611
|
+
// There is also cselector for selecting among complex input signals of the form (real,imag).
|
|
1612
|
+
//
|
|
1613
|
+
//-----------------------------------------------------------------------------
|
|
1614
|
+
selector(i,n) = par(j, n, S(i, j)) with { S(i,i) = _; S(i,j) = !; };
|
|
1615
|
+
cselector(i,n) = par(j, n, S(i, j)) with { S(i,i) = (_,_); S(i,j) = (!,!); }; // for complex numbers
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
//--------------------`(ba.)select2stereo`--------------------
|
|
1619
|
+
// Select between 2 stereo signals.
|
|
1620
|
+
//
|
|
1621
|
+
// #### Usage
|
|
1622
|
+
//
|
|
1623
|
+
// ```
|
|
1624
|
+
// _,_,_,_ : select2stereo(bpc) : _,_
|
|
1625
|
+
// ```
|
|
1626
|
+
//
|
|
1627
|
+
// Where:
|
|
1628
|
+
//
|
|
1629
|
+
// * `bpc`: the selector switch (0/1)
|
|
1630
|
+
//------------------------------------------------------------
|
|
1631
|
+
select2stereo(bpc) = ro.cross2 : select2(bpc), select2(bpc) : _,_;
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
//-----------------------------`(ba.)selectn`---------------------------------
|
|
1635
|
+
// Selects the ith input among N at run time.
|
|
1636
|
+
//
|
|
1637
|
+
// #### Usage
|
|
1638
|
+
//
|
|
1639
|
+
// ```
|
|
1640
|
+
// selectn(N,i)
|
|
1641
|
+
// _,_,_,_ : selectn(4,2) : _ // selects the 3rd input among 4
|
|
1642
|
+
// ```
|
|
1643
|
+
//
|
|
1644
|
+
// Where:
|
|
1645
|
+
//
|
|
1646
|
+
// * `N`: number of inputs (int, known at compile time, N > 0)
|
|
1647
|
+
// * `i`: input to select (int, numbered from 0)
|
|
1648
|
+
//
|
|
1649
|
+
// #### Example test program
|
|
1650
|
+
//
|
|
1651
|
+
// ```
|
|
1652
|
+
// N = 64;
|
|
1653
|
+
// process = par(n, N, (par(i,N,i) : selectn(N,n)));
|
|
1654
|
+
// ```
|
|
1655
|
+
//-----------------------------------------------------------------------------
|
|
1656
|
+
selectn(N,i) = selectnX(N,i,selector)
|
|
1657
|
+
with {
|
|
1658
|
+
selector(i,j,x,y) = select2((i >= j), x, y);
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
// The generic version with a 'sel' function to be applied on:
|
|
1663
|
+
// - the channel index as a (possibly) fractional value
|
|
1664
|
+
// - the next channel index as an integer value
|
|
1665
|
+
// - the 2 signals to be selected between
|
|
1666
|
+
|
|
1667
|
+
selectnX(N,i,sel) = S(N,0)
|
|
1668
|
+
with {
|
|
1669
|
+
S(1,offset) = _;
|
|
1670
|
+
S(n,offset) = S(left, offset), S(right, offset+left) : sel(i, offset+left)
|
|
1671
|
+
with {
|
|
1672
|
+
right = int(n/2);
|
|
1673
|
+
left = n-right;
|
|
1674
|
+
};
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
//-----------------------------`(ba.)selectmulti`---------------------------------
|
|
1679
|
+
// Selects the ith circuit among N at run time (all should have the same number of inputs and outputs)
|
|
1680
|
+
// with a crossfade.
|
|
1681
|
+
//
|
|
1682
|
+
// #### Usage
|
|
1683
|
+
//
|
|
1684
|
+
// ```
|
|
1685
|
+
// selectmulti(n,lgen,id)
|
|
1686
|
+
// ```
|
|
1687
|
+
//
|
|
1688
|
+
// Where:
|
|
1689
|
+
//
|
|
1690
|
+
// * `n`: crossfade in samples
|
|
1691
|
+
// * `lgen`: list of circuits
|
|
1692
|
+
// * `id`: circuit to select (int, numbered from 0)
|
|
1693
|
+
//
|
|
1694
|
+
// #### Example test program
|
|
1695
|
+
//
|
|
1696
|
+
// ```
|
|
1697
|
+
// process = selectmulti(ma.SR/10, ((3,9),(2,8),(5,7)), nentry("choice", 0, 0, 2, 1));
|
|
1698
|
+
// process = selectmulti(ma.SR/10, ((_*3,_*9),(_*2,_*8),(_*5,_*7)), nentry("choice", 0, 0, 2, 1));
|
|
1699
|
+
// ```
|
|
1700
|
+
//-----------------------------------------------------------------------------
|
|
1701
|
+
selectmulti(n, lgen, id) = selectmultiX(ins, lgen, id)
|
|
1702
|
+
with {
|
|
1703
|
+
selectmultiX(0, lgen, id) = selector; // No inputs
|
|
1704
|
+
selectmultiX(N, lgen, id) = par(i, ins, _) <: selector; // General case
|
|
1705
|
+
|
|
1706
|
+
selector = lgen : ro.interleave(outs, N) : par(i, outs, selectnX(N, id, xfade))
|
|
1707
|
+
with {
|
|
1708
|
+
// crossfade of 'n' samples between 'x' and 'y' channels when the channel index changes
|
|
1709
|
+
xfade(i, j, x, y) = x*(1-xb) + y*xb with { xb = ramp(n, (i >= j)); };
|
|
1710
|
+
};
|
|
1711
|
+
|
|
1712
|
+
outs = outputs(take(1, lgen)); // Number of outputs of the first circuit (all should have the same value)
|
|
1713
|
+
ins = inputs(take(1, lgen)); // Number of inputs of the first circuit (all should have the same value)
|
|
1714
|
+
N = outputs(lgen)/outs; // Number of items in the list
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
//-----------------------------`(ba.)selectoutn`---------------------------------
|
|
1719
|
+
// Route input to the output among N at run time.
|
|
1720
|
+
//
|
|
1721
|
+
// #### Usage
|
|
1722
|
+
//
|
|
1723
|
+
// ```
|
|
1724
|
+
// _ : selectoutn(N, i) : si.bus(N)
|
|
1725
|
+
// ```
|
|
1726
|
+
//
|
|
1727
|
+
// Where:
|
|
1728
|
+
//
|
|
1729
|
+
// * `N`: number of outputs (int, known at compile time, N > 0)
|
|
1730
|
+
// * `i`: output number to route to (int, numbered from 0) (i.e. slider)
|
|
1731
|
+
//
|
|
1732
|
+
// #### Example test program
|
|
1733
|
+
//
|
|
1734
|
+
// ```
|
|
1735
|
+
// process = 1 : selectoutn(3, sel) : par(i, 3, vbargraph("v.bargraph %i", 0, 1));
|
|
1736
|
+
// sel = hslider("volume", 0, 0, 2, 1) : int;
|
|
1737
|
+
// ```
|
|
1738
|
+
//--------------------------------------------------------------------------
|
|
1739
|
+
declare selectoutn author "Vince";
|
|
1740
|
+
|
|
1741
|
+
selectoutn(N, s) = _ <: par(i, N, *(s==i));
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
//=====================================Other==============================================
|
|
1745
|
+
//========================================================================================
|
|
1746
|
+
|
|
1747
|
+
//----------------------------`(ba.)latch`--------------------------------
|
|
1748
|
+
// Latch input on positive-going transition of trig:"records" the input when trig
|
|
1749
|
+
// switches from 0 to 1, outputs a frozen values everytime else.
|
|
1750
|
+
//
|
|
1751
|
+
// #### Usage
|
|
1752
|
+
//
|
|
1753
|
+
// ```
|
|
1754
|
+
// _ : latch(trig) : _
|
|
1755
|
+
// ```
|
|
1756
|
+
//
|
|
1757
|
+
// Where:
|
|
1758
|
+
//
|
|
1759
|
+
// * `trig`: hold trigger (0 for hold, 1 for bypass)
|
|
1760
|
+
//------------------------------------------------------------
|
|
1761
|
+
latch(trig, x) = x * s : + ~ *(1-s) with { s = (trig' <= 0) & (trig > 0); };
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
//--------------------------`(ba.)sAndH`-------------------------------
|
|
1765
|
+
// Sample And Hold: "records" the input when trig is 1, outputs a frozen value when trig is 0.
|
|
1766
|
+
// `sAndH` is a standard Faust function.
|
|
1767
|
+
//
|
|
1768
|
+
// #### Usage
|
|
1769
|
+
//
|
|
1770
|
+
// ```
|
|
1771
|
+
// _ : sAndH(trig) : _
|
|
1772
|
+
// ```
|
|
1773
|
+
//
|
|
1774
|
+
// Where:
|
|
1775
|
+
//
|
|
1776
|
+
// * `trig`: hold trigger (0 for hold, 1 for bypass)
|
|
1777
|
+
//----------------------------------------------------------------
|
|
1778
|
+
declare sAndH author "Romain Michon";
|
|
1779
|
+
|
|
1780
|
+
sAndH(trig) = select2(trig,_,_) ~ _;
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
//--------------------------`(ba.)downSample`-------------------------------
|
|
1784
|
+
// Down sample a signal. WARNING: this function doesn't change the
|
|
1785
|
+
// rate of a signal, it just holds samples...
|
|
1786
|
+
// `downSample` is a standard Faust function.
|
|
1787
|
+
//
|
|
1788
|
+
// #### Usage
|
|
1789
|
+
//
|
|
1790
|
+
// ```
|
|
1791
|
+
// _ : downSample(freq) : _
|
|
1792
|
+
// ```
|
|
1793
|
+
//
|
|
1794
|
+
// Where:
|
|
1795
|
+
//
|
|
1796
|
+
// * `freq`: new rate in Hz
|
|
1797
|
+
//----------------------------------------------------------------
|
|
1798
|
+
declare downSample author "Romain Michon";
|
|
1799
|
+
|
|
1800
|
+
downSample(freq) = sAndH(hold)
|
|
1801
|
+
with {
|
|
1802
|
+
hold = time%int(ma.SR/freq) == 0;
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
//------------------`(ba.)peakhold`---------------------------
|
|
1807
|
+
// Outputs current max value above zero.
|
|
1808
|
+
//
|
|
1809
|
+
// #### Usage
|
|
1810
|
+
//
|
|
1811
|
+
// ```
|
|
1812
|
+
// _ : peakhold(mode) : _
|
|
1813
|
+
// ```
|
|
1814
|
+
//
|
|
1815
|
+
// Where:
|
|
1816
|
+
//
|
|
1817
|
+
// `mode` means:
|
|
1818
|
+
// 0 - Pass through. A single sample 0 trigger will work as a reset.
|
|
1819
|
+
// 1 - Track and hold max value.
|
|
1820
|
+
//----------------------------------------------------------------
|
|
1821
|
+
declare peakhold author "Jonatan Liljedahl, revised by Romain Michon";
|
|
1822
|
+
|
|
1823
|
+
peakhold = (*,_ : max) ~ _;
|
|
1824
|
+
|
|
1825
|
+
//------------------`(ba.)peakholder`-------------------------------------------
|
|
1826
|
+
//
|
|
1827
|
+
// While peak-holder functions are scarcely discussed in the literature
|
|
1828
|
+
// (please do send me an email if you know otherwise), common sense
|
|
1829
|
+
// tells that the expected behaviour should be as follows: the absolute
|
|
1830
|
+
// value of the input signal is compared with the output of the peak-holder;
|
|
1831
|
+
// if the input is greater or equal to the output, a new peak is detected
|
|
1832
|
+
// and sent to the output; otherwise, a timer starts and the current peak
|
|
1833
|
+
// is held for N samples; once the timer is out and no new peaks have been
|
|
1834
|
+
// detected, the absolute value of the current input becomes the new peak.
|
|
1835
|
+
//
|
|
1836
|
+
// #### Usage
|
|
1837
|
+
//
|
|
1838
|
+
// ```
|
|
1839
|
+
// _ : peakholder(holdTime) : _
|
|
1840
|
+
// ```
|
|
1841
|
+
//
|
|
1842
|
+
// Where:
|
|
1843
|
+
//
|
|
1844
|
+
// * `holdTime`: hold time in samples
|
|
1845
|
+
//------------------------------------------------------------------------------
|
|
1846
|
+
declare peakholder author "Dario Sanfilippo";
|
|
1847
|
+
declare peakholder copyright
|
|
1848
|
+
"Copyright (C) 2022 Dario Sanfilippo <sanfilippo.dario@gmail.com>";
|
|
1849
|
+
declare peakholder license "MIT-style STK-4.3 license";
|
|
1850
|
+
peakholder(holdTime, x) = loop ~ si.bus(2) : ! , _
|
|
1851
|
+
with {
|
|
1852
|
+
loop(timerState, outState) = timer , output
|
|
1853
|
+
with {
|
|
1854
|
+
isNewPeak = abs(x) >= outState;
|
|
1855
|
+
isTimeOut = timerState >= holdTime;
|
|
1856
|
+
bypass = isNewPeak | isTimeOut;
|
|
1857
|
+
timer = ba.if(bypass, 0, timerState + 1);
|
|
1858
|
+
output = ba.if(bypass, abs(x), outState);
|
|
1859
|
+
};
|
|
1860
|
+
};
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
/*
|
|
1864
|
+
// Alternate version with branchless code
|
|
1865
|
+
//----------------------------------------
|
|
1866
|
+
peakholder(holdTime, x) = loop ~ si.bus(2) : ! , _
|
|
1867
|
+
with {
|
|
1868
|
+
loop(timerState, outState) = timer , output
|
|
1869
|
+
with {
|
|
1870
|
+
isNewPeak = abs(x) >= outState;
|
|
1871
|
+
isTimeOut = timerState >= holdTime;
|
|
1872
|
+
bypass = isNewPeak | isTimeOut;
|
|
1873
|
+
timer = (1 - bypass) * (timerState + 1);
|
|
1874
|
+
output = bypass * (abs(x) - outState) + outState;
|
|
1875
|
+
};
|
|
1876
|
+
};
|
|
1877
|
+
*/
|
|
1878
|
+
|
|
1879
|
+
/*
|
|
1880
|
+
// The function below is kept for back-compatibility in case any user relies
|
|
1881
|
+
// on it for their software. However, the function behaves differently than
|
|
1882
|
+
// expected: currently, the timer is not reset when a new peak is detected.
|
|
1883
|
+
//------------------------------------------------------------------------------
|
|
1884
|
+
declare peakholder author "Jonatan Liljedahl";
|
|
1885
|
+
peakholder(n) = peakhold2 ~ reset : (!,_) with {
|
|
1886
|
+
reset = sweep(n) > 0;
|
|
1887
|
+
// first out is gate that is 1 while holding last peak
|
|
1888
|
+
peakhold2 = _,abs <: peakhold,!,_ <: >=,_,!;
|
|
1889
|
+
};
|
|
1890
|
+
*/
|
|
1891
|
+
|
|
1892
|
+
|
|
1893
|
+
//--------------------------`(ba.)impulsify`---------------------------
|
|
1894
|
+
// Turns a signal into an impulse with the value of the current sample
|
|
1895
|
+
// (0.3,0.2,0.1 becomes 0.3,0.0,0.0). This function is typically used with a
|
|
1896
|
+
// `button` to turn its output into an impulse. `impulsify` is a standard Faust
|
|
1897
|
+
// function.
|
|
1898
|
+
//
|
|
1899
|
+
// #### Usage
|
|
1900
|
+
//
|
|
1901
|
+
// ```
|
|
1902
|
+
// button("gate") : impulsify;
|
|
1903
|
+
// ```
|
|
1904
|
+
//----------------------------------------------------------------
|
|
1905
|
+
impulsify = _ <: _,mem : - <: >(0)*_;
|
|
1906
|
+
|
|
1907
|
+
|
|
1908
|
+
//-----------------------`(ba.)automat`------------------------------
|
|
1909
|
+
// Record and replay in a loop the successives values of the input signal.
|
|
1910
|
+
//
|
|
1911
|
+
// #### Usage
|
|
1912
|
+
//
|
|
1913
|
+
// ```
|
|
1914
|
+
// hslider(...) : automat(t, size, init) : _
|
|
1915
|
+
// ```
|
|
1916
|
+
//
|
|
1917
|
+
// Where:
|
|
1918
|
+
//
|
|
1919
|
+
// * `t`: tempo in BPM
|
|
1920
|
+
// * `size`: number of items in the loop
|
|
1921
|
+
// * `init`: init value in the loop
|
|
1922
|
+
//-----------------------------------------------------------------------
|
|
1923
|
+
automat(t, size, init, input) = rwtable(size+1, init, windex, input, rindex)
|
|
1924
|
+
with {
|
|
1925
|
+
clock = beat(t);
|
|
1926
|
+
rindex = int(clock) : (+ : %(size)) ~ _; // each clock read the next entry of the table
|
|
1927
|
+
windex = if(timeToRenew, rindex, size); // we ignore input unless it is time to renew
|
|
1928
|
+
timeToRenew = int(clock) & (inputHasMoved | (input <= init));
|
|
1929
|
+
inputHasMoved = abs(input-input') : countfrom(int(clock)') : >(0);
|
|
1930
|
+
countfrom(reset) = (+ : if(reset, 0, _)) ~ _;
|
|
1931
|
+
};
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
//-----------------`(ba.)bpf`-------------------
|
|
1935
|
+
// bpf is an environment (a group of related definitions) that can be used to
|
|
1936
|
+
// create break-point functions. It contains three functions:
|
|
1937
|
+
//
|
|
1938
|
+
// * `start(x,y)` to start a break-point function
|
|
1939
|
+
// * `end(x,y)` to end a break-point function
|
|
1940
|
+
// * `point(x,y)` to add intermediate points to a break-point function
|
|
1941
|
+
//
|
|
1942
|
+
// A minimal break-point function must contain at least a start and an end point:
|
|
1943
|
+
//
|
|
1944
|
+
// ```
|
|
1945
|
+
// f = bpf.start(x0,y0) : bpf.end(x1,y1);
|
|
1946
|
+
// ```
|
|
1947
|
+
//
|
|
1948
|
+
// A more involved break-point function can contains any number of intermediate
|
|
1949
|
+
// points:
|
|
1950
|
+
//
|
|
1951
|
+
// ```
|
|
1952
|
+
// f = bpf.start(x0,y0) : bpf.point(x1,y1) : bpf.point(x2,y2) : bpf.end(x3,y3);
|
|
1953
|
+
// ```
|
|
1954
|
+
//
|
|
1955
|
+
// In any case the `x_{i}` must be in increasing order (for all `i`, `x_{i} < x_{i+1}`).
|
|
1956
|
+
// For example the following definition:
|
|
1957
|
+
//
|
|
1958
|
+
// ```
|
|
1959
|
+
// f = bpf.start(x0,y0) : ... : bpf.point(xi,yi) : ... : bpf.end(xn,yn);
|
|
1960
|
+
// ```
|
|
1961
|
+
//
|
|
1962
|
+
// implements a break-point function f such that:
|
|
1963
|
+
//
|
|
1964
|
+
// * `f(x) = y_{0}` when `x < x_{0}`
|
|
1965
|
+
// * `f(x) = y_{n}` when `x > x_{n}`
|
|
1966
|
+
// * `f(x) = y_{i} + (y_{i+1}-y_{i})*(x-x_{i})/(x_{i+1}-x_{i})` when `x_{i} <= x`
|
|
1967
|
+
// and `x < x_{i+1}`
|
|
1968
|
+
//
|
|
1969
|
+
// `bpf` is a standard Faust function.
|
|
1970
|
+
//--------------------------------------------------------
|
|
1971
|
+
bpf = environment
|
|
1972
|
+
{
|
|
1973
|
+
// Start a break-point function
|
|
1974
|
+
start(x0,y0) = \(x).(x0,y0,x,y0);
|
|
1975
|
+
// Add a break-point
|
|
1976
|
+
point(x1,y1) = \(x0,y0,x,y).(x1, y1, x, if(x < x0, y, if(x < x1, y0 + (x-x0)*(y1-y0)/(x1-x0), y1)));
|
|
1977
|
+
// End a break-point function
|
|
1978
|
+
end(x1,y1) = \(x0,y0,x,y).(if(x < x0, y, if(x < x1, y0 + (x-x0)*(y1-y0)/(x1-x0), y1)));
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
//-------------------`(ba.)listInterp`-------------------------
|
|
1983
|
+
// Linearly interpolates between the elements of a list.
|
|
1984
|
+
//
|
|
1985
|
+
// #### Usage
|
|
1986
|
+
//
|
|
1987
|
+
// ```
|
|
1988
|
+
// index = 1.69; // range is 0-4
|
|
1989
|
+
// process = listInterp((800,400,350,450,325),index);
|
|
1990
|
+
// ```
|
|
1991
|
+
//
|
|
1992
|
+
// Where:
|
|
1993
|
+
//
|
|
1994
|
+
// * `index`: the index (float) to interpolate between the different values.
|
|
1995
|
+
// The range of `index` depends on the size of the list.
|
|
1996
|
+
//------------------------------------------------------------
|
|
1997
|
+
declare listInterp author "Romain Michon";
|
|
1998
|
+
|
|
1999
|
+
listInterp(v) =
|
|
2000
|
+
bpf.start(0,take(1,v)) :
|
|
2001
|
+
seq(i,count(v)-2,bpf.point(i+1,take(i+2,v))) :
|
|
2002
|
+
bpf.end(count(v)-1,take(count(v),v));
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
//-------------------`(ba.)bypass1`-------------------------
|
|
2006
|
+
// Takes a mono input signal, route it to `e` and bypass it if `bpc = 1`.
|
|
2007
|
+
// When bypassed, `e` is feed with zeros so that its state is cleanup up.
|
|
2008
|
+
// `bypass1` is a standard Faust function.
|
|
2009
|
+
//
|
|
2010
|
+
// #### Usage
|
|
2011
|
+
//
|
|
2012
|
+
// ```
|
|
2013
|
+
// _ : bypass1(bpc,e) : _
|
|
2014
|
+
// ```
|
|
2015
|
+
//
|
|
2016
|
+
// Where:
|
|
2017
|
+
//
|
|
2018
|
+
// * `bpc`: bypass switch (0/1)
|
|
2019
|
+
// * `e`: a mono effect
|
|
2020
|
+
//------------------------------------------------------------
|
|
2021
|
+
declare bypass1 author "Julius Smith";
|
|
2022
|
+
// License: STK-4.3
|
|
2023
|
+
|
|
2024
|
+
bypass1(bpc,e) = _ <: select2(bpc,(inswitch:e),_)
|
|
2025
|
+
with {
|
|
2026
|
+
inswitch = select2(bpc,_,0);
|
|
2027
|
+
};
|
|
2028
|
+
|
|
2029
|
+
|
|
2030
|
+
//-------------------`(ba.)bypass2`-------------------------
|
|
2031
|
+
// Takes a stereo input signal, route it to `e` and bypass it if `bpc = 1`.
|
|
2032
|
+
// When bypassed, `e` is feed with zeros so that its state is cleanup up.
|
|
2033
|
+
// `bypass2` is a standard Faust function.
|
|
2034
|
+
//
|
|
2035
|
+
// #### Usage
|
|
2036
|
+
//
|
|
2037
|
+
// ```
|
|
2038
|
+
// _,_ : bypass2(bpc,e) : _,_
|
|
2039
|
+
// ```
|
|
2040
|
+
//
|
|
2041
|
+
// Where:
|
|
2042
|
+
//
|
|
2043
|
+
// * `bpc`: bypass switch (0/1)
|
|
2044
|
+
// * `e`: a stereo effect
|
|
2045
|
+
//------------------------------------------------------------
|
|
2046
|
+
declare bypass2 author "Julius Smith";
|
|
2047
|
+
// License: STK-4.3
|
|
2048
|
+
|
|
2049
|
+
bypass2(bpc,e) = _,_ <: ((inswitch:e),_,_) : select2stereo(bpc)
|
|
2050
|
+
with {
|
|
2051
|
+
inswitch = _,_ : (select2(bpc,_,0), select2(bpc,_,0)) : _,_;
|
|
2052
|
+
};
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
//-------------------`(ba.)bypass1to2`-------------------------
|
|
2056
|
+
// Bypass switch for effect `e` having mono input signal and stereo output.
|
|
2057
|
+
// Effect `e` is bypassed if `bpc = 1`.When bypassed, `e` is feed with zeros
|
|
2058
|
+
// so that its state is cleanup up.
|
|
2059
|
+
// `bypass1to2` is a standard Faust function.
|
|
2060
|
+
//
|
|
2061
|
+
// #### Usage
|
|
2062
|
+
//
|
|
2063
|
+
// ```
|
|
2064
|
+
// _ : bypass1to2(bpc,e) : _,_
|
|
2065
|
+
// ```
|
|
2066
|
+
//
|
|
2067
|
+
// Where:
|
|
2068
|
+
//
|
|
2069
|
+
// * `bpc`: bypass switch (0/1)
|
|
2070
|
+
// * `e`: a mono-to-stereo effect
|
|
2071
|
+
//------------------------------------------------------------
|
|
2072
|
+
declare bypass1to2 author "Julius Smith";
|
|
2073
|
+
// License: STK-4.3
|
|
2074
|
+
|
|
2075
|
+
bypass1to2(bpc,e) = _ <: ((inswitch:e),_,_) : select2stereo(bpc)
|
|
2076
|
+
with {
|
|
2077
|
+
inswitch = select2(bpc,_,0);
|
|
2078
|
+
};
|
|
2079
|
+
|
|
2080
|
+
|
|
2081
|
+
//-------------------`(ba.)bypass_fade`-------------------------
|
|
2082
|
+
// Bypass an arbitrary (N x N) circuit with 'n' samples crossfade.
|
|
2083
|
+
// Inputs and outputs signals are faded out when 'e' is bypassed,
|
|
2084
|
+
// so that 'e' state is cleanup up.
|
|
2085
|
+
// Once bypassed the effect is replaced by `par(i,N,_)`.
|
|
2086
|
+
// Bypassed circuits can be chained.
|
|
2087
|
+
//
|
|
2088
|
+
// #### Usage
|
|
2089
|
+
//
|
|
2090
|
+
// ```
|
|
2091
|
+
// _ : bypass_fade(n,b,e) : _
|
|
2092
|
+
// or
|
|
2093
|
+
// _,_ : bypass_fade(n,b,e) : _,_
|
|
2094
|
+
// ```
|
|
2095
|
+
// * `n`: number of samples for the crossfade
|
|
2096
|
+
// * `b`: bypass switch (0/1)
|
|
2097
|
+
// * `e`: N x N circuit
|
|
2098
|
+
//
|
|
2099
|
+
// #### Example test program
|
|
2100
|
+
//
|
|
2101
|
+
// ```
|
|
2102
|
+
// process = bypass_fade(ma.SR/10, checkbox("bypass echo"), echo);
|
|
2103
|
+
// process = bypass_fade(ma.SR/10, checkbox("bypass reverb"), freeverb);
|
|
2104
|
+
// ```
|
|
2105
|
+
//---------------------------------------------------------------
|
|
2106
|
+
bypass_fade(n, b, e) = par(i, ins, _)
|
|
2107
|
+
<: (par(i, ins, *(1-xb)) : e : par(i, outs, *(1-xb))), par(i, ins, *(xb))
|
|
2108
|
+
:> par(i, outs, _)
|
|
2109
|
+
with {
|
|
2110
|
+
ins = inputs(e);
|
|
2111
|
+
outs = outputs(e);
|
|
2112
|
+
xb = ramp(n, b);
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
//----------------------------`(ba.)toggle`------------------------------------------
|
|
2117
|
+
// Triggered by the change of 0 to 1, it toggles the output value
|
|
2118
|
+
// between 0 and 1.
|
|
2119
|
+
//
|
|
2120
|
+
// #### Usage
|
|
2121
|
+
//
|
|
2122
|
+
// ```
|
|
2123
|
+
// _ : toggle : _
|
|
2124
|
+
// ```
|
|
2125
|
+
// #### Example test program
|
|
2126
|
+
//
|
|
2127
|
+
// ```
|
|
2128
|
+
// button("toggle") : toggle : vbargraph("output", 0, 1)
|
|
2129
|
+
// (an.amp_follower(0.1) > 0.01) : toggle : vbargraph("output", 0, 1) // takes audio input
|
|
2130
|
+
// ```
|
|
2131
|
+
//
|
|
2132
|
+
//------------------------------------------------------------------------------
|
|
2133
|
+
declare toggle author "Vince";
|
|
2134
|
+
|
|
2135
|
+
toggle = trig : loop
|
|
2136
|
+
with {
|
|
2137
|
+
trig(x) = (x-x') == 1;
|
|
2138
|
+
loop = != ~ _;
|
|
2139
|
+
};
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
//----------------------------`(ba.)on_and_off`------------------------------------------
|
|
2143
|
+
// The first channel set the output to 1, the second channel to 0.
|
|
2144
|
+
//
|
|
2145
|
+
// #### Usage
|
|
2146
|
+
//
|
|
2147
|
+
// ```
|
|
2148
|
+
// _,_ : on_and_off : _
|
|
2149
|
+
// ```
|
|
2150
|
+
//
|
|
2151
|
+
// #### Example test program
|
|
2152
|
+
//
|
|
2153
|
+
// ```
|
|
2154
|
+
// button("on"), button("off") : on_and_off : vbargraph("output", 0, 1)
|
|
2155
|
+
// ```
|
|
2156
|
+
//
|
|
2157
|
+
//------------------------------------------------------------------------------
|
|
2158
|
+
declare on_and_off author "Vince";
|
|
2159
|
+
|
|
2160
|
+
on_and_off(a, b) = (a : trig) : loop(b)
|
|
2161
|
+
with {
|
|
2162
|
+
trig(x) = (x-x') == 1;
|
|
2163
|
+
loop(b) = + ~ (_ >= 1) * ((b : trig) == 0);
|
|
2164
|
+
};
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
//----------------------------`(ba.)bitcrusher`------------------------------------------
|
|
2168
|
+
// Produce distortion by reduction of the signal resolution.
|
|
2169
|
+
//
|
|
2170
|
+
// #### Usage
|
|
2171
|
+
//
|
|
2172
|
+
// ```
|
|
2173
|
+
// _ : bitcrusher(nbits) : _
|
|
2174
|
+
// ```
|
|
2175
|
+
//
|
|
2176
|
+
// Where:
|
|
2177
|
+
//
|
|
2178
|
+
// * `nbits`: the number of bits of the wanted resolution
|
|
2179
|
+
//
|
|
2180
|
+
//------------------------------------------------------------------------------
|
|
2181
|
+
declare bitcrusher author "Julius O. Smith III, revised by Stephane Letz";
|
|
2182
|
+
|
|
2183
|
+
bitcrusher(nbits,x) = round(x * scaler) / scaler
|
|
2184
|
+
with {
|
|
2185
|
+
scaler = float(2^nbits - 1);
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
//=================================Sliding Reduce=========================================
|
|
2190
|
+
// Provides various operations on the last n samples using a high order
|
|
2191
|
+
// `slidingReduce(op,n,maxN,disabledVal,x)` fold-like function:
|
|
2192
|
+
//
|
|
2193
|
+
// * `slidingSum(n)`: the sliding sum of the last n input samples, CPU-light
|
|
2194
|
+
// * `slidingSump(n,maxN)`: the sliding sum of the last n input samples, numerically stable "forever"
|
|
2195
|
+
// * `slidingMax(n,maxN)`: the sliding max of the last n input samples
|
|
2196
|
+
// * `slidingMin(n,maxN)`: the sliding min of the last n input samples
|
|
2197
|
+
// * `slidingMean(n)`: the sliding mean of the last n input samples, CPU-light
|
|
2198
|
+
// * `slidingMeanp(n,maxN)`: the sliding mean of the last n input samples, numerically stable "forever"
|
|
2199
|
+
// * `slidingRMS(n)`: the sliding RMS of the last n input samples, CPU-light
|
|
2200
|
+
// * `slidingRMSp(n,maxN)`: the sliding RMS of the last n input samples, numerically stable "forever"
|
|
2201
|
+
//
|
|
2202
|
+
// #### Working Principle
|
|
2203
|
+
//
|
|
2204
|
+
// If we want the maximum of the last 8 values, we can do that as:
|
|
2205
|
+
//
|
|
2206
|
+
// ```
|
|
2207
|
+
// simpleMax(x) =
|
|
2208
|
+
// (
|
|
2209
|
+
// (
|
|
2210
|
+
// max(x@0,x@1),
|
|
2211
|
+
// max(x@2,x@3)
|
|
2212
|
+
// ) :max
|
|
2213
|
+
// ),
|
|
2214
|
+
// (
|
|
2215
|
+
// (
|
|
2216
|
+
// max(x@4,x@5),
|
|
2217
|
+
// max(x@6,x@7)
|
|
2218
|
+
// ) :max
|
|
2219
|
+
// )
|
|
2220
|
+
// :max;
|
|
2221
|
+
// ```
|
|
2222
|
+
//
|
|
2223
|
+
// `max(x@2,x@3)` is the same as `max(x@0,x@1)@2` but the latter re-uses a
|
|
2224
|
+
// value we already computed,so is more efficient. Using the same trick for
|
|
2225
|
+
// values 4 trough 7, we can write:
|
|
2226
|
+
//
|
|
2227
|
+
// ```
|
|
2228
|
+
// efficientMax(x)=
|
|
2229
|
+
// (
|
|
2230
|
+
// (
|
|
2231
|
+
// max(x@0,x@1),
|
|
2232
|
+
// max(x@0,x@1)@2
|
|
2233
|
+
// ) :max
|
|
2234
|
+
// ),
|
|
2235
|
+
// (
|
|
2236
|
+
// (
|
|
2237
|
+
// max(x@0,x@1),
|
|
2238
|
+
// max(x@0,x@1)@2
|
|
2239
|
+
// ) :max@4
|
|
2240
|
+
// )
|
|
2241
|
+
// :max;
|
|
2242
|
+
// ```
|
|
2243
|
+
//
|
|
2244
|
+
// We can rewrite it recursively, so it becomes possible to get the maximum at
|
|
2245
|
+
// have any number of values, as long as it's a power of 2.
|
|
2246
|
+
//
|
|
2247
|
+
// ```
|
|
2248
|
+
// recursiveMax =
|
|
2249
|
+
// case {
|
|
2250
|
+
// (1,x) => x;
|
|
2251
|
+
// (N,x) => max(recursiveMax(N/2,x), recursiveMax(N/2,x)@(N/2));
|
|
2252
|
+
// };
|
|
2253
|
+
// ```
|
|
2254
|
+
//
|
|
2255
|
+
// What if we want to look at a number of values that's not a power of 2?
|
|
2256
|
+
// For each value, we will have to decide whether to use it or not.
|
|
2257
|
+
// If n is bigger than the index of the value, we use it, otherwise we replace
|
|
2258
|
+
// it with (`0-(ma.MAX)`):
|
|
2259
|
+
//
|
|
2260
|
+
// ```
|
|
2261
|
+
// variableMax(n,x) =
|
|
2262
|
+
// max(
|
|
2263
|
+
// max(
|
|
2264
|
+
// (
|
|
2265
|
+
// (x@0 : useVal(0)),
|
|
2266
|
+
// (x@1 : useVal(1))
|
|
2267
|
+
// ):max,
|
|
2268
|
+
// (
|
|
2269
|
+
// (x@2 : useVal(2)),
|
|
2270
|
+
// (x@3 : useVal(3))
|
|
2271
|
+
// ):max
|
|
2272
|
+
// ),
|
|
2273
|
+
// max(
|
|
2274
|
+
// (
|
|
2275
|
+
// (x@4 : useVal(4)),
|
|
2276
|
+
// (x@5 : useVal(5))
|
|
2277
|
+
// ):max,
|
|
2278
|
+
// (
|
|
2279
|
+
// (x@6 : useVal(6)),
|
|
2280
|
+
// (x@7 : useVal(7))
|
|
2281
|
+
// ):max
|
|
2282
|
+
// )
|
|
2283
|
+
// )
|
|
2284
|
+
// with {
|
|
2285
|
+
// useVal(i) = select2((n>=i) , (0-(ma.MAX)),_);
|
|
2286
|
+
// };
|
|
2287
|
+
// ```
|
|
2288
|
+
//
|
|
2289
|
+
// Now it becomes impossible to re-use any values. To fix that let's first look
|
|
2290
|
+
// at how we'd implement it using recursiveMax, but with a fixed n that is not
|
|
2291
|
+
// a power of 2. For example, this is how you'd do it with `n=3`:
|
|
2292
|
+
//
|
|
2293
|
+
// ```
|
|
2294
|
+
// binaryMaxThree(x) =
|
|
2295
|
+
// (
|
|
2296
|
+
// recursiveMax(1,x)@0, // the first x
|
|
2297
|
+
// recursiveMax(2,x)@1 // the second and third x
|
|
2298
|
+
// ):max;
|
|
2299
|
+
// ```
|
|
2300
|
+
//
|
|
2301
|
+
// `n=6`
|
|
2302
|
+
//
|
|
2303
|
+
// ```
|
|
2304
|
+
// binaryMaxSix(x) =
|
|
2305
|
+
// (
|
|
2306
|
+
// recursiveMax(2,x)@0, // first two
|
|
2307
|
+
// recursiveMax(4,x)@2 // third trough sixth
|
|
2308
|
+
// ):max;
|
|
2309
|
+
// ```
|
|
2310
|
+
//
|
|
2311
|
+
// Note that `recursiveMax(2,x)` is used at a different delay then in
|
|
2312
|
+
// `binaryMaxThree`, since it represents 1 and 2, not 2 and 3. Each block is
|
|
2313
|
+
// delayed the combined size of the previous blocks.
|
|
2314
|
+
//
|
|
2315
|
+
// `n=7`
|
|
2316
|
+
//
|
|
2317
|
+
// ```
|
|
2318
|
+
// binaryMaxSeven(x) =
|
|
2319
|
+
// (
|
|
2320
|
+
// (
|
|
2321
|
+
// recursiveMax(1,x)@0, // first x
|
|
2322
|
+
// recursiveMax(2,x)@1 // second and third
|
|
2323
|
+
// ):max,
|
|
2324
|
+
// (
|
|
2325
|
+
// recursiveMax(4,x)@3 // fourth trough seventh
|
|
2326
|
+
// )
|
|
2327
|
+
// ):max;
|
|
2328
|
+
// ```
|
|
2329
|
+
//
|
|
2330
|
+
// To make a variable version, we need to know which powers of two are used,
|
|
2331
|
+
// and at which delay time.
|
|
2332
|
+
//
|
|
2333
|
+
// Then it becomes a matter of:
|
|
2334
|
+
//
|
|
2335
|
+
// * lining up all the different block sizes in parallel: `sequentialOperatorParOut()`
|
|
2336
|
+
// * delaying each the appropriate amount: `sumOfPrevBlockSizes()`
|
|
2337
|
+
// * turning it on or off: `useVal()`
|
|
2338
|
+
// * getting the maximum of all of them: `parallelOp()`
|
|
2339
|
+
//
|
|
2340
|
+
// In Faust, we can only do that for a fixed maximum number of values: `maxN`, known at compile time.
|
|
2341
|
+
|
|
2342
|
+
//========================================================================================
|
|
2343
|
+
// Section contributed by Bart Brouns (bart@magnetophon.nl).
|
|
2344
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2345
|
+
// Copyright (C) 2018 Bart Brouns
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
//-----------------------------`(ba.)slidingReduce`-----------------------------
|
|
2349
|
+
// Fold-like high order function. Apply a commutative binary operation `op` to
|
|
2350
|
+
// the last `n` consecutive samples of a signal `x`. For example :
|
|
2351
|
+
// `slidingReduce(max,128,128,0-(ma.MAX))` will compute the maximum of the last
|
|
2352
|
+
// 128 samples. The output is updated each sample, unlike reduce, where the
|
|
2353
|
+
// output is constant for the duration of a block.
|
|
2354
|
+
//
|
|
2355
|
+
// #### Usage
|
|
2356
|
+
//
|
|
2357
|
+
// ```
|
|
2358
|
+
// _ : slidingReduce(op,n,maxN,disabledVal) : _
|
|
2359
|
+
// ```
|
|
2360
|
+
//
|
|
2361
|
+
// Where:
|
|
2362
|
+
//
|
|
2363
|
+
// * `n`: the number of values to process
|
|
2364
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2365
|
+
// * `op`: the operator. Needs to be a commutative one.
|
|
2366
|
+
// * `disabledVal`: the value to use when we want to ignore a value.
|
|
2367
|
+
//
|
|
2368
|
+
// In other words, `op(x,disabledVal)` should equal to `x`. For example,
|
|
2369
|
+
// `+(x,0)` equals `x` and `min(x,ma.MAX)` equals `x`. So if we want to
|
|
2370
|
+
// calculate the sum, we need to give 0 as `disabledVal`, and if we want the
|
|
2371
|
+
// minimum, we need to give `ma.MAX` as `disabledVal`.
|
|
2372
|
+
//------------------------------------------------------------------------------
|
|
2373
|
+
slidingReduce(op,n,0,disabledVal) = 0:!;
|
|
2374
|
+
slidingReduce(op,n,1,disabledVal) = _;
|
|
2375
|
+
slidingReduce(op,n,maxN,disabledVal) =
|
|
2376
|
+
sequentialOperatorParOut(maxNrBits(maxN)-1,op) : par(i, maxNrBits(maxN), _@sumOfPrevBlockSizes(i) : useVal(i)) : parallelOp(op, maxNrBits(maxN))
|
|
2377
|
+
with {
|
|
2378
|
+
sequentialOperatorParOut(N,op) = seq(i, N, operator(i));
|
|
2379
|
+
operator(i) = si.bus(i), (_<: _ , op(_,_@(pow2(i))));
|
|
2380
|
+
|
|
2381
|
+
// The sum of all the sizes of the previous blocks
|
|
2382
|
+
sumOfPrevBlockSizes(0) = 0;
|
|
2383
|
+
sumOfPrevBlockSizes(i) = (ba.subseq((allBlockSizes),0,i):>_);
|
|
2384
|
+
|
|
2385
|
+
allBlockSizes = par(i, maxNrBits(maxN-1), (pow2(i)) * isUsed(i));
|
|
2386
|
+
maxNrBits(n) = int2nrOfBits(n);
|
|
2387
|
+
|
|
2388
|
+
// Decide wether or not to use a certain value, based on n
|
|
2389
|
+
useVal(i) = select2(isUsed(i), disabledVal, _);
|
|
2390
|
+
|
|
2391
|
+
isUsed(i) = ba.take(i+1, (int2bin(n,(maxN-1)*2+1)));
|
|
2392
|
+
pow2(i) = 1<<i;
|
|
2393
|
+
// same as:
|
|
2394
|
+
// pow2(i) = int(pow(2,i));
|
|
2395
|
+
// but in the block diagram, it will be displayed as a number, instead of a formula
|
|
2396
|
+
|
|
2397
|
+
// convert n into a list of ones and zeros
|
|
2398
|
+
int2bin(n,maxN) = par(j, maxNrBits(maxN-1), int(floor((n)/(pow2(j))))%2);
|
|
2399
|
+
// calculate how many ones and zeros are needed to represent maxN
|
|
2400
|
+
int2nrOfBits(n) = int(floor(log(n)/log(2))+1);
|
|
2401
|
+
};
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
//------------------------------`(ba.)slidingSum`------------------------------
|
|
2405
|
+
// The sliding sum of the last n input samples.
|
|
2406
|
+
//
|
|
2407
|
+
// It will eventually run into numerical trouble when there is a persistent dc component.
|
|
2408
|
+
// If that matters in your application, use the more CPU-intensive `ba.slidingSump`.
|
|
2409
|
+
//
|
|
2410
|
+
// #### Usage
|
|
2411
|
+
//
|
|
2412
|
+
// ```
|
|
2413
|
+
// _ : slidingSum(n) : _
|
|
2414
|
+
// ```
|
|
2415
|
+
//
|
|
2416
|
+
// Where:
|
|
2417
|
+
//
|
|
2418
|
+
// * `n`: the number of values to process
|
|
2419
|
+
//------------------------------------------------------------------------------
|
|
2420
|
+
slidingSum(n) = fi.integrator <: _, _@int(max(0,n)) :> -;
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
//------------------------------`(ba.)slidingSump`------------------------------
|
|
2424
|
+
// The sliding sum of the last n input samples.
|
|
2425
|
+
//
|
|
2426
|
+
// It uses a lot more CPU than `ba.slidingSum`, but is numerically stable "forever" in return.
|
|
2427
|
+
//
|
|
2428
|
+
// #### Usage
|
|
2429
|
+
//
|
|
2430
|
+
// ```
|
|
2431
|
+
// _ : slidingSump(n,maxN) : _
|
|
2432
|
+
// ```
|
|
2433
|
+
//
|
|
2434
|
+
// Where:
|
|
2435
|
+
//
|
|
2436
|
+
// * `n`: the number of values to process
|
|
2437
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2438
|
+
//------------------------------------------------------------------------------
|
|
2439
|
+
slidingSump(n,maxN) = slidingReduce(+,n,maxN,0);
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
//----------------------------`(ba.)slidingMax`--------------------------------
|
|
2443
|
+
// The sliding maximum of the last n input samples.
|
|
2444
|
+
//
|
|
2445
|
+
// #### Usage
|
|
2446
|
+
//
|
|
2447
|
+
// ```
|
|
2448
|
+
// _ : slidingMax(n,maxN) : _
|
|
2449
|
+
// ```
|
|
2450
|
+
//
|
|
2451
|
+
// Where:
|
|
2452
|
+
//
|
|
2453
|
+
// * `n`: the number of values to process
|
|
2454
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2455
|
+
//------------------------------------------------------------------------------
|
|
2456
|
+
slidingMax(n,maxN) = slidingReduce(max,n,maxN,0-(ma.MAX));
|
|
2457
|
+
|
|
2458
|
+
//----------------------------`(ba.)slidingMin`--------------------------------
|
|
2459
|
+
// The sliding minimum of the last n input samples.
|
|
2460
|
+
//
|
|
2461
|
+
// #### Usage
|
|
2462
|
+
//
|
|
2463
|
+
// ```
|
|
2464
|
+
// _ : slidingMin(n,maxN) : _
|
|
2465
|
+
// ```
|
|
2466
|
+
//
|
|
2467
|
+
// Where:
|
|
2468
|
+
//
|
|
2469
|
+
// * `n`: the number of values to process
|
|
2470
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2471
|
+
//------------------------------------------------------------------------------
|
|
2472
|
+
slidingMin(n,maxN) = slidingReduce(min,n,maxN,ma.MAX);
|
|
2473
|
+
|
|
2474
|
+
|
|
2475
|
+
//----------------------------`(ba.)slidingMean`-------------------------------
|
|
2476
|
+
// The sliding mean of the last n input samples.
|
|
2477
|
+
//
|
|
2478
|
+
// It will eventually run into numerical trouble when there is a persistent dc component.
|
|
2479
|
+
// If that matters in your application, use the more CPU-intensive `ba.slidingMeanp`.
|
|
2480
|
+
//
|
|
2481
|
+
// #### Usage
|
|
2482
|
+
//
|
|
2483
|
+
// ```
|
|
2484
|
+
// _ : slidingMean(n) : _
|
|
2485
|
+
// ```
|
|
2486
|
+
//
|
|
2487
|
+
// Where:
|
|
2488
|
+
//
|
|
2489
|
+
// * `n`: the number of values to process
|
|
2490
|
+
//------------------------------------------------------------------------------
|
|
2491
|
+
slidingMean(n) = slidingSum(n)/n;
|
|
2492
|
+
|
|
2493
|
+
|
|
2494
|
+
//----------------------------`(ba.)slidingMeanp`-------------------------------
|
|
2495
|
+
// The sliding mean of the last n input samples.
|
|
2496
|
+
//
|
|
2497
|
+
// It uses a lot more CPU than `ba.slidingMean`, but is numerically stable "forever" in return.
|
|
2498
|
+
//
|
|
2499
|
+
// #### Usage
|
|
2500
|
+
//
|
|
2501
|
+
// ```
|
|
2502
|
+
// _ : slidingMeanp(n,maxN) : _
|
|
2503
|
+
// ```
|
|
2504
|
+
//
|
|
2505
|
+
// Where:
|
|
2506
|
+
//
|
|
2507
|
+
// * `n`: the number of values to process
|
|
2508
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2509
|
+
//------------------------------------------------------------------------------
|
|
2510
|
+
slidingMeanp(n,maxN) = slidingSump(n,maxN)/n;
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
//---------------------------`(ba.)slidingRMS`---------------------------------
|
|
2514
|
+
// The root mean square of the last n input samples.
|
|
2515
|
+
//
|
|
2516
|
+
// It will eventually run into numerical trouble when there is a persistent dc component.
|
|
2517
|
+
// If that matters in your application, use the more CPU-intensive `ba.slidingRMSp`.
|
|
2518
|
+
|
|
2519
|
+
//
|
|
2520
|
+
// #### Usage
|
|
2521
|
+
//
|
|
2522
|
+
// ```
|
|
2523
|
+
// _ : slidingRMS(n) : _
|
|
2524
|
+
// ```
|
|
2525
|
+
//
|
|
2526
|
+
// Where:
|
|
2527
|
+
//
|
|
2528
|
+
// * `n`: the number of values to process
|
|
2529
|
+
//------------------------------------------------------------------------------
|
|
2530
|
+
slidingRMS(n) = pow(2) : slidingMean(n) : sqrt;
|
|
2531
|
+
|
|
2532
|
+
|
|
2533
|
+
//---------------------------`(ba.)slidingRMSp`---------------------------------
|
|
2534
|
+
// The root mean square of the last n input samples.
|
|
2535
|
+
//
|
|
2536
|
+
// It uses a lot more CPU than `ba.slidingRMS`, but is numerically stable "forever" in return.
|
|
2537
|
+
//
|
|
2538
|
+
// #### Usage
|
|
2539
|
+
//
|
|
2540
|
+
// ```
|
|
2541
|
+
// _ : slidingRMSp(n,maxN) : _
|
|
2542
|
+
// ```
|
|
2543
|
+
//
|
|
2544
|
+
// Where:
|
|
2545
|
+
//
|
|
2546
|
+
// * `n`: the number of values to process
|
|
2547
|
+
// * `maxN`: the maximum number of values to process (int, known at compile time, maxN > 0)
|
|
2548
|
+
//------------------------------------------------------------------------------
|
|
2549
|
+
slidingRMSp(n,maxn) = pow(2) : slidingMeanp(n,maxn) : sqrt;
|
|
2550
|
+
|
|
2551
|
+
|
|
2552
|
+
//========================================================================================
|
|
2553
|
+
// section contributed by Bart Brouns (bart@magnetophon.nl).
|
|
2554
|
+
// spdx-license-identifier: gpl-3.0
|
|
2555
|
+
// copyright (c) 2020 Bart Brouns
|
|
2556
|
+
|
|
2557
|
+
//=================================Parallel Operators=========================================
|
|
2558
|
+
// Provides various operations on N parallel inputs using a high order
|
|
2559
|
+
// `parallelOp(op,N,x)` function:
|
|
2560
|
+
//
|
|
2561
|
+
// * `parallelMax(N)`: the max of n parallel inputs
|
|
2562
|
+
// * `parallelMin(N)`: the min of n parallel inputs
|
|
2563
|
+
// * `parallelMean(N)`: the mean of n parallel inputs
|
|
2564
|
+
// * `parallelRMS(N)`: the RMS of n parallel inputs
|
|
2565
|
+
|
|
2566
|
+
//-----------------------------`(ba.)parallelOp`-----------------------------
|
|
2567
|
+
// Apply a commutative binary operation `op` to N parallel inputs.
|
|
2568
|
+
//
|
|
2569
|
+
// #### usage
|
|
2570
|
+
//
|
|
2571
|
+
// ```
|
|
2572
|
+
// si.bus(N) : parallelOp(op,N) : _
|
|
2573
|
+
// ```
|
|
2574
|
+
//
|
|
2575
|
+
// where:
|
|
2576
|
+
//
|
|
2577
|
+
// * `N`: the number of parallel inputs known at compile time
|
|
2578
|
+
// * `op`: the operator which needs to be commutative
|
|
2579
|
+
//
|
|
2580
|
+
//------------------------------------------------------------------------------
|
|
2581
|
+
|
|
2582
|
+
parallelOp(op,1) = _;
|
|
2583
|
+
parallelOp(op,2) = op;
|
|
2584
|
+
parallelOp(op,n) = op(parallelOp(op,n-1));
|
|
2585
|
+
|
|
2586
|
+
declare parallelOp author "Bart Brouns";
|
|
2587
|
+
declare parallelOp licence "GPL-3.0";
|
|
2588
|
+
declare parallelOp copyright "Copyright (c) 2020 Bart Brouns <bart@magnetophon.nl>";
|
|
2589
|
+
|
|
2590
|
+
|
|
2591
|
+
//---------------------------`(ba.)parallelMax`---------------------------------
|
|
2592
|
+
// The maximum of N parallel inputs.
|
|
2593
|
+
//
|
|
2594
|
+
// #### Usage
|
|
2595
|
+
//
|
|
2596
|
+
// ```
|
|
2597
|
+
// si.bus(N) : parallelMax(N) : _
|
|
2598
|
+
// ```
|
|
2599
|
+
//
|
|
2600
|
+
// Where:
|
|
2601
|
+
//
|
|
2602
|
+
// * `N`: the number of parallel inputs known at compile time
|
|
2603
|
+
//------------------------------------------------------------------------------
|
|
2604
|
+
parallelMax(n) = parallelOp(max,n);
|
|
2605
|
+
|
|
2606
|
+
declare parallelMax author "Bart Brouns";
|
|
2607
|
+
declare parallelMax licence "GPL-3.0";
|
|
2608
|
+
declare parallelMax copyright "Copyright (c) 2020 Bart Brouns <bart@magnetophon.nl>";
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
//---------------------------`(ba.)parallelMin`---------------------------------
|
|
2612
|
+
// The minimum of N parallel inputs.
|
|
2613
|
+
//
|
|
2614
|
+
// #### Usage
|
|
2615
|
+
//
|
|
2616
|
+
// ```
|
|
2617
|
+
// si.bus(N) : parallelMin(N) : _
|
|
2618
|
+
// ```
|
|
2619
|
+
//
|
|
2620
|
+
// Where:
|
|
2621
|
+
//
|
|
2622
|
+
// * `N`: the number of parallel inputs known at compile time
|
|
2623
|
+
//------------------------------------------------------------------------------
|
|
2624
|
+
parallelMin(n) = parallelOp(min,n);
|
|
2625
|
+
|
|
2626
|
+
declare parallelMin author "Bart Brouns";
|
|
2627
|
+
declare parallelMin licence "GPL-3.0";
|
|
2628
|
+
declare parallelMin copyright "Copyright (c) 2020 Bart Brouns <bart@magnetophon.nl>";
|
|
2629
|
+
|
|
2630
|
+
|
|
2631
|
+
//---------------------------`(ba.)parallelMean`---------------------------------
|
|
2632
|
+
// The mean of N parallel inputs.
|
|
2633
|
+
//
|
|
2634
|
+
// #### Usage
|
|
2635
|
+
//
|
|
2636
|
+
// ```
|
|
2637
|
+
// si.bus(N) : parallelMean(N) : _
|
|
2638
|
+
// ```
|
|
2639
|
+
//
|
|
2640
|
+
// Where:
|
|
2641
|
+
//
|
|
2642
|
+
// * `N`: the number of parallel inputs known at compile time
|
|
2643
|
+
//------------------------------------------------------------------------------
|
|
2644
|
+
parallelMean(n) = si.bus(n):>_/n;
|
|
2645
|
+
|
|
2646
|
+
declare parallelMean author "Bart Brouns";
|
|
2647
|
+
declare parallelMean licence "GPL-3.0";
|
|
2648
|
+
declare parallelMean copyright "Copyright (c) 2020 Bart Brouns <bart@magnetophon.nl>";
|
|
2649
|
+
|
|
2650
|
+
//---------------------------`(ba.)parallelRMS`---------------------------------
|
|
2651
|
+
// The RMS of N parallel inputs.
|
|
2652
|
+
//
|
|
2653
|
+
// #### Usage
|
|
2654
|
+
//
|
|
2655
|
+
// ```
|
|
2656
|
+
// si.bus(N) : parallelRMS(N) : _
|
|
2657
|
+
// ```
|
|
2658
|
+
//
|
|
2659
|
+
// Where:
|
|
2660
|
+
//
|
|
2661
|
+
// * `N`: the number of parallel inputs known at compile time
|
|
2662
|
+
//------------------------------------------------------------------------------
|
|
2663
|
+
parallelRMS(n) = par(i, n, pow(2)) : parallelMean(n) : sqrt;
|
|
2664
|
+
|
|
2665
|
+
declare parallelRMS author "Bart Brouns";
|
|
2666
|
+
declare parallelRMS licence "GPL-3.0";
|
|
2667
|
+
declare parallelRMS copyright "Copyright (c) 2020 Bart Brouns <bart@magnetophon.nl>";
|
|
2668
|
+
|
|
2669
|
+
//////////////////////////////////Deprecated Functions////////////////////////////////////
|
|
2670
|
+
// This section implements functions that used to be in music.lib but that are now
|
|
2671
|
+
// considered as "deprecated".
|
|
2672
|
+
//////////////////////////////////////////////////////////////////////////////////////////
|
|
2673
|
+
|
|
2674
|
+
millisec = ma.SR/1000.0;
|
|
2675
|
+
|
|
2676
|
+
time1s = hslider("time", 0, 0, 1000, 0.1)*millisec;
|
|
2677
|
+
time2s = hslider("time", 0, 0, 2000, 0.1)*millisec;
|
|
2678
|
+
time5s = hslider("time", 0, 0, 5000, 0.1)*millisec;
|
|
2679
|
+
time10s = hslider("time", 0, 0, 10000, 0.1)*millisec;
|
|
2680
|
+
time21s = hslider("time", 0, 0, 21000, 0.1)*millisec;
|
|
2681
|
+
time43s = hslider("time", 0, 0, 43000, 0.1)*millisec;
|