Refactoring
This commit is contained in:
parent
6c653e5ba2
commit
00a1fe1e32
|
@ -52,7 +52,7 @@ Analyzer::Base::Base(QWidget* parent, uint scopeSize)
|
|||
m_fht(new FHT(scopeSize)),
|
||||
m_engine(nullptr),
|
||||
m_lastScope(512),
|
||||
current_chunk(0),
|
||||
current_chunk_(0),
|
||||
new_frame_(false),
|
||||
is_playing_(false) {}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class Base : public QWidget {
|
|||
FHT* m_fht;
|
||||
EngineBase* m_engine;
|
||||
Scope m_lastScope;
|
||||
int current_chunk;
|
||||
int current_chunk_;
|
||||
|
||||
bool new_frame_;
|
||||
bool is_playing_;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "gstenginepipeline.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/utilities.h"
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
|
@ -98,8 +99,8 @@ GstEngine::GstEngine(TaskManager* task_manager)
|
|||
next_element_id_(0),
|
||||
is_fading_out_to_pause_(false),
|
||||
has_faded_out_(false),
|
||||
scope_chunk(0),
|
||||
have_new_buffer(false) {
|
||||
scope_chunk_(0),
|
||||
have_new_buffer_(false) {
|
||||
seek_timer_->setSingleShot(true);
|
||||
seek_timer_->setInterval(kSeekDelayNanosec / kNsecPerMsec);
|
||||
connect(seek_timer_, SIGNAL(timeout()), SLOT(SeekNow()));
|
||||
|
@ -240,37 +241,37 @@ void GstEngine::AddBufferToScope(GstBuffer* buf, int pipeline_id) {
|
|||
}
|
||||
|
||||
latest_buffer_ = buf;
|
||||
have_new_buffer = true;
|
||||
have_new_buffer_ = true;
|
||||
}
|
||||
|
||||
const Engine::Scope& GstEngine::scope(int chunk_length) {
|
||||
// the new buffer could have a different size
|
||||
if (have_new_buffer) {
|
||||
if (have_new_buffer_) {
|
||||
if (latest_buffer_ != nullptr) {
|
||||
scope_chunks = ceil(((double)GST_BUFFER_DURATION(latest_buffer_) /
|
||||
scope_chunks_ = ceil(((double)GST_BUFFER_DURATION(latest_buffer_) /
|
||||
(double)(chunk_length * 1000000)));
|
||||
}
|
||||
|
||||
// if the buffer is shorter than the chunk length
|
||||
if (scope_chunks <= 0) {
|
||||
scope_chunks = 1;
|
||||
if (scope_chunks_ <= 0) {
|
||||
scope_chunks_ = 1;
|
||||
}
|
||||
|
||||
scope_chunk = 0;
|
||||
have_new_buffer = false;
|
||||
scope_chunk_ = 0;
|
||||
have_new_buffer_ = false;
|
||||
}
|
||||
|
||||
UpdateScope(chunk_length);
|
||||
return scope_;
|
||||
}
|
||||
|
||||
void GstEngine::UpdateScope(int chunk_length_) {
|
||||
void GstEngine::UpdateScope(int chunk_length) {
|
||||
typedef Engine::Scope::value_type sample_type;
|
||||
|
||||
// determine where to split the buffer
|
||||
int chunk_density = GST_BUFFER_SIZE(latest_buffer_) /
|
||||
(GST_BUFFER_DURATION(latest_buffer_) / 1000000);
|
||||
int chunk_size = chunk_length_ * chunk_density;
|
||||
(GST_BUFFER_DURATION(latest_buffer_) / kNsecPerMsec);
|
||||
int chunk_size = chunk_length * chunk_density;
|
||||
|
||||
// determine the number of channels
|
||||
GstStructure* structure =
|
||||
|
@ -282,31 +283,31 @@ void GstEngine::UpdateScope(int chunk_length_) {
|
|||
if (channels > 2) return;
|
||||
|
||||
// in case a buffer doesn't arrive in time
|
||||
if (scope_chunk >= scope_chunks) {
|
||||
scope_chunk = 0;
|
||||
if (scope_chunk_ >= scope_chunks_) {
|
||||
scope_chunk_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// set the starting point in the buffer to take data from
|
||||
const sample_type* source =
|
||||
reinterpret_cast<sample_type*>(GST_BUFFER_DATA(latest_buffer_));
|
||||
source += (chunk_size / sizeof(sample_type)) * scope_chunk;
|
||||
source += (chunk_size / sizeof(sample_type)) * scope_chunk_;
|
||||
sample_type* dest = scope_.data();
|
||||
|
||||
int bytes;
|
||||
int bytes = 0;
|
||||
|
||||
// make sure we don't go beyond the end of the buffer
|
||||
if (scope_chunk == scope_chunks - 1) {
|
||||
bytes = qMin(
|
||||
static_cast<Engine::Scope::size_type>(GST_BUFFER_SIZE(latest_buffer_) - (chunk_size * scope_chunk)),
|
||||
if (scope_chunk_ == scope_chunks_ - 1) {
|
||||
bytes =
|
||||
qMin(static_cast<Engine::Scope::size_type>(
|
||||
GST_BUFFER_SIZE(latest_buffer_) - (chunk_size * scope_chunk_)),
|
||||
scope_.size() * sizeof(sample_type));
|
||||
} else {
|
||||
bytes = qMin(
|
||||
static_cast<Engine::Scope::size_type>(chunk_size),
|
||||
bytes = qMin(static_cast<Engine::Scope::size_type>(chunk_size),
|
||||
scope_.size() * sizeof(sample_type));
|
||||
}
|
||||
|
||||
scope_chunk++;
|
||||
scope_chunk_++;
|
||||
|
||||
memcpy(dest, source, bytes);
|
||||
}
|
||||
|
|
|
@ -224,9 +224,9 @@ class GstEngine : public Engine::Base, public BufferConsumer {
|
|||
bool is_fading_out_to_pause_;
|
||||
bool has_faded_out_;
|
||||
|
||||
int scope_chunk;
|
||||
bool have_new_buffer;
|
||||
int scope_chunks;
|
||||
int scope_chunk_;
|
||||
bool have_new_buffer_;
|
||||
int scope_chunks_;
|
||||
|
||||
QList<DeviceFinder*> device_finders_;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue