ADSR for DPCM
This commit is contained in:
1 parent
1896471e1a
commit
ac3f16155f
2 files changed
+16
-8
No files matched your search
+15
-7
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user