diff --git a/app/dialog/speedduration/speedduration.h b/app/dialog/speedduration/speedduration.h index bd66f6164..8ea9d5e78 100644 --- a/app/dialog/speedduration/speedduration.h +++ b/app/dialog/speedduration/speedduration.h @@ -6,6 +6,7 @@ #include #include "node/block/clip/clip.h" +#include "node/output/track/track.h" #include "widget/slider/floatslider.h" #include "widget/slider/timeslider.h" diff --git a/app/node/block/block.cpp b/app/node/block/block.cpp index 3dbb8fb70..2da792fd9 100644 --- a/app/node/block/block.cpp +++ b/app/node/block/block.cpp @@ -97,7 +97,14 @@ void Block::set_length_and_media_out(const rational &length) return; } - set_media_out(media_out() + (length - this->length())); + rational media_out_diff = length - this->length(); + + // Try to maintain the same speed (which is determined by the media in to out points) + if (media_length() != this->length()) { + media_out_diff = media_out_diff / this->length() * media_length(); + } + + set_media_out(media_out() + media_out_diff); set_length(length); } @@ -110,8 +117,15 @@ void Block::set_length_and_media_in(const rational &length) return; } + rational media_in_diff = this->length() - length; + + // Try to maintain the same speed (which is determined by the media in to out points) + if (media_length() != this->length()) { + media_in_diff = media_in_diff / this->length() * media_length(); + } + // Calculate media_in adjustment - set_media_in(media_in() + (this->length() - length)); + set_media_in(media_in() + media_in_diff); // Set the length without setting media out set_length(length); diff --git a/app/render/backend/audiorenderworker.cpp b/app/render/backend/audiorenderworker.cpp index 0e9b9b715..6e4f645ef 100644 --- a/app/render/backend/audiorenderworker.cpp +++ b/app/render/backend/audiorenderworker.cpp @@ -54,19 +54,15 @@ NodeValueTable AudioRenderWorker::RenderBlock(const TrackOutput *track, const Ti // Stretch samples here if (b->media_length() != b->length()) { QByteArray speed_adjusted_samples; - double clip_speed = b->speed(); - int sample_count = audio_params_.bytes_to_samples(samples_from_this_block.size()); - qDebug() << "Adjusting audio to speed" << clip_speed; + double clip_speed = b->speed(); + + int sample_count = audio_params_.bytes_to_samples(samples_from_this_block.size()); for (double i=0;i= samples_from_this_block.size() || (byte_index + audio_params_.samples_to_bytes(1)) > samples_from_this_block.size()) { - qDebug() << "Tried to access" << byte_index << "-" << (byte_index + audio_params_.samples_to_bytes(1)) << "of" << samples_from_this_block.size(); - } - QByteArray sample_at_this_index = samples_from_this_block.mid(byte_index, audio_params_.samples_to_bytes(1)); speed_adjusted_samples.append(sample_at_this_index); }