From 556470bcdf8569c17d823d8010c770be5e5d354a Mon Sep 17 00:00:00 2001 From: David Braun <2096055+DBraun@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:20:30 -0500 Subject: [PATCH] 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. --- src/synthesis/producers/sample_source.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/synthesis/producers/sample_source.cpp b/src/synthesis/producers/sample_source.cpp index f31d041..17a348e 100644 --- a/src/synthesis/producers/sample_source.cpp +++ b/src/synthesis/producers/sample_source.cpp @@ -310,11 +310,21 @@ namespace vital { data["length"] = data_->length; data["sample_rate"] = data_->sample_rate; std::unique_ptr pcm_data = std::make_unique(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); data["samples"] = encoded.toStdString(); 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); data["samples_stereo"] = encoded_stereo.toStdString(); }