fix bug in sample_source.cpp

Fixes bug https://forum.vital.audio/t/sample-startpoint-bug/16148/5

Now if you load and save a JSON preset in a loop, the JSON doesn't change.
This commit is contained in:
David Braun 2025-01-08 14:20:30 -05:00
parent 809e9a7bff
commit 556470bcdf

View file

@ -310,11 +310,21 @@ namespace vital {
data["length"] = data_->length; data["length"] = data_->length;
data["sample_rate"] = data_->sample_rate; data["sample_rate"] = data_->sample_rate;
std::unique_ptr<int16_t[]> pcm_data = std::make_unique<int16_t[]>(data_->length); std::unique_ptr<int16_t[]> pcm_data = std::make_unique<int16_t[]>(data_->length);
utils::floatToPcmData(pcm_data.get(), data_->left_buffers[kUpsampleTimes].get(), data_->length); // There was an issue where I was loading JSON "A" and immediately saving it to JSON "B" but A!=B.
// It turns out that this kBufferSamples offset was necessary to prevent this issue.
// todo: ask Matt Tytel
utils::floatToPcmData(pcm_data.get(),
data_->left_buffers[kUpsampleTimes].get() + Sample::kBufferSamples, // Add offset
data_->length);
String encoded = Base64::toBase64(pcm_data.get(), sizeof(int16_t) * data_->length); String encoded = Base64::toBase64(pcm_data.get(), sizeof(int16_t) * data_->length);
data["samples"] = encoded.toStdString(); data["samples"] = encoded.toStdString();
if (data_->stereo) { if (data_->stereo) {
utils::floatToPcmData(pcm_data.get(), data_->right_buffers[kUpsampleTimes].get(), data_->length); // There was an issue where I was loading JSON "A" and immediately saving it to JSON "B" but A!=B.
// It turns out that this kBufferSamples offset was necessary to prevent this issue.
// todo: ask Matt Tytel
utils::floatToPcmData(pcm_data.get(),
data_->right_buffers[kUpsampleTimes].get() + Sample::kBufferSamples, // Add offset
data_->length);
String encoded_stereo = Base64::toBase64(pcm_data.get(), sizeof(int16_t) * data_->length); String encoded_stereo = Base64::toBase64(pcm_data.get(), sizeof(int16_t) * data_->length);
data["samples_stereo"] = encoded_stereo.toStdString(); data["samples_stereo"] = encoded_stereo.toStdString();
} }