audio: rewrote audio cache to write to contiguous segments rather than one long file
Fixes issues with PCM file placement, optimizes some audio-based timeline and cache operations, just generally a better approach.
This commit is contained in:
@@ -63,11 +63,13 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (!playback_) {
|
||||
return;
|
||||
}
|
||||
|
||||
const AudioParams& params = playback_->GetParameters();
|
||||
|
||||
if (!playback_
|
||||
|| playback_->GetPCMFilename().isEmpty()
|
||||
|| !params.is_valid()) {
|
||||
if (!params.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,9 +80,9 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
cached_waveform_ = QPixmap(size());
|
||||
cached_waveform_.fill(Qt::transparent);
|
||||
|
||||
QFile fs(playback_->GetPCMFilename());
|
||||
QIODevice* fs = playback_->CreatePlaybackDevice();
|
||||
|
||||
if (fs.open(QFile::ReadOnly)) {
|
||||
if (fs->open(QFile::ReadOnly)) {
|
||||
|
||||
QPainter wave_painter(&cached_waveform_);
|
||||
|
||||
@@ -89,13 +91,13 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
|
||||
int drew = 0;
|
||||
|
||||
fs.seek(params.samples_to_bytes(ScreenToUnitRounded(0)));
|
||||
fs->seek(params.samples_to_bytes(ScreenToUnitRounded(0)));
|
||||
|
||||
for (int x=0; x<width() && !fs.atEnd(); x++) {
|
||||
for (int x=0; x<width() && !fs->atEnd(); x++) {
|
||||
int samples_len = ScreenToUnitRounded(x+1) - ScreenToUnitRounded(x);
|
||||
int max_read_size = params.samples_to_bytes(samples_len);
|
||||
|
||||
QByteArray read_buffer = fs.read(max_read_size);
|
||||
QByteArray read_buffer = fs->read(max_read_size);
|
||||
|
||||
// Detect whether we've reached EOF and recalculate sample count if so
|
||||
if (read_buffer.size() < max_read_size) {
|
||||
@@ -117,9 +119,11 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
cached_scale_ = GetScale();
|
||||
cached_scroll_ = GetScroll();
|
||||
|
||||
fs.close();
|
||||
fs->close();
|
||||
|
||||
}
|
||||
|
||||
delete fs;
|
||||
}
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
Reference in New Issue
Block a user