fixed reversed waveform issues and worked on planar audio support

This commit is contained in:
itsmattkc
2018-10-08 10:34:28 +11:00
parent 81d229595f
commit 1123abd82e
2 changed files with 38 additions and 16 deletions
+35 -13
View File
@@ -117,22 +117,44 @@ void cache_audio_worker(Clip* c, Clip* nest) {
ret = retrieve_next_frame(c, c->frame); ret = retrieve_next_frame(c, c->frame);
// reverse it // reverse it
int frame_bytes = av_samples_get_buffer_size(NULL, c->frame->channels, c->frame->nb_samples, static_cast<AVSampleFormat>(c->frame->format), 1); AVSampleFormat sample_fmt = static_cast<AVSampleFormat>(c->frame->format);
int half_frame_bytes = frame_bytes >> 1; if (av_sample_fmt_is_planar(sample_fmt)) {
int sample_size = c->frame->channels*2; int sample_size = av_get_bytes_per_sample(sample_fmt);
char* temp_chars = new char[sample_size]; char* temp_chars = new char[sample_size];
for (int i=0;i<half_frame_bytes;i+=sample_size) { for (int j=0;j<c->frame->channels;j++) {
for (int j=0;j<sample_size;j++) { int frame_bytes = c->frame->linesize[0];
temp_chars[j] = c->frame->data[0][i+j]; int half_frame_bytes = frame_bytes >> 1;
for (int i=0;i<half_frame_bytes;i+=sample_size) {
for (int k=0;k<sample_size;k++) {
temp_chars[k] = c->frame->data[j][i+k];
}
for (int k=0;k<sample_size;k++) {
c->frame->data[j][i+k] = c->frame->data[j][frame_bytes-i-sample_size+k];
}
for (int k=0;k<sample_size;k++) {
c->frame->data[j][frame_bytes-i-sample_size+k] = temp_chars[k];
}
}
} }
for (int j=0;j<sample_size;j++) { delete [] temp_chars;
c->frame->data[0][i+j] = c->frame->data[0][frame_bytes-i-sample_size+j]; } else {
} int frame_bytes = av_samples_get_buffer_size(NULL, c->frame->channels, c->frame->nb_samples, sample_fmt, 1);
for (int j=0;j<sample_size;j++) { int half_frame_bytes = frame_bytes >> 1;
c->frame->data[0][frame_bytes-i-sample_size+j] = temp_chars[j]; int sample_size = c->frame->channels*av_get_bytes_per_sample(sample_fmt);
char* temp_chars = new char[sample_size];
for (int i=0;i<half_frame_bytes;i+=sample_size) {
for (int j=0;j<sample_size;j++) {
temp_chars[j] = c->frame->data[0][i+j];
}
for (int j=0;j<sample_size;j++) {
c->frame->data[0][i+j] = c->frame->data[0][frame_bytes-i-sample_size+j];
}
for (int j=0;j<sample_size;j++) {
c->frame->data[0][frame_bytes-i-sample_size+j] = temp_chars[j];
}
} }
delete [] temp_chars;
} }
delete [] temp_chars;
} else { } else {
ret = retrieve_next_frame(c, c->frame); ret = retrieve_next_frame(c, c->frame);
} }
+3 -3
View File
@@ -1804,14 +1804,14 @@ void TimelineWidget::redraw_clips() {
int waveform_index = qFloor((((clip->clip_in + ((double) i/panel_timeline->zoom))/media_length) * ms->audio_preview.size())/divider)*divider; int waveform_index = qFloor((((clip->clip_in + ((double) i/panel_timeline->zoom))/media_length) * ms->audio_preview.size())/divider)*divider;
if (clip->reverse) { if (clip->reverse) {
waveform_index = ms->audio_preview.size() - waveform_index; waveform_index = ms->audio_preview.size() - waveform_index - (ms->audio_channels * 2);
} }
int rectified_height = 0; int rectified_height = 0;
for (int j=0;j<ms->audio_channels;j++) { for (int j=0;j<ms->audio_channels;j++) {
int mid = clip_rect.top()+channel_height*j+(channel_height/2); int mid = clip_rect.top()+channel_height*j+(channel_height/2);
int offset = waveform_index+(j*2); int offset = waveform_index+(j*2);
if ((offset + 1) < ms->audio_preview.size()) { if ((offset + 1) < ms->audio_preview.size()) {
qint8 min = (double)ms->audio_preview.at(offset) / 128.0 * (channel_height/2); qint8 min = (double)ms->audio_preview.at(offset) / 128.0 * (channel_height/2);