Commit f4bb788d authored by Lyberta's avatar Lyberta

Added OpenCL pulse plugin.

parent 315a4347
......@@ -21,7 +21,7 @@ plugins: libs
$(MAKE) all -C Src/DPF_TriangleAliased
$(MAKE) all -C Src/DPF_SawtoothAliased
$(MAKE) all -C Src/DPF_Noise
#$(MAKE) all -C Src/DPF_PulseBandlimited
$(MAKE) all -C Src/DPF_PulseBandlimited
$(MAKE) all -C Src/DPF_TriangleBandlimited
$(MAKE) all -C Src/DPF_SawtoothBandlimited
#$(MAKE) all -C Src/DPF_PulseOpenCL
......
#pragma once
#define DISTRHO_PLUGIN_NAME "ftz Pulse OpenCL"
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_URI "https://ftz.lyberta.net/projects/chiptune/pulse_opencl.html"
#define DISTRHO_PLUGIN_IS_SYNTH 1
#!/usr/bin/make -f
# Makefile for DISTRHO Plugins #
# ---------------------------- #
# Created by falkTX
#
# --------------------------------------------------------------
# Project name, used for binaries
NAME = ftz_chiptune_pulse_opencl
# --------------------------------------------------------------
# Files to build
OBJS_DSP = \
Plugin.cpp.o \
../DPF/Utils.cpp.o
OBJS_UI =
# --------------------------------------------------------------
# Do some magic
include ../Makefile.mk
# --------------------------------------------------------------
# Enable all possible plugin types
ifeq ($(HAVE_JACK),true)
TARGETS += jack
endif
ifeq ($(LINUX),true)
TARGETS += dssi_dsp
ifeq ($(HAVE_DGL),true)
ifeq ($(HAVE_LIBLO),true)
TARGETS += dssi_ui
endif
endif
endif
ifeq ($(HAVE_DGL),true)
TARGETS += lv2_sep
else
TARGETS += lv2_dsp
endif
TARGETS += vst
all: $(TARGETS)
# --------------------------------------------------------------
/// \file
/// \brief Source file that contains implementation of the OpenCLPulsePlugin
/// class.
/// \author Lyberta
/// \copyright GNU GPLv3 or any later version.
#include "Plugin.h"
namespace DISTRHO
{
const std::uint32_t NumParameters = 8;
enum class PulseParameterIndex
{
MasterVolume,
Pan,
PitchBendRange,
DutyCycle,
AttackTime,
DecayTime,
SustainLevel,
ReleaseTime
};
BaseParameterIndex ToBaseParameterIndex(std::uint32_t index)
{
switch (static_cast<PulseParameterIndex>(index))
{
case PulseParameterIndex::MasterVolume:
{
return BaseParameterIndex::MasterVolume;
}
case PulseParameterIndex::Pan:
{
return BaseParameterIndex::Pan;
}
case PulseParameterIndex::PitchBendRange:
{
return BaseParameterIndex::PitchBendRange;
}
case PulseParameterIndex::DutyCycle:
{
throw std::out_of_range{"ToBaseParameterIndex: Invalid index."};
}
case PulseParameterIndex::AttackTime:
{
return BaseParameterIndex::AttackTime;
}
case PulseParameterIndex::DecayTime:
{
return BaseParameterIndex::DecayTime;
}
case PulseParameterIndex::SustainLevel:
{
return BaseParameterIndex::SustainLevel;
}
case PulseParameterIndex::ReleaseTime:
{
return BaseParameterIndex::ReleaseTime;
}
}
throw std::out_of_range{"ToBaseParameterIndex: Invalid index."};
}
OpenCLPulsePlugin::OpenCLPulsePlugin()
: PluginBaseTemplate<OpenCLSettings>{NumParameters}
{
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::vector<cl::Device> devices;
platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
synth.emplace(settings, channel,
ftz::Audio::OpenCL::BandlimitedPulseWave<OpenCLSettings::CalcType>::
Settings{{}, devices[0]},
ftz::Audio::Envelope<OpenCLSettings::CalcType>::Settings{});
effects.insert(std::begin(effects), *synth);
}
const char* OpenCLPulsePlugin::getName() const
{
return "ftz Chiptune Pulse OpenCL";
}
const char* OpenCLPulsePlugin::getLabel() const
{
return "ftz Chiptune Pulse OpenCL";
}
const char* OpenCLPulsePlugin::getDescription() const
{
return "Pulse wave synth.";
}
std::int64_t OpenCLPulsePlugin::getUniqueId() const
{
return d_cconst('F', 'C', 'T', '8');
}
void OpenCLPulsePlugin::initParameter(std::uint32_t index,
Parameter& parameter)
{
auto new_index = static_cast<PulseParameterIndex>(index);
if (new_index != PulseParameterIndex::DutyCycle)
{
this->template InitParameter<Synth>(ToBaseParameterIndex(index),
parameter);
return;
}
parameter.hints = kParameterIsAutomable;
parameter.name = "Duty cycle";
parameter.symbol = "duty_cycle";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
parameter.ranges.def = ftz::Audio::DutyCycle<OpenCLSettings::CalcType>{};
}
float OpenCLPulsePlugin::getParameterValue(std::uint32_t index) const
{
auto new_index = static_cast<PulseParameterIndex>(index);
if (new_index != PulseParameterIndex::DutyCycle)
{
return this->GetParameterValue(*synth, ToBaseParameterIndex(index));
}
return synth->GetGeneratorSettings().GetDutyCycle();
}
void OpenCLPulsePlugin::setParameterValue(std::uint32_t index, float value)
{
auto new_index = static_cast<PulseParameterIndex>(index);
if (new_index != PulseParameterIndex::DutyCycle)
{
this->SetParameterValue(*synth, ToBaseParameterIndex(index), value);
return;
}
auto generator_settings = synth->GetGeneratorSettings();
generator_settings.SetDutyCycle(value);
synth->SetGeneratorSettings(std::move(generator_settings));
}
void OpenCLPulsePlugin::sampleRateChanged(double new_sample_rate)
{
this->SampleRateChanged(*synth, new_sample_rate);
}
Plugin* createPlugin()
{
return new OpenCLPulsePlugin{};
}
}
/// \file
/// \brief Header file that describes the OpenCLPulsePlugin class.
/// \author Lyberta
/// \copyright GNU GPLv3 or any later version.
#pragma once
#include <ftz/Audio/OpenCL/BandlimitedPulseWave.h>
#include <ftz/Audio/ParallelPolyphonicSynth.h>
#include "../DPF/PluginBaseTemplate.h"
namespace DISTRHO
{
/// \brief A bandlimited pulse synth plugin using OpenCL.
/// \details This is a DPF wrapper of the bandlimited pulse synth implemented
/// using OpenCL.
class OpenCLPulsePlugin final : public PluginBaseTemplate<OpenCLSettings>
{
public:
/// \brief Constructor.
OpenCLPulsePlugin();
protected:
/// \brief Returns plugin name.
/// \return Plugin name.
const char* getName() const override;
/// \brief Returns plugin label.
/// \return Plugin label.
const char* getLabel() const override;
/// \brief Returns plugin description.
/// \return Plugin description.
const char* getDescription() const override;
/// \brief Returns plugin unique id.
/// \return Plugin unique id.
std::int64_t getUniqueId() const override;
/// \brief Initializes plugin parameter.
/// \param[in] index Index of the parameter.
/// \param[out] parameter Parameter info.
void initParameter(std::uint32_t index, Parameter& parameter) override;
/// \brief Returns the value of the plugin parameter.
/// \param[in] index Index of the parameter.
/// \return Parameter value.
float getParameterValue(std::uint32_t index) const override;
/// \brief Sets the value of the plugin parameter.
/// \param[in] index Index of the parameter.
/// \param[in] value Value to set.
void setParameterValue(std::uint32_t index, float value) override;
/// \brief Called when sample rate has changed.
/// \param[in] new_sample_rate Sample rate to set.
void sampleRateChanged(double new_sample_rate) override;
private:
/// \brief Type of the synth.
using Synth = ftz::Audio::ParallelPolyphonicSynth<
ftz::Audio::OpenCL::BandlimitedPulseWave<OpenCLSettings::CalcType>,
OpenCLSettings::SampleFormat>;
std::optional<Synth> synth; ///< Holds the synth.
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment