add auto-release based on actual sample length and envelope applied during playback instead of after and instead of specifying the DPCM length just use the wav length
This commit is contained in:
1 parent
ac3f16155f
commit
2e1fc43cb4
2 files changed
+16
-6
No files matched your search
+15
-5
@@ -37,17 +37,21 @@ struct Wave {
|
||||
std::vector<int16_t> sampleData;
|
||||
};
|
||||
|
||||
bool loadWavFile(const std::string& path, std::vector<int16_t>& outSamples) {
|
||||
bool loadWavFile(const std::string& path, std::vector<int16_t>& outSamples, int& outDurationMs) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file.is_open()) return false;
|
||||
|
||||
file.seekg(44); // skip header
|
||||
file.seekg(44); // skip header (basic .wav, no format parsing)
|
||||
outSamples.clear();
|
||||
|
||||
int16_t sample;
|
||||
while (file.read(reinterpret_cast<char*>(&sample), sizeof(sample))) {
|
||||
outSamples.push_back(sample);
|
||||
}
|
||||
|
||||
int sampleRate = 44100; // hardcoded for now
|
||||
outDurationMs = static_cast<int>((outSamples.size() * 1000.0) / sampleRate);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,9 +130,8 @@ bool loadWaveParams(const std::string& filename, std::vector<Wave>& waves, int&
|
||||
}
|
||||
|
||||
int start_ms, duration_ms;
|
||||
ss >> start_ms >> duration_ms;
|
||||
ss >> start_ms;
|
||||
wave.start_ms = start_ms;
|
||||
wave.duration_ms = duration_ms;
|
||||
|
||||
if (wave.type == DPCM) {
|
||||
std::string token;
|
||||
@@ -160,14 +163,21 @@ bool loadWaveParams(const std::string& filename, std::vector<Wave>& waves, int&
|
||||
wave.sweepDepth = 0.0;
|
||||
wave.sweepRate = 0.0;
|
||||
|
||||
if (!loadWavFile(wave.samplePath, wave.sampleData)) {
|
||||
int actualLength = 0;
|
||||
if (!loadWavFile(wave.samplePath, wave.sampleData, actualLength)) {
|
||||
std::cout << "Failed to load sample: " << wave.samplePath << std::endl;
|
||||
}
|
||||
|
||||
wave.duration_ms = actualLength;
|
||||
wave.start_ms = start_ms;
|
||||
|
||||
waves.push_back(wave);
|
||||
continue;
|
||||
}
|
||||
|
||||
ss >> duration_ms;
|
||||
wave.duration_ms = duration_ms;
|
||||
|
||||
// Standard wave parameters
|
||||
double volume = 1.0;
|
||||
double duty = 0.5;
|
||||
|
||||
Reference in new issue
Block a user