For some reasons, I need to convert the samples of a audio into byte[] for network transmission. I found a function for short2bytearray
public static byte[] short2byte(short in) {
byte[] ret = new byte[2];
ret[0] = (byte) (in & 0xff);
ret[1] = (byte) ((in >> 8) & 0xff);
return ret;
}
because the audio keeps playing and samples are keep taking, so I save samples into a HashMap first and then open a thread to process this map.
private void convert() {
Thread conv = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// while (needConver) {
Iterator<Entry<Integer, short[]>> iter = sampleBuffer
.entrySet().iterator();
Log.i("Converting", "enter");
if (iter.hasNext()) {
Entry<Integer, short[]> entry = iter.next();
//stops in here
byte[] converted = new byte[entry.getValue().length * 2];
for (short in : entry.getValue()) {
Admin.combineByteArray(converted, Admin.short2byte(in));
}
convertedBuffer.put(entry.getKey(), converted);
sampleBuffer.remove(entry.getKey());
}
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// }
}
});
conv.start();
}
The thread will only create once. I want it too keep tracking the sampleBuffer and convert data that stores in it. However, when I run the conversation function Admin.short2byte(in), it will output lots of information like
`03-22 14:52:48.004: D/dalvikvm(24194): GC_FOR_ALLOC freed 4096K, 50% free 8517K/16839K, paused 13ms, total 13ms`
could you please tell me why and how to fix this? thank you
03-22 14:52:48.004: D/dalvikvm(24194): GC_FOR_ALLOC freed 4096K, 50% free 8517K/16839K, paused 13ms, total 13msbut I know it's not errorssampleBufferwhile you are iterating through it. Also, what doesAdmin.combineByteArraydo?