diff options
author | Damien Zammit <damien@zamaudio.com> | 2018-03-04 23:33:51 +1100 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2018-03-04 23:33:51 +1100 |
commit | 15e5a1b47adb70bb96c0e565da99a87f7bf7a1a0 (patch) | |
tree | 2bdc8d23136b7e599a40fd06c676e8911f03ea1a | |
parent | 68b2969ce1d3258c98706d86f8b100cdf777dbd9 (diff) |
ZamGrains: Add new plugin (no UI yet)
-rw-r--r-- | plugins/ZamGrains/DistrhoPluginInfo.h | 38 | ||||
-rw-r--r-- | plugins/ZamGrains/Makefile | 53 | ||||
-rw-r--r-- | plugins/ZamGrains/ZamGrainsPlugin.cpp | 260 | ||||
-rw-r--r-- | plugins/ZamGrains/ZamGrainsPlugin.hpp | 135 |
4 files changed, 486 insertions, 0 deletions
diff --git a/plugins/ZamGrains/DistrhoPluginInfo.h b/plugins/ZamGrains/DistrhoPluginInfo.h new file mode 100644 index 0000000..0c718ca --- /dev/null +++ b/plugins/ZamGrains/DistrhoPluginInfo.h @@ -0,0 +1,38 @@ +/* + * ZamGrains + * Copyright (C) 2018 Damien Zammit <damien@zamaudio.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define DISTRHO_PLUGIN_BRAND "ZamAudio" +#define DISTRHO_PLUGIN_NAME "ZamGrains" + +#define DISTRHO_PLUGIN_HAS_UI 1 +#define DISTRHO_PLUGIN_IS_SYNTH 0 + +#define DISTRHO_PLUGIN_NUM_INPUTS 1 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 1 + +#define DISTRHO_PLUGIN_WANT_LATENCY 0 +#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 +#define DISTRHO_PLUGIN_WANT_STATE 0 +#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 +#define DISTRHO_PLUGIN_IS_RT_SAFE 1 + +#define DISTRHO_PLUGIN_URI "urn:zamaudio:ZamGrains" +#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:DelayPlugin" + + +#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED diff --git a/plugins/ZamGrains/Makefile b/plugins/ZamGrains/Makefile new file mode 100644 index 0000000..9611c17 --- /dev/null +++ b/plugins/ZamGrains/Makefile @@ -0,0 +1,53 @@ +#!/usr/bin/make -f +# Makefile for zam-plugins # +# ------------------------ # +# Created by falkTX +# + +# -------------------------------------------------------------- +# Project name, used for binaries + +NAME = ZamGrains + +# -------------------------------------------------------------- +# Files to build + +OBJS_DSP = \ + ZamGrainsPlugin.cpp.o + +OBJS_UI = #\ + #ZamGrainsArtwork.cpp.o \ + #ZamGrainsUI.cpp.o + +# -------------------------------------------------------------- +# Do some magic + +include ../Makefile.mk + +# -------------------------------------------------------------- +# Enable all possible plugin types + +ifeq ($(HAVE_JACK),true) +TARGETS += jack +endif + +ifeq ($(LINUX),true) +TARGETS += ladspa +ifeq ($(HAVE_DGL),true) +ifeq ($(HAVE_LIBLO),true) +TARGETS += dssi +endif +endif +endif + +ifeq ($(HAVE_DGL),true) +TARGETS += lv2_sep +else +TARGETS += lv2_dsp +endif + +TARGETS += vst + +all: $(TARGETS) + +# -------------------------------------------------------------- diff --git a/plugins/ZamGrains/ZamGrainsPlugin.cpp b/plugins/ZamGrains/ZamGrainsPlugin.cpp new file mode 100644 index 0000000..7188e2e --- /dev/null +++ b/plugins/ZamGrains/ZamGrainsPlugin.cpp @@ -0,0 +1,260 @@ +/* + * ZamGrains Granular Delay + * Copyright (C) 2018 Damien Zammit <damien@zamaudio.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "ZamGrainsPlugin.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +ZamGrainsPlugin::ZamGrainsPlugin() + : Plugin(paramCount, 1, 0) +{ + // set default values + loadProgram(0); +} + +// ----------------------------------------------------------------------- +// Init + +void ZamGrainsPlugin::initParameter(uint32_t index, Parameter& parameter) +{ + switch (index) + { + case paramDelaytime: + parameter.hints = kParameterIsAutomable; + parameter.name = "Loop time"; + parameter.symbol = "time"; + parameter.unit = "ms"; + parameter.ranges.def = 160.0f; + parameter.ranges.min = 5.0f; + parameter.ranges.max = 1000.0f; + break; + case paramGrains: + parameter.hints = kParameterIsAutomable | kParameterIsInteger; + parameter.name = "Grains"; + parameter.symbol = "grains"; + parameter.unit = " "; + parameter.ranges.def = 1.0f; + parameter.ranges.min = 1.0f; + parameter.ranges.max = 100.0f; + break; + case paramGrainspeed: + parameter.hints = kParameterIsAutomable | kParameterIsLogarithmic; + parameter.name = "Grain Speed"; + parameter.symbol = "gs"; + parameter.unit = " "; + parameter.ranges.def = 1.0f; + parameter.ranges.min = 0.1f; + parameter.ranges.max = 20.f; + break; + case paramPlayspeed: + parameter.hints = kParameterIsAutomable | kParameterIsLogarithmic; + parameter.name = "Play Speed"; + parameter.symbol = "ps"; + parameter.unit = " "; + parameter.ranges.def = 1.0f; + parameter.ranges.min = 0.1f; + parameter.ranges.max = 20.f; + break; + case paramGain: + parameter.hints = kParameterIsAutomable; + parameter.name = "Output Gain"; + parameter.symbol = "gain"; + parameter.unit = "dB"; + parameter.ranges.def = 0.0f; + parameter.ranges.min = -60.0f; + parameter.ranges.max = 0.0f; + break; + } +} + + +void ZamGrainsPlugin::initProgramName(uint32_t index, String& programName) +{ + switch(index) { + case 0: + programName = "Zero"; + break; + } +} + +void ZamGrainsPlugin::loadProgram(uint32_t index) +{ + switch(index) { + case 0: + delaytime = 1000.f; + grainspeed = 1.f; + playspeed = 1.f; + grains = 1.f; + gain = 0.f; + break; + } + + activate(); +} + +// ----------------------------------------------------------------------- +// Internal data + +float ZamGrainsPlugin::getParameterValue(uint32_t index) const +{ + switch (index) + { + case paramDelaytime: + return delaytime; + break; + case paramGrains: + return grains; + break; + case paramGrainspeed: + return grainspeed; + break; + case paramPlayspeed: + return playspeed; + break; + case paramGain: + return gain; + break; + default: + return 0.0f; + } +} + +void ZamGrainsPlugin::setParameterValue(uint32_t index, float value) +{ + switch (index) + { + case paramDelaytime: + delaytime = value; + break; + case paramGrains: + grains = value; + break; + case paramGrainspeed: + grainspeed = value; + break; + case paramPlayspeed: + playspeed = value; + break; + case paramGain: + gain = value; + break; + } +} + +// ----------------------------------------------------------------------- +// Process + +void ZamGrainsPlugin::activate() +{ + int i; + for (i = 0; i < MAX_DELAY; i++) { + z[i] = 0.f; + } + posz = 0; + posrate = 0; + posphasor = 0; + currgrains = 0; + samphold = 0; + samphold2 = 0; + zidx = 0; + zidx2 = 0; + zidxold = 0; + zidx2old = 0; +} + +float ZamGrainsPlugin::sample_and_hold(int ctrl, float input, int *state) { + if (ctrl == 0) + *state = input; + return *state; +} + +float ZamGrainsPlugin::hanning(int pos, int windowsize) +{ + float s = sinf(M_PI * (float)pos / (float)(windowsize - 1)); + return s*s; +} + +void ZamGrainsPlugin::run(const float** inputs, float** outputs, uint32_t frames) +{ + uint32_t i; + float srate = getSampleRate(); + int delaysamples; + float sampz, sampz2; + float xfade; + + int windowsize; + int outofphase; + + delaysamples = (int)(delaytime * srate) / 1000; + windowsize = delaysamples / grains; + + for (i = 0; i < frames; i++) { + z[posz] = inputs[0][i]; + outofphase = (posphasor + windowsize / 2) % windowsize; + zidx = (int)(sample_and_hold(posphasor, (float)posz * playspeed, &samphold) + (float)posphasor * grainspeed); + zidx2 = (int)(sample_and_hold(outofphase, (float)posz * playspeed, &samphold2) + (float)outofphase * grainspeed); + + if (++posphasor >= (unsigned int)windowsize) { + posphasor = 0; + } + + if (zidx >= delaysamples) { + zidx %= (int)(delaysamples); + } + + if (zidx2 >= delaysamples) { + zidx2 %= (int)(delaysamples); + } + + if (++posz >= (unsigned int)delaysamples) { + posz = 0; + } + + + xfade = 1.0f / (float)frames; + sampz = z[zidxold]; + sampz2 = z[zidx2old]; + sampz *= (1.-xfade); + sampz2 *= (1.-xfade); + sampz += z[zidx] * xfade; + sampz2 += z[zidx2] * xfade; + sampz = sanitize_denormal(sampz); + sampz2 = sanitize_denormal(sampz2); + + outputs[0][i] = from_dB(gain) * ( + sampz * hanning(posphasor, windowsize) + + sampz2 * hanning(outofphase, windowsize) + ); + + zidxold = zidx; + zidx2old = zidx2; + } + delaytimeold = delaytime; +} + +// ----------------------------------------------------------------------- + +Plugin* createPlugin() +{ + return new ZamGrainsPlugin(); +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO diff --git a/plugins/ZamGrains/ZamGrainsPlugin.hpp b/plugins/ZamGrains/ZamGrainsPlugin.hpp new file mode 100644 index 0000000..b452e48 --- /dev/null +++ b/plugins/ZamGrains/ZamGrainsPlugin.hpp @@ -0,0 +1,135 @@ +/* + * ZamGrains Granular Delay + * Copyright (C) 2018 Damien Zammit <damien@zamaudio.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef ZAMGRAINSPLUGIN_HPP_INCLUDED +#define ZAMGRAINSPLUGIN_HPP_INCLUDED + +#include "DistrhoPlugin.hpp" + +// 1 second of delay at 192kHz +#define MAX_DELAY 192000 + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------- + +class ZamGrainsPlugin : public Plugin +{ +public: + enum Parameters + { + paramGain = 0, + paramGrains, + paramGrainspeed, + paramPlayspeed, + paramDelaytime, + paramCount + }; + + ZamGrainsPlugin(); + +protected: + // ------------------------------------------------------------------- + // Information + + const char* getLabel() const noexcept override + { + return "ZamGrains"; + } + + const char* getDescription() const noexcept override + { + return "A granular delay plugin"; + } + + const char* getMaker() const noexcept override + { + return "Damien Zammit"; + } + + const char* getHomePage() const noexcept override + { + return "http://www.zamaudio.com"; + } + + const char* getLicense() const noexcept override + { + return "GPL v2+"; + } + + uint32_t getVersion() const noexcept override + { + return d_version(3, 10, 0); + } + + int64_t getUniqueId() const noexcept override + { + return d_cconst('Z', 'M', 'G', 'R'); + } + + // ------------------------------------------------------------------- + // Init + + void initParameter(uint32_t index, Parameter& parameter) override; + void initProgramName(uint32_t index, String& programName) override; + + // ------------------------------------------------------------------- + // Internal data + + float getParameterValue(uint32_t index) const override; + void setParameterValue(uint32_t index, float value) override; + void loadProgram(uint32_t index); + + // ------------------------------------------------------------------- + // Process + + static inline float + sanitize_denormal(float v) { + if(!std::isnormal(v)) + return 0.f; + return v; + } + + static inline float + from_dB(float gdb) { + return (exp(gdb/20.f*log(10.f))); + } + + static inline float + to_dB(float g) { + return (20.f*log10(g)); + } + + void activate() override; + void run(const float** inputs, float** outputs, uint32_t frames) override; + float sample_and_hold(int ctrl, float input, int *state); + float hanning(int pos, int windowsize); + + // ------------------------------------------------------------------- + +private: + int currgrains, zidx, zidx2, zidxold, zidx2old, samphold, samphold2; + float grains, grainspeed, playspeed, delaytime, gain, delaytimeout; + float delaytimeold; + float z[MAX_DELAY]; + unsigned int posz; + unsigned int posphasor, posrate; +}; + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO + +#endif // ZAMGRAINS_HPP_INCLUDED |