[問題] C轉成JAVA效率的問題
我抓了一包 Intel/DVI ADPCM coder/decoder.
改寫成JAVA版本, 效率異常的糟糕..
如果改成 JNI 呼叫,效率會比較好嗎?
有沒有人可以給我建議~~
http://www.cs.columbia.edu/~gskc/Code/AdvancedInternetServices/SoundNoiseRatio/dvi_adpcm.c
我改的code:
static void adpcm_decoder(byte[] in_data_ptr, int sidx, short[]
out_data_ptr, int len, ADPCMState state) {
int val_pred; // Predicted value
int vp_diff; // Current change to val_pred
int code; // 包含sign與delta...
int step; // Stepsize
int index; // Current step change index
int input_buffer = 0;
// place to keep next 4-bit value
// 為了抑制最佳化警告...
boolean buffer_step; // toggle between output_buffer/output
int s = sidx, d = 0;
// val_pred=state->ValPrev;
val_pred = state.ValPrev << 3;
index = state.Index;
// step=StepSizeTable[index];
step = StepSizeTable[index] << 3;
for (buffer_step = false; len > 0; len--) {
// Step 1 - get the delta value
if (buffer_step) code = input_buffer & 0xF;
else {
input_buffer = in_data_ptr[s++];
code = (input_buffer >> 4) & 0xF;
}
buffer_step = !buffer_step;
// Step 2 - Find new index value (for later)
index += IndexTable[code];
index = BOUND(index, 0, 88);
// Step 3 - Compute difference and new predicted value
// Computes vp_diff=(delta+0.5)*step/4, but see comment
// in adpcm_coder.
vp_diff = step >> 3;
if ((code & 0x04) != 0) vp_diff += step;
if ((code & 0x02) != 0) vp_diff += step >> 1;
if ((code & 0x01) != 0) vp_diff += step >> 2;
if ((code & 0x08) != 0) val_pred -= vp_diff;
else val_pred += vp_diff;
// Step 4 - clamp output value
// BOUND( val_pred, -32768, 32767 );
val_pred = BOUND(val_pred, -32768 * 8, 32767 * 8);
// Step 5 - Update step value
// step=StepSizeTable[index];
step = StepSizeTable[index] << 3;
// Step 6 - Output value
// *out_data_ptr++=val_pred;
out_data_ptr[d++] = (short)((int)val_pred >> 3);
}
}
public static int DecodeADPCM(byte[] src_data_ptr, int idx, short[]
dest_buf_ptr, int dest_buf_size) {
int data_count;
ADPCMState state = new ADPCMState();
data_count = Tools.ToInt(src_data_ptr, idx + 0);
state.ValPrev = Tools.ToInt(src_data_ptr, idx + 4);
state.Index = Tools.ToInt(src_data_ptr, idx + 8);
if (dest_buf_size < data_count * 2) return -1;
adpcm_decoder(src_data_ptr, idx + 4 * 3, dest_buf_ptr, data_count, state);
data_count *= 2;
return data_count;
}
--
開發 Andorid app...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.70.208.163
→
03/03 22:37, , 1F
03/03 22:37, 1F
→
03/03 23:15, , 2F
03/03 23:15, 2F
※ 編輯: nosrep 來自: 61.70.208.163 (03/04 00:03)
推
03/04 02:42, , 3F
03/04 02:42, 3F
推
03/04 08:10, , 4F
03/04 08:10, 4F
→
03/04 13:52, , 5F
03/04 13:52, 5F
→
03/04 16:23, , 6F
03/04 16:23, 6F
→
03/04 18:07, , 7F
03/04 18:07, 7F
→
03/07 00:07, , 8F
03/07 00:07, 8F
→
03/10 08:34, , 9F
03/10 08:34, 9F