added in-timeline recording

This commit is contained in:
itsmattkc
2018-10-26 20:02:48 +11:00
parent 269d7153df
commit d4692b9480
11 changed files with 172 additions and 23 deletions
+23 -6
View File
@@ -2,6 +2,7 @@
#include "project/sequence.h"
#include "panels/project.h"
#include "panels/panels.h"
#include "panels/timeline.h"
#include "panels/viewer.h"
@@ -11,6 +12,7 @@
#include <QAudioInput>
#include <QtMath>
#include <QFile>
#include <QDir>
#include <QDebug>
extern "C" {
@@ -263,7 +265,22 @@ bool start_recording() {
qDebug() << "[ERROR] No active sequence to record into";
return false;
}
output_recording.setFileName("C:/Users/Matt/output.wav");
QString audio_path = project_url + " Audio";
QDir audio_dir(audio_path);
if (!audio_dir.exists() && !audio_dir.mkpath(".")) {
qDebug() << "[ERROR] Failed to create audio directory";
return false;
}
QString audio_filename;
int file_number = 0;
do {
file_number++;
audio_filename = audio_path + "/Recording " + QString::number(file_number) + ".wav";
} while (QFile(audio_filename).exists());
output_recording.setFileName(audio_filename);
if (!output_recording.open(QFile::WriteOnly)) {
qDebug() << "[ERROR] Failed to open output file. Does Olive have permission to write to this directory?";
return false;
@@ -287,16 +304,16 @@ void stop_recording() {
if (recording) {
audio_input->stop();
/*if (audio_input->state() == QAudio::ActiveState) {
}*/
write_wave_trailer(output_recording);
output_recording.close();
delete audio_input;
audio_input = NULL;
recording = false;
}
recording = false;
}
const QString& get_recorded_audio_filename() {
return output_recording.fileName();
}
+1
View File
@@ -48,6 +48,7 @@ int get_buffer_offset_from_frame(Sequence *s, long frame);
bool start_recording();
void stop_recording();
const QString& get_recorded_audio_filename();
extern bool recording;
#endif // AUDIO_H
+3 -3
View File
@@ -293,14 +293,13 @@ void cache_audio_worker(Clip* c, Clip* nest) {
break;
case MEDIA_TYPE_TONE:
frame = c->frame;
nb_bytes = av_samples_get_buffer_size(NULL, frame->channels, frame->nb_samples, static_cast<AVSampleFormat>(frame->format), 1);
if (c->frame_sample_index < 0 || c->frame_sample_index >= nb_bytes) {
nb_bytes = frame->nb_samples * av_get_bytes_per_sample(static_cast<AVSampleFormat>(frame->format)) * frame->channels;
while ((c->frame_sample_index == -1 || c->frame_sample_index >= nb_bytes) && nb_bytes > 0) {
// create "new frame"
memset(c->frame->data[0], 0, nb_bytes);
apply_audio_effects(c, bytes_to_seconds(frame->pts, frame->channels, frame->sample_rate), frame, nb_bytes);
c->frame->pts += nb_bytes;
c->frame_sample_index = 0;
qDebug() << "2 >> c->audio_target_frame:" << c->audio_target_frame;
if (c->audio_buffer_write == 0) c->audio_buffer_write = get_buffer_offset_from_frame(c->sequence, qMax(timeline_in, c->audio_target_frame));
int offset = audio_ibuffer_read - c->audio_buffer_write;
if (offset > 0) {
@@ -546,6 +545,7 @@ void reset_cache(Clip* c, long target_frame) {
}
break;
case MEDIA_TYPE_TONE:
c->reached_end = false;
c->audio_target_frame = target_frame;
c->frame_sample_index = -1;
c->frame->pts = 0;