Gather stats for max callback time

A small amount of stats analysis, mostly max callback time, with simple
display in the UI.

Also improves pow calculation to use lut implementation instead of
math.h pow(), for a speedup somewhere around 20-30%.
master
Raph Levien 12 years ago
parent c934c830b6
commit 229003da19
  1. 1
      android/jni/Android.mk
  2. 44
      android/src/com/google/synthesizer/android/stats/JitterStats.java
  3. 14
      android/src/com/google/synthesizer/android/ui/PianoActivity2.java
  4. 2
      cpp/src/android_glue.cc
  5. 5
      cpp/src/dx7note.cc

@ -6,6 +6,7 @@ LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := android_glue.cc \
dx7note.cc \
env.cc \
exp2.cc \
fm_core.cc \
fm_op_kernel.cc \
freqlut.cc \

@ -0,0 +1,44 @@
package com.google.synthesizer.android.stats;
import android.util.Log;
public class JitterStats {
public JitterStats() {
startTime_ = new double[N_STATS];
endTime_ = new double[N_STATS];
}
// Takes stats buf in format from android_glue
public void aggregate(byte[] statsBuf) {
String[] lines = new String(statsBuf).split("\n");
for (int i = 0; i < lines.length; i++) {
String[] toks = lines[i].split(" ");
if (toks.length == 3 && "ts".equals(toks[0])) {
double startTime = Double.parseDouble(toks[1]);
double endTime = Double.parseDouble(toks[2]);
startTime_[bufIx_] = startTime;
endTime_[bufIx_] = endTime;
bufIx_ = (bufIx_ + 1) % N_STATS;
double cbTime = endTime - startTime;
meanCbTime_ += (cbTime - meanCbTime_) * .01;
}
}
}
public String report() {
double maxCbTime = 0.0;
for (int i = 0; i < N_STATS; i++) {
double cbTime = endTime_[i] - startTime_[i];
maxCbTime = Math.max(maxCbTime, cbTime);
}
return "max cb = " + Double.toString(maxCbTime * 1000) + "ms";
}
static final int N_STATS = 2000;
double meanCbTime_;
double startTime_[];
double endTime_[];
int bufIx_ = 0;
}

@ -18,7 +18,6 @@ package com.google.synthesizer.android.ui;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
@ -46,6 +45,7 @@ import android.widget.TextView;
import com.google.synthesizer.R;
import com.google.synthesizer.android.AndroidGlue;
import com.google.synthesizer.android.stats.JitterStats;
import com.google.synthesizer.android.widgets.knob.KnobListener;
import com.google.synthesizer.android.widgets.knob.KnobView;
import com.google.synthesizer.android.widgets.piano.PianoView;
@ -120,6 +120,7 @@ public class PianoActivity2 extends Activity {
tryConnectUsb();
}
jitterStats_ = new JitterStats();
statusHandler_ = new Handler();
statusRunnable_ = new Runnable() {
public void run() {
@ -127,15 +128,11 @@ public class PianoActivity2 extends Activity {
if (n > 0) {
byte[] buf = new byte[n];
androidGlue_.readStatsBytes(buf, 0, n);
jitterStats_.aggregate(buf);
TextView statusTextView = (TextView)findViewById(R.id.status);
String statusString = new String(buf);
int nlIndex = statusString.indexOf('\n');
if (nlIndex >= 0) {
statusString = statusString.substring(0, nlIndex);
}
statusTextView.setText(statusString);
statusTextView.setText(jitterStats_.report());
}
statusHandler_.postDelayed(statusRunnable_, 10);
statusHandler_.postDelayed(statusRunnable_, 100);
}
};
statusRunnable_.run();
@ -252,4 +249,5 @@ public class PianoActivity2 extends Activity {
private Spinner presetSpinner_;
private Handler statusHandler_;
private Runnable statusRunnable_;
private JitterStats jitterStats_;
}

@ -27,6 +27,7 @@
#include "synth.h"
#include "freqlut.h"
#include "exp2.h"
#include "sin.h"
#include "synth_unit.h"
@ -137,6 +138,7 @@ Java_com_google_synthesizer_android_AndroidGlue_start(JNIEnv *env,
buffer_size = buf_size;
Freqlut::init(sample_rate);
Exp2::init();
Sin::init();
ring_buffer = new RingBuffer();
stats_ring_buffer = new RingBuffer();

@ -21,6 +21,7 @@
#include "synth.h"
#include "freqlut.h"
#include "patch.h"
#include "exp2.h"
#include "dx7note.h"
using namespace std;
@ -171,8 +172,8 @@ void Dx7Note::compute(int32_t *buf) {
for (int op = 0; op < 6; op++) {
params_[op].gain[0] = params_[op].gain[1];
int32_t level = env_[op].getsample();
// TODO: replace pow with faster calculation
int32_t gain = pow(2, 10 + level * (1.0 / (1 << 24)));
int32_t gain = Exp2::lookup(level - (14 * (1 << 24)));
//int32_t gain = pow(2, 10 + level * (1.0 / (1 << 24)));
params_[op].gain[1] = gain;
}
core_.compute(buf, params_, algorithm_, fb_buf_, fb_shift_);

Loading…
Cancel
Save