Skip to content

Commit

Permalink
Append, don't replace, previous input on new input.
Browse files Browse the repository at this point in the history
Previously, we were overwriting the incoming data buffer (input_data_)
each time the input stream called onDataIn(). Instead, append the new
data to the existing data, so that we don’t lose data if the callback
is called more than once before we can process the data.

When processing the data, only lock the input_data_ buffer long enough
to copy its data to a local variable, rather than for all of the
processing.

On pause or resume, lock on the input_data_ buffer before clearing it.
  • Loading branch information
damellis committed Oct 28, 2016
1 parent 351ea65 commit b760015
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Xcode/ESP/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,18 @@ void ofApp::update() {
}
}
}

MatrixDouble input;

std::lock_guard<std::mutex> guard(input_data_mutex_);
for (int i = 0; i < input_data_.getNumRows(); i++){
vector<double> raw_data = input_data_.getRowVector(i);
{
std::lock_guard<std::mutex> guard(input_data_mutex_);
for (int i = 0; i < input_data_.getNumRows(); i++)
input.push_back(input_data_.getRowVector(i));
input_data_.clear();
}

for (int i = 0; i < input.getNumRows(); i++){
vector<double> raw_data = input.getRowVector(i);
vector<double> data_point;
plot_raw_.update(raw_data);
if (calibrator_ == nullptr) {
Expand Down Expand Up @@ -2007,7 +2015,8 @@ void ofApp::exit() {

void ofApp::onDataIn(GRT::MatrixDouble input) {
std::lock_guard<std::mutex> guard(input_data_mutex_);
input_data_ = input;
for (int i = 0; i < input.getNumRows(); i++)
input_data_.push_back(input.getRowVector(i));
}

void ofApp::pauseResume() {
Expand All @@ -2017,6 +2026,8 @@ void ofApp::pauseResume() {
class_likelihood_values_.resize(0);
class_distance_values_.resize(0);
}

std::lock_guard<std::mutex> guard(input_data_mutex_);
input_data_.clear();

ESP_EVENT("Toggle streaming");
Expand Down

0 comments on commit b760015

Please sign in to comment.