audiobackend: fixed bug that sometimes extended the
While we implement an audio cache "truncate" function when the sequence length changes, the render functions also have the ability to extend it. This is fine, but if truncation happened while workers were caching, it could truncate and then extend beyond the length of the sequence. This commit changes the worker extend function to only extend as much as the length, therefore not undoing the truncation.
This commit is contained in:
@@ -66,34 +66,40 @@ void AudioBackend::ThreadCompletedCache(NodeDependency dep, NodeValueTable data,
|
||||
|
||||
int offset = params().time_to_bytes(dep.in());
|
||||
int length = params().time_to_bytes(dep.range().length());
|
||||
int out_point = offset + length;
|
||||
int out_point = qMin(offset + length, params().time_to_bytes(GetSequenceLength()));
|
||||
|
||||
QFile f(CachePathName());
|
||||
if (f.open(QFile::ReadWrite)) {
|
||||
|
||||
if (f.size() < out_point && !f.resize(out_point)) {
|
||||
qCritical() << "Failed to resize file" << CachePathName();
|
||||
if (offset < out_point) {
|
||||
if (offset + length > out_point) {
|
||||
length = out_point - offset;
|
||||
}
|
||||
|
||||
if (!f.seek(offset)) {
|
||||
qCritical() << "Failed to seek file" << CachePathName();
|
||||
QFile f(CachePathName());
|
||||
if (f.open(QFile::ReadWrite)) {
|
||||
|
||||
if (f.size() < out_point && !f.resize(out_point)) {
|
||||
qCritical() << "Failed to resize file" << CachePathName();
|
||||
}
|
||||
|
||||
if (!f.seek(offset)) {
|
||||
qCritical() << "Failed to seek file" << CachePathName();
|
||||
}
|
||||
|
||||
// Replace data with this data
|
||||
int copy_length = qMin(length, cached_samples.size());
|
||||
|
||||
f.write(cached_samples.data(), copy_length);
|
||||
|
||||
if (copy_length < length) {
|
||||
|
||||
// Fill in remainder with silence
|
||||
QByteArray empty_space(length - copy_length, 0);
|
||||
f.write(empty_space);
|
||||
}
|
||||
|
||||
f.close();
|
||||
} else {
|
||||
qWarning() << "Failed to write to cached PCM file";
|
||||
}
|
||||
|
||||
// Replace data with this data
|
||||
int copy_length = qMin(length, cached_samples.size());
|
||||
|
||||
f.write(cached_samples.data(), copy_length);
|
||||
|
||||
if (copy_length < length) {
|
||||
|
||||
// Fill in remainder with silence
|
||||
QByteArray empty_space(length - copy_length, 0);
|
||||
f.write(empty_space);
|
||||
}
|
||||
|
||||
f.close();
|
||||
} else {
|
||||
qWarning() << "Failed to write to cached PCM file";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user