Implement & exercise getKeyFrameMap in JNI
This commit is contained in:
@@ -23,6 +23,9 @@
|
||||
|
||||
package com.breakfastquay.rubberband;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class RubberBandStretcher
|
||||
{
|
||||
public RubberBandStretcher(int sampleRate, int channels,
|
||||
@@ -62,6 +65,19 @@ public class RubberBandStretcher
|
||||
public native int getSamplesRequired();
|
||||
|
||||
public native void setKeyFrameMap(long[] from, long[] to);
|
||||
public void setKeyFrameMap(Map<Long, Long> m) {
|
||||
Set<Long> keys = m.keySet();
|
||||
int n = keys.size();
|
||||
long[] from = new long[n];
|
||||
long[] to = new long[n];
|
||||
int i = 0;
|
||||
for (Long k : keys) {
|
||||
from[i] = k.longValue();
|
||||
to[i] = m.get(k).longValue();
|
||||
++i;
|
||||
}
|
||||
setKeyFrameMap(from, to);
|
||||
}
|
||||
|
||||
public native void study(float[][] input, int offset, int n, boolean finalBlock);
|
||||
public void study(float[][] input, boolean finalBlock) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.breakfastquay.rubberband.test;
|
||||
|
||||
import com.breakfastquay.rubberband.RubberBandStretcher;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RubberBandTest
|
||||
{
|
||||
|
||||
@@ -15,7 +17,7 @@ public class RubberBandTest
|
||||
(rate,
|
||||
channels,
|
||||
RubberBandStretcher.OptionEngineFiner +
|
||||
RubberBandStretcher.OptionProcessRealTime,
|
||||
RubberBandStretcher.OptionProcessOffline,
|
||||
1.0,
|
||||
1.0);
|
||||
|
||||
@@ -38,11 +40,16 @@ public class RubberBandTest
|
||||
));
|
||||
|
||||
int blocksize = 1024;
|
||||
int blocks = 200;
|
||||
int blocks = 400;
|
||||
double freq = 440.0;
|
||||
|
||||
stretcher.setMaxProcessSize(blocksize);
|
||||
|
||||
TreeMap<Long, Long> keyFrameMap = new TreeMap<Long, Long>();
|
||||
keyFrameMap.put((long)(3 * rate), (long)(4 * rate));
|
||||
keyFrameMap.put((long)(5 * rate), (long)(5 * rate));
|
||||
stretcher.setKeyFrameMap(keyFrameMap);
|
||||
|
||||
float[][] buffer = new float[channels][blocksize];
|
||||
|
||||
int i0 = 0;
|
||||
@@ -53,6 +60,27 @@ public class RubberBandTest
|
||||
for (int i = 0; i < blocksize; ++i) {
|
||||
buffer[c][i] = (float)Math.sin
|
||||
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
|
||||
if (i0 % rate == 0) {
|
||||
buffer[c][i] = 1.f;
|
||||
}
|
||||
++i0;
|
||||
}
|
||||
}
|
||||
|
||||
stretcher.study(buffer, block + 1 == blocks);
|
||||
}
|
||||
|
||||
i0 = 0;
|
||||
|
||||
for (int block = 0; block < blocks; ++block) {
|
||||
|
||||
for (int c = 0; c < channels; ++c) {
|
||||
for (int i = 0; i < blocksize; ++i) {
|
||||
buffer[c][i] = (float)Math.sin
|
||||
((double)i0 * freq * Math.PI * 2.0 / (double)rate);
|
||||
if (i0 % rate == 0) {
|
||||
buffer[c][i] = 1.f;
|
||||
}
|
||||
++i0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user