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);
// 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);
int half_frame_bytes = frame_bytes >> 1;
int sample_size = c->frame->channels*2;
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];
AVSampleFormat sample_fmt = static_cast<AVSampleFormat>(c->frame->format);
if (av_sample_fmt_is_planar(sample_fmt)) {
int sample_size = av_get_bytes_per_sample(sample_fmt);
char* temp_chars = new char[sample_size];
for (int j=0;j<c->frame->channels;j++) {
int frame_bytes = c->frame->linesize[0];
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++) {
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;
} else {
int frame_bytes = av_samples_get_buffer_size(NULL, c->frame->channels, c->frame->nb_samples, sample_fmt, 1);
int half_frame_bytes = frame_bytes >> 1;
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 {
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;
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;
for (int j=0;j<ms->audio_channels;j++) {
int mid = clip_rect.top()+channel_height*j+(channel_height/2);
int offset = waveform_index+(j*2);
int mid = clip_rect.top()+channel_height*j+(channel_height/2);
int offset = waveform_index+(j*2);
if ((offset + 1) < ms->audio_preview.size()) {
qint8 min = (double)ms->audio_preview.at(offset) / 128.0 * (channel_height/2);