diff --git a/app/render/backend/audio/audiobackend.cpp b/app/render/backend/audio/audiobackend.cpp index 0521d75a5..e50328d4a 100644 --- a/app/render/backend/audio/audiobackend.cpp +++ b/app/render/backend/audio/audiobackend.cpp @@ -19,6 +19,19 @@ QIODevice *AudioBackend::GetAudioPullDevice() return &pull_device_; } +void AudioBackend::InvalidateCache(const rational &start_range, const rational &end_range) +{ + /* + // Truncate to length if necessary + int max_length_in_bytes = params().time_to_bytes(viewer_node()->Length()); + if (pcm_data_.size() > max_length_in_bytes) { + pcm_data_.resize(max_length_in_bytes); + } + */ + + AudioRenderBackend::InvalidateCache(start_range, end_range); +} + bool AudioBackend::InitInternal() { // Initiate one thread per CPU core @@ -34,7 +47,6 @@ bool AudioBackend::InitInternal() void AudioBackend::CloseInternal() { - // This backend doesn't init anything yet } bool AudioBackend::CompileInternal() @@ -63,23 +75,26 @@ void AudioBackend::ThreadCompletedCache(NodeDependency dep) int length = params().time_to_bytes(dep.range().length()); int out_point = offset + length; - if (pcm_data_.size() < out_point) { - pcm_data_.resize(out_point); - } - - // Replace data with this data - int copy_length = qMin(length, cached_samples.size()); - - memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast(copy_length)); - - if (copy_length < length) { - // Fill in remainder with silence - memset(pcm_data_.data() + offset + copy_length, 0, static_cast(length - copy_length)); - } - QFile f(CachePathName()); - if (f.open(QFile::WriteOnly)) { - f.write(pcm_data_); + if (f.open(QFile::WriteOnly | QFile::Append)) { + + if (f.size() < out_point) { + f.resize(out_point); + } + + f.seek(offset); + + // 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(); } diff --git a/app/render/backend/audio/audiobackend.h b/app/render/backend/audio/audiobackend.h index 7cbe4c428..3fca71a12 100644 --- a/app/render/backend/audio/audiobackend.h +++ b/app/render/backend/audio/audiobackend.h @@ -15,6 +15,9 @@ public: virtual QIODevice* GetAudioPullDevice() override; +public slots: + virtual void InvalidateCache(const rational &start_range, const rational &end_range) override; + protected: virtual bool InitInternal() override; diff --git a/app/render/backend/audiorenderbackend.cpp b/app/render/backend/audiorenderbackend.cpp index 044ae8000..c72424db3 100644 --- a/app/render/backend/audiorenderbackend.cpp +++ b/app/render/backend/audiorenderbackend.cpp @@ -28,12 +28,6 @@ void AudioRenderBackend::InvalidateCache(const rational &start_range, const rati rational start_range_adj = qMax(rational(0), start_range); rational end_range_adj = qMin(viewer_node()->Length(), end_range); - // Truncate to length if necessary - int max_length_in_bytes = params().time_to_bytes(viewer_node()->Length()); - if (pcm_data_.size() > max_length_in_bytes) { - pcm_data_.resize(max_length_in_bytes); - } - // Add the range to the list cache_queue_.append(TimeRange(start_range_adj, end_range_adj)); diff --git a/app/render/backend/audiorenderbackend.h b/app/render/backend/audiorenderbackend.h index 2270921f0..1685a6b4f 100644 --- a/app/render/backend/audiorenderbackend.h +++ b/app/render/backend/audiorenderbackend.h @@ -39,8 +39,6 @@ protected: QString CachePathName(); - QByteArray pcm_data_; - private: void ValidateRanges();