diff --git a/android/res/layout/piano2.xml b/android/res/layout/piano2.xml
index 8ffbad7..fe71d67 100644
--- a/android/res/layout/piano2.xml
+++ b/android/res/layout/piano2.xml
@@ -18,19 +18,15 @@
android:gravity="center_horizontal" />
@@ -39,13 +35,13 @@
app:value="1.0"
app:min="0"
app:max="1"
- android:layout_margin="2px" />
+ android:layout_margin="2dp" />
+ android:layout_margin="2dp" />
@@ -58,8 +54,19 @@
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_span="6"
/>
+
+
diff --git a/android/res/raw/drums.sf2 b/android/res/raw/drums.sf2
deleted file mode 100644
index 9f8e88f..0000000
Binary files a/android/res/raw/drums.sf2 and /dev/null differ
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index c087a5a..4260e72 100644
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -77,4 +77,6 @@
- Amplification
- Effects
+
+ Capture
diff --git a/android/src/com/google/synthesizer/android/service/SynthesizerService.java b/android/src/com/google/synthesizer/android/service/SynthesizerService.java
index 187cb6f..d80b4da 100755
--- a/android/src/com/google/synthesizer/android/service/SynthesizerService.java
+++ b/android/src/com/google/synthesizer/android/service/SynthesizerService.java
@@ -69,13 +69,13 @@ public class SynthesizerService extends Service {
// For now, cap the sample rate to reduce cpu requirements.
sampleRateInHz = Math.min(sampleRateInHz, 11025);
SoundFontReader sampleLibrary = null;
- InputStream sampleLibraryFile = getResources().openRawResource(R.raw.drums);
- try {
- sampleLibrary = new SoundFontReader(sampleLibraryFile);
- } catch (IOException e) {
- logger_.log(Level.SEVERE, "Unable to load sample library.", e);
- sampleLibrary = null;
- }
+ //InputStream sampleLibraryFile = getResources().openRawResource(R.raw.drums);
+ //try {
+ // sampleLibrary = new SoundFontReader(sampleLibraryFile);
+ //} catch (IOException e) {
+ // logger_.log(Level.SEVERE, "Unable to load sample library.", e);
+ // sampleLibrary = null;
+ //}
synthesizer_ = new MultiChannelSynthesizer(CHANNELS, FINGERS, sampleRateInHz, sampleLibrary);
// Load the presets from a file.
diff --git a/android/src/com/google/synthesizer/android/stats/JitterStats.java b/android/src/com/google/synthesizer/android/stats/JitterStats.java
index 58e395d..abc743d 100644
--- a/android/src/com/google/synthesizer/android/stats/JitterStats.java
+++ b/android/src/com/google/synthesizer/android/stats/JitterStats.java
@@ -35,10 +35,27 @@ public class JitterStats {
return "max cb = " + Double.toString(maxCbTime * 1000) + "ms";
}
+ public void setNominalCb(double nominalCb) {
+ nominalCbPeriod_ = nominalCb;
+ }
+
+ public String reportLong() {
+ StringBuilder sb = new StringBuilder();
+ double startTime = startTime_[bufIx_];
+ for (int i = 0; i < N_STATS; i++) {
+ double nominalStart = startTime + nominalCbPeriod_ * i;
+ double thisStart = startTime_[(bufIx_ + i) % N_STATS] - nominalStart;
+ double thisEnd = endTime_[(bufIx_ + i) % N_STATS] - nominalStart;
+ sb.append(thisStart + " " + thisEnd + "\n");
+ }
+ return sb.toString();
+ }
+
static final int N_STATS = 2000;
double meanCbTime_;
double startTime_[];
double endTime_[];
+ double nominalCbPeriod_;
int bufIx_ = 0;
}
diff --git a/android/src/com/google/synthesizer/android/ui/PianoActivity2.java b/android/src/com/google/synthesizer/android/ui/PianoActivity2.java
index 69eaaa2..01c79aa 100644
--- a/android/src/com/google/synthesizer/android/ui/PianoActivity2.java
+++ b/android/src/com/google/synthesizer/android/ui/PianoActivity2.java
@@ -37,9 +37,11 @@ import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
+import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
+import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
@@ -74,6 +76,8 @@ public class PianoActivity2 extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
getJbMr1Params(params);
}
+ //params.sampleRate = 44100;
+ //params.bufferSize = 976;
androidGlue_ = new AndroidGlue();
androidGlue_.start(params.sampleRate, params.bufferSize);
@@ -121,6 +125,7 @@ public class PianoActivity2 extends Activity {
}
jitterStats_ = new JitterStats();
+ jitterStats_.setNominalCb(params.bufferSize / (double)params.sampleRate);
statusHandler_ = new Handler();
statusRunnable_ = new Runnable() {
public void run() {
@@ -136,6 +141,30 @@ public class PianoActivity2 extends Activity {
}
};
statusRunnable_.run();
+
+ // Create burst of load -- test code to be removed. Ultimately we'll
+ // be able to get this kind of functionality by hooking up the sequencer
+ if (false) {
+ new Handler().postDelayed(new Runnable() {
+ public void run() {
+ int n = 110;
+ byte[] midi = new byte[n * 3];
+ for (int i = 0; i < n; i++) {
+ midi[i * 3] = (byte)0x90;
+ midi[i * 3 + 1] = (byte)(1 + i);
+ midi[i * 3 + 2] = 64;
+ }
+ androidGlue_.sendMidi(midi);
+ }
+ }, 10000);
+ }
+ Button captureButton = (Button) findViewById(R.id.capture);
+ captureButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ TextView stats = (TextView) findViewById(R.id.stats);
+ stats.setText(jitterStats_.reportLong());
+ }
+ });
}
@Override
diff --git a/cpp/src/android_glue.cc b/cpp/src/android_glue.cc
index 123ab3f..511acff 100644
--- a/cpp/src/android_glue.cc
+++ b/cpp/src/android_glue.cc
@@ -89,13 +89,16 @@ extern "C" void BqPlayerCallback(SLAndroidSimpleBufferQueueItf queueItf,
double start_time = ts_to_double(&tp);
int16_t *buf_ptr = buffer + buffer_size * cur_buffer;
synth_unit->GetSamples(buffer_size, buf_ptr);
+ char buf[64];
+ //uint8_t *mem = new uint8_t[1024];
+ //delete[] mem;
+ //sprintf(buf, "%.6f", start_time);
clock_gettime(CLOCK_MONOTONIC, &tp);
double end_time = ts_to_double(&tp);
SLresult result = (*queueItf)->Enqueue(bq_player_buffer_queue,
buf_ptr, buffer_size * 2);
assert(SL_RESULT_SUCCESS == result);
cur_buffer = (cur_buffer + 1) % N_BUFFERS;
- char buf[64];
size_t i = 0;
buf[i++] = 't';
buf[i++] = 's';
diff --git a/cpp/src/fm_core.cc b/cpp/src/fm_core.cc
index 3066a09..a6ebe1d 100644
--- a/cpp/src/fm_core.cc
+++ b/cpp/src/fm_core.cc
@@ -18,10 +18,6 @@
#include
#endif
-#ifdef __ANDROID_API__
-#include
-#endif
-
#include "synth.h"
#include "fm_op_kernel.h"
#include "fm_core.h"