audiobackend: truncate PCM cache size when the length is reduced
This commit is contained in:
@@ -85,6 +85,7 @@ void AudioBackend::ThreadCompletedCache(NodeDependency dep, NodeValueTable data,
|
||||
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);
|
||||
|
||||
@@ -36,12 +36,14 @@ void AudioRenderBackend::ConnectViewer(ViewerOutput *node)
|
||||
{
|
||||
connect(node, &ViewerOutput::AudioChangedBetween, this, &AudioRenderBackend::InvalidateCache);
|
||||
connect(node, &ViewerOutput::AudioGraphChanged, this, &AudioRenderBackend::QueueRecompile);
|
||||
connect(node, &ViewerOutput::LengthChanged, this, &AudioRenderBackend::TruncateCache);
|
||||
}
|
||||
|
||||
void AudioRenderBackend::DisconnectViewer(ViewerOutput *node)
|
||||
{
|
||||
disconnect(node, &ViewerOutput::AudioChangedBetween, this, &AudioRenderBackend::InvalidateCache);
|
||||
disconnect(node, &ViewerOutput::AudioGraphChanged, this, &AudioRenderBackend::QueueRecompile);
|
||||
disconnect(node, &ViewerOutput::LengthChanged, this, &AudioRenderBackend::TruncateCache);
|
||||
}
|
||||
|
||||
bool AudioRenderBackend::CompileInternal()
|
||||
@@ -192,6 +194,17 @@ void AudioRenderBackend::ConformUpdated(Stream *stream, const AudioRenderingPara
|
||||
}
|
||||
}
|
||||
|
||||
void AudioRenderBackend::TruncateCache(const rational &r)
|
||||
{
|
||||
int seq_length = params_.time_to_bytes(r);
|
||||
|
||||
QFile cache_pcm(CachePathName());
|
||||
|
||||
if (cache_pcm.size() > seq_length) {
|
||||
cache_pcm.resize(seq_length);
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioRenderBackend::ConformWaitInfo::operator==(const AudioRenderBackend::ConformWaitInfo &rhs) const
|
||||
{
|
||||
return rhs.params == params
|
||||
|
||||
@@ -74,6 +74,8 @@ private slots:
|
||||
|
||||
void ConformUpdated(Stream *stream, const AudioRenderingParams& params);
|
||||
|
||||
void TruncateCache(const rational& r);
|
||||
|
||||
};
|
||||
|
||||
#endif // AUDIORENDERBACKEND_H
|
||||
|
||||
Reference in New Issue
Block a user