even more improved corner pin and more consistent audio
This commit is contained in:
@@ -38,8 +38,6 @@ CornerPinEffect::CornerPinEffect(Clip *c, const EffectMeta *em) : Effect(c, em)
|
||||
}
|
||||
|
||||
void CornerPinEffect::process_coords(double timecode, GLTextureCoords &coords) {
|
||||
coords.grid_size += 4;
|
||||
|
||||
coords.vertexTopLeftX += top_left_x->get_double_value(timecode);
|
||||
coords.vertexTopLeftY += top_left_y->get_double_value(timecode);
|
||||
|
||||
|
||||
+5
-7
@@ -68,9 +68,7 @@ void init_audio(Sequence* s) {
|
||||
audio_thread->start(QThread::TimeCriticalPriority);
|
||||
|
||||
clear_audio_ibuffer();
|
||||
}
|
||||
|
||||
dout << "h";
|
||||
}
|
||||
}
|
||||
|
||||
void stop_audio() {
|
||||
@@ -88,9 +86,9 @@ void clear_audio_ibuffer() {
|
||||
audio_ibuffer_read = 0;
|
||||
}
|
||||
|
||||
int get_buffer_offset_from_frame(Sequence* s, long frame) {
|
||||
int get_buffer_offset_from_frame(double framerate, long frame) {
|
||||
if (frame >= audio_ibuffer_frame) {
|
||||
return qFloor(((double) (frame - audio_ibuffer_frame)/s->frame_rate)*s->audio_frequency)*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(s->audio_layout);
|
||||
return qFloor(((double) (frame - audio_ibuffer_frame)/framerate)*audio_output->format().sampleRate())*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO);
|
||||
} else {
|
||||
dout << "[WARNING] Invalid values passed to get_buffer_offset_from_frame";
|
||||
return 0;
|
||||
@@ -160,14 +158,14 @@ int AudioSenderThread::send_audio_to_output(int offset, int max) {
|
||||
int channel_count = av_get_channel_layout_nb_channels(s->audio_layout);
|
||||
long sample_cache_playhead = panel_timeline->ui->audio_monitor->sample_cache_offset + (panel_timeline->ui->audio_monitor->sample_cache.size()/channel_count);
|
||||
int next_buffer_offset, buffer_offset_adjusted, i;
|
||||
int buffer_offset = get_buffer_offset_from_frame(s, sample_cache_playhead);
|
||||
int buffer_offset = get_buffer_offset_from_frame(s->frame_rate, sample_cache_playhead);
|
||||
if (samples.size() != channel_count) samples.resize(channel_count);
|
||||
samples.fill(0);
|
||||
|
||||
// TODO: I don't like this, but i'm not sure if there's a smarter way to do it
|
||||
while (buffer_offset < audio_ibuffer_limit) {
|
||||
sample_cache_playhead++;
|
||||
next_buffer_offset = qMin(get_buffer_offset_from_frame(s, sample_cache_playhead), audio_ibuffer_limit);
|
||||
next_buffer_offset = qMin(get_buffer_offset_from_frame(s->frame_rate, sample_cache_playhead), audio_ibuffer_limit);
|
||||
while (buffer_offset < next_buffer_offset) {
|
||||
for (i=0;i<samples.size();i++) {
|
||||
buffer_offset_adjusted = buffer_offset%audio_ibuffer_size;
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ void clear_audio_ibuffer();
|
||||
|
||||
void init_audio(Sequence *s);
|
||||
void stop_audio();
|
||||
int get_buffer_offset_from_frame(Sequence* s, long frame);
|
||||
int get_buffer_offset_from_frame(double framerate, long frame);
|
||||
|
||||
bool start_recording();
|
||||
void stop_recording();
|
||||
|
||||
+12
-12
@@ -86,8 +86,8 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
long timeline_out = c->timeline_out;
|
||||
|
||||
long frame_skip = 0;
|
||||
double last_fr = c->sequence->frame_rate;
|
||||
if (!nests.isEmpty()) {
|
||||
double last_fr = c->sequence->frame_rate;
|
||||
for (int i=nests.size()-1;i>=0;i--) {
|
||||
timeline_in = refactor_frame_number(timeline_in, last_fr, nests.at(i)->sequence->frame_rate) + nests.at(i)->timeline_in - nests.at(i)->clip_in;
|
||||
timeline_out = refactor_frame_number(timeline_out, last_fr, nests.at(i)->sequence->frame_rate) + nests.at(i)->timeline_in - nests.at(i)->clip_in;
|
||||
@@ -213,10 +213,10 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
dout << "time for the end of rev cache" << rev_frame->nb_samples << c->rev_target << c->frame->pts << c->frame->pkt_duration << c->frame->nb_samples;
|
||||
dout << "diff:" << (c->frame->pkt_pts + c->frame->pkt_duration) - c->rev_target;
|
||||
#endif
|
||||
int cutoff = qRound64((((c->frame->pkt_pts + c->frame->pkt_duration) - c->reverse_target) * timebase) * c->sequence->audio_frequency);
|
||||
int cutoff = qRound64((((c->frame->pkt_pts + c->frame->pkt_duration) - c->reverse_target) * timebase) * audio_output->format().sampleRate());
|
||||
if (cutoff > 0) {
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "cut off" << cutoff << "samples (rate:" << c->sequence->audio_frequency << ")";
|
||||
dout << "cut off" << cutoff << "samples (rate:" << audio_output->format().sampleRate() << ")";
|
||||
#endif
|
||||
rev_frame->nb_samples -= cutoff;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "pre cutoff deets::: rev_frame.pts:" << rev_frame->pts << "rev_frame.nb_samples" << rev_frame->nb_samples << "rev_target:" << c->reverse_target;
|
||||
#endif
|
||||
rev_frame->nb_samples = qRound64(static_cast<double>(c->reverse_target - rev_frame->pts) / c->stream->codecpar->sample_rate * (c->sequence->audio_frequency / c->speed));
|
||||
rev_frame->nb_samples = qRound64(static_cast<double>(c->reverse_target - rev_frame->pts) / c->stream->codecpar->sample_rate * (audio_output->format().sampleRate() / c->speed));
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "post cutoff deets::" << rev_frame->nb_samples;
|
||||
#endif
|
||||
@@ -283,7 +283,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
// get precise sample offset for the elected clip_in from this audio frame
|
||||
double target_sts = playhead_to_clip_seconds(c, c->audio_target_frame);
|
||||
double frame_sts = ((frame->pts - c->stream->start_time) * timebase);
|
||||
int nb_samples = qRound64((target_sts - frame_sts)*c->sequence->audio_frequency);
|
||||
int nb_samples = qRound64((target_sts - frame_sts)*audio_output->format().sampleRate());
|
||||
c->frame_sample_index = nb_samples * 4;
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "fsts:" << frame_sts << "tsts:" << target_sts << "nbs:" << nb_samples << "nbb:" << nb_bytes << "rev_targetToSec:" << (c->reverse_target * timebase);
|
||||
@@ -297,10 +297,10 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
dout << "fsi-post-post:" << c->frame_sample_index;
|
||||
#endif
|
||||
if (c->audio_buffer_write == 0) {
|
||||
c->audio_buffer_write = get_buffer_offset_from_frame((sequence == NULL) ? c->sequence : sequence, qMax(timeline_in, c->audio_target_frame));
|
||||
c->audio_buffer_write = get_buffer_offset_from_frame(c->sequence->frame_rate, qMax(timeline_in, c->audio_target_frame));
|
||||
|
||||
if (frame_skip > 0) {
|
||||
int target = get_buffer_offset_from_frame((sequence == NULL) ? c->sequence : sequence, qMax(timeline_in + frame_skip, c->audio_target_frame));
|
||||
int target = get_buffer_offset_from_frame(c->sequence->frame_rate, qMax(timeline_in + frame_skip, c->audio_target_frame));
|
||||
c->frame_sample_index += (target - c->audio_buffer_write);
|
||||
c->audio_buffer_write = target;
|
||||
}
|
||||
@@ -328,7 +328,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
// apply any audio effects to the data
|
||||
if (nb_bytes == INT_MAX) nb_bytes = frame->nb_samples * av_get_bytes_per_sample(static_cast<AVSampleFormat>(frame->format)) * frame->channels;
|
||||
if (new_frame) {
|
||||
apply_audio_effects(c, bytes_to_seconds(c->audio_buffer_write, 2, c->sequence->audio_frequency) + audio_ibuffer_timecode + ((double)c->clip_in/c->sequence->frame_rate) - ((double)timeline_in/((sequence == NULL) ? c->sequence->frame_rate : sequence->frame_rate)), frame, nb_bytes, nests);
|
||||
apply_audio_effects(c, bytes_to_seconds(c->audio_buffer_write, 2, audio_output->format().sampleRate()) + audio_ibuffer_timecode + ((double)c->clip_in/c->sequence->frame_rate) - ((double)timeline_in/last_fr), frame, nb_bytes, nests);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -342,7 +342,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
c->frame->pts += nb_bytes;
|
||||
c->frame_sample_index = 0;
|
||||
if (c->audio_buffer_write == 0) {
|
||||
c->audio_buffer_write = get_buffer_offset_from_frame(sequence, qMax(timeline_in, c->audio_target_frame));
|
||||
c->audio_buffer_write = get_buffer_offset_from_frame(c->sequence->frame_rate, qMax(timeline_in, c->audio_target_frame));
|
||||
}
|
||||
int offset = audio_ibuffer_read - c->audio_buffer_write;
|
||||
if (offset > 0) {
|
||||
@@ -360,7 +360,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
if (frame->nb_samples == 0) {
|
||||
break;
|
||||
} else {
|
||||
long buffer_timeline_out = get_buffer_offset_from_frame((sequence == NULL) ? c->sequence : sequence, timeline_out);
|
||||
long buffer_timeline_out = get_buffer_offset_from_frame(c->sequence->frame_rate, timeline_out);
|
||||
audio_write_lock.lock();
|
||||
|
||||
while (c->frame_sample_index < nb_bytes
|
||||
@@ -757,7 +757,7 @@ void open_clip_worker(Clip* clip) {
|
||||
AVFrame* reverse_frame = av_frame_alloc();
|
||||
|
||||
reverse_frame->format = sample_format;
|
||||
reverse_frame->nb_samples = clip->sequence->audio_frequency*2;
|
||||
reverse_frame->nb_samples = audio_output->format().sampleRate()*2;
|
||||
reverse_frame->channel_layout = clip->sequence->audio_layout;
|
||||
reverse_frame->channels = av_get_channel_layout_nb_channels(clip->sequence->audio_layout);
|
||||
av_frame_get_buffer(reverse_frame, 0);
|
||||
@@ -843,7 +843,7 @@ void open_clip_worker(Clip* clip) {
|
||||
clip->frame->format = sample_format;
|
||||
clip->frame->channel_layout = clip->sequence->audio_layout;
|
||||
clip->frame->channels = av_get_channel_layout_nb_channels(clip->frame->channel_layout);
|
||||
clip->frame->sample_rate = clip->sequence->audio_frequency;
|
||||
clip->frame->sample_rate = audio_output->format().sampleRate();
|
||||
clip->frame->nb_samples = 2048;
|
||||
av_frame_make_writable(clip->frame);
|
||||
if (av_frame_get_buffer(clip->frame, 0)) {
|
||||
|
||||
+27
-9
@@ -376,7 +376,7 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
|
||||
|
||||
fbo_switcher = !fbo_switcher;
|
||||
|
||||
GLTextureCoords coords;
|
||||
GLTextureCoords coords;
|
||||
coords.grid_size = 1;
|
||||
coords.vertexTopLeftX = coords.vertexBottomLeftX = -video_width/2;
|
||||
coords.vertexTopLeftY = coords.vertexTopRightY = -video_height/2;
|
||||
@@ -437,16 +437,34 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
if (coords.grid_size <= 1) {
|
||||
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
|
||||
// calculate the Q coordinate
|
||||
double m1 = ((double)coords.vertexTopRightY - (double)coords.vertexBottomLeftY)/((double)coords.vertexTopRightX - (double)coords.vertexBottomLeftX);
|
||||
double c1 = (double)coords.vertexBottomLeftY - m1 * (double)coords.vertexBottomLeftX;
|
||||
double m2 = ((double)coords.vertexBottomRightY - (double)coords.vertexTopLeftY)/((double)coords.vertexBottomRightX - (double)coords.vertexTopLeftX);
|
||||
double c2 = (double)coords.vertexTopLeftY - m2 * (double)coords.vertexTopLeftX;
|
||||
double mid_x = (c2 - c1) / (m1 - m2);
|
||||
double mid_y = m1 * mid_x + c1;
|
||||
|
||||
double d0 = qSqrt(qPow(mid_x - (double)coords.vertexBottomLeftX, 2) + qPow(mid_y - (double)coords.vertexBottomLeftY, 2));
|
||||
double d1 = qSqrt(qPow((double)coords.vertexBottomRightX - mid_x, 2) + qPow(mid_y - (double)coords.vertexBottomRightY, 2));
|
||||
double d2 = qSqrt(qPow((double)coords.vertexTopRightX - mid_x, 2) + qPow((double)coords.vertexTopRightY - mid_y, 2));
|
||||
double d3 = qSqrt(qPow(mid_x - (double)coords.vertexTopLeftX, 2) + qPow((double)coords.vertexTopLeftY - mid_y, 2));
|
||||
|
||||
double q0 = (d0 + d2)/d2;
|
||||
double q1 = (d1 + d3)/d3;
|
||||
double q2 = (d2 + d0)/d0;
|
||||
double q3 = (d3 + d1)/d1;
|
||||
|
||||
//if (coords.grid_size <= 1) {
|
||||
glTexCoord4f(coords.textureTopLeftX*q3, coords.textureTopLeftY*q3, 0, q3); // top left
|
||||
glVertex2f(coords.vertexTopLeftX, coords.vertexTopLeftY); // top left
|
||||
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
|
||||
glTexCoord4f(coords.textureTopRightX*q2, coords.textureTopRightY*q2, 0, q2); // top right
|
||||
glVertex2f(coords.vertexTopRightX, coords.vertexTopRightY); // top right
|
||||
glTexCoord2f(coords.textureBottomRightX, coords.textureBottomRightY); // bottom right
|
||||
glTexCoord4f(coords.textureBottomRightX*q1, coords.textureBottomRightY*q1, 0, q1); // bottom right
|
||||
glVertex2f(coords.vertexBottomRightX, coords.vertexBottomRightY); // bottom right
|
||||
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
|
||||
glTexCoord4f(coords.textureBottomLeftX*q0, coords.textureBottomLeftY*q0, 0, q0); // bottom left
|
||||
glVertex2f(coords.vertexBottomLeftX, coords.vertexBottomLeftY); // bottom left
|
||||
} else {
|
||||
/*} else {
|
||||
double rows = coords.grid_size;
|
||||
double cols = coords.grid_size;
|
||||
|
||||
@@ -477,11 +495,11 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
|
||||
glVertex2f(double_lerp(vertexBLX, vertexBRX, col_prog), double_lerp(vertexTLY, vertexBLY, next_row_prog)); // bottom left
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
glEnd();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // unbind texture
|
||||
|
||||
if (!nests.isEmpty()) {
|
||||
nests.last()->fbo[0]->release();
|
||||
|
||||
Reference in New Issue
Block a user