Skip to content

Commit

Permalink
Add initial support for SFZ filter opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Bullock committed Sep 29, 2017
1 parent 9f72ce7 commit 928cabe
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
38 changes: 38 additions & 0 deletions module/SFZero/SFZero/SFZReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ void SFZReader::read(const char* text, unsigned int length)
buildingRegion->ampeg_veltrack.sustain = value.getFloatValue();
else if (opcode == "ampeg_vel2release")
buildingRegion->ampeg_veltrack.release = value.getFloatValue();
else if (opcode == "fil_type")
buildingRegion->fil_type = static_cast<SFZRegion::FilterType>(filterTypeValue(value));
else if (opcode == "cutoff")
buildingRegion->initialFilterFc = value.getIntValue();
else if (opcode == "fileg_depth")
buildingRegion->modEnvToFilterFc = value.getIntValue();
else if (opcode == "resonance")
buildingRegion->initialFilterQ = value.getIntValue();
else if (opcode == "fileg_delay")
buildingRegion->modeg.delay = value.getFloatValue();
else if (opcode == "fileg_start")
buildingRegion->modeg.start = value.getFloatValue();
else if (opcode == "fileg_attack")
buildingRegion->modeg.attack = value.getFloatValue();
else if (opcode == "fileg_decay")
buildingRegion->modeg.decay = value.getFloatValue();
else if (opcode == "fileg_sustain")
buildingRegion->modeg.sustain = value.getFloatValue();
else if (opcode == "fileg_hold")
buildingRegion->modeg.hold = value.getFloatValue();
else if (opcode == "fileg_release")
buildingRegion->modeg.release = value.getFloatValue();
else if (opcode == "default_path")
error("\"default_path\" outside of <control> tag");
else
Expand Down Expand Up @@ -416,6 +438,22 @@ int SFZReader::loopModeValue(const String& str)
return SFZRegion::sample_loop;
}

int SFZReader::filterTypeValue(const String& str)
{
if (str == "lpf_1p")
return SFZRegion::lpf_1p;
if (str == "hpf_1p")
return SFZRegion::hpf_1p;
if (str == "lpf_2p")
return SFZRegion::lpf_2p;
if (str == "hpf_2p")
return SFZRegion::hpf_2p;
if (str == "bpf_2p")
return SFZRegion::bpf_2p;
if (str == "brf_2p")
return SFZRegion::brf_2p;
return SFZRegion::no_filter;
}

void SFZReader::finishRegion(SFZRegion* region)
{
Expand Down
2 changes: 2 additions & 0 deletions module/SFZero/SFZero/SFZReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class SFZReader {
int keyValue(const String& str);
int triggerValue(const String& str);
int loopModeValue(const String& str);
int filterTypeValue(const String& str);

void finishRegion(SFZRegion* region);
void error(const String& message);
};
Expand Down
6 changes: 5 additions & 1 deletion module/SFZero/SFZero/SFZRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class SFZRegion {
fast, normal
};


enum FilterType {
lpf_1p, hpf_1p, lpf_2p, hpf_2p, bpf_2p, brf_2p, no_filter
};

SFZRegion();
void clear();
void clearForSF2();
Expand Down Expand Up @@ -85,6 +88,7 @@ class SFZRegion {
int freqModLFO, modLfoToPitch, modLfoToFilterFc, modLfoToVolume;
float delayVibLFO;
int freqVibLFO, vibLfoToPitch;
FilterType fil_type;

static inline double timecents2Secs(double timecents) { return pow(2.0, timecents / 1200.0); }
static inline float timecents2Secs(float timecents) { return powf(2.0f, timecents / 1200.0f); }
Expand Down

0 comments on commit 928cabe

Please sign in to comment.