}
} else {
// we assume that it is 44k1 stereo 16 bit and down sample
// nothing clever - no anti alias etc....
ByteBuffer bbs = ByteBuffer.wrap(s);
ByteBuffer bbd = ByteBuffer.wrap(d);
// iterate over the values we have,
// add them to the taget bucket they fall into
// and count the drops....
int drange = d.length / 2;
double v[] = new double[drange];
double w[] = new double[drange];
double rat = 8000.0 / 44100.0;
int top = s.length / 2;
for (int eo = 0; eo < top; eo++) {
int samp = (int) Math.floor(eo * rat);
if (samp >= drange) {
samp = drange - 1;
}
v[samp] += bbs.getShort(eo * 2);
w[samp]++;
}
// now reweight the samples to ensure
// no volume quirks
// and move to short
short vw = 0;
for (int ei = 0; ei < drange; ei++) {
if (w[ei] != 0) {
vw = (short) (v[ei] / w[ei]);
}
bbd.putShort(ei * 2, vw);
}
}
}