ADSR for DPCM

This commit is contained in:
maksw committed 2025-04-08 08:15:30 +02:00
1 parent 1896471e1a
commit ac3f16155f
2 files changed
+16 -8

No files matched your search

+15 -7
View File
@@ -31,6 +31,8 @@ struct Wave {
double sweepRate;
double attack;
double decay;
double sustain = 1.0;
double release = 0.0;
std::string samplePath;
std::vector<int16_t> sampleData;
};
@@ -130,6 +132,8 @@ bool loadWaveParams(const std::string& filename, std::vector<Wave>& waves, int&
if (wave.type == DPCM) {
std::string token;
// Skip any comment block
while (ss >> token && token == "/*") {
while (ss >> token && token != "*/");
}
@@ -139,18 +143,22 @@ bool loadWaveParams(const std::string& filename, std::vector<Wave>& waves, int&
continue;
}
// Optional volume
if (!(ss >> wave.volume)) {
wave.volume = 1.0;
}
wave.samplePath = token;
// Optional volume
if (!(ss >> wave.volume)) wave.volume = 1.0;
// Optional ADSR envelope for DPCM
if (!(ss >> wave.attack)) wave.attack = 0.0;
if (!(ss >> wave.decay)) wave.decay = 0.0;
if (!(ss >> wave.sustain)) wave.sustain = 1.0;
if (!(ss >> wave.release)) wave.release = 0.0;
// Not used for DPCM but set anyway
wave.frequency = 0;
wave.dutyCycle = 0.5;
wave.sweepDepth = 0.0;
wave.sweepRate = 0.0;
wave.attack = 0.01;
wave.decay = 0.2;
if (!loadWavFile(wave.samplePath, wave.sampleData)) {
std::cout << "Failed to load sample: " << wave.samplePath << std::endl;
+1 -1
View File
@@ -4,4 +4,4 @@ SINE 0 500 440 1.0 0 3 5 0.05 0.3 // sine with slow vibrato and long decay
TRIANGLE 1000 500 550 0.9 0.5 2 3 0.02 0.25 // triangle with sweep
SQUARE 2000 500 330 0.7 0.25 6 4 0.01 0.2 // square with duty cycle and sweep
NOISE 3000 300 0 0.8 0 0 0 0.02 0.1 // noise burst
DPCM 3900 500 snare.wav 1.0 // dpcm sample 1.0 volume
DPCM 3900 500 snare.wav 0.8 0.01 0.1 0.7 0.2 // with volume + ADSR