麻烦大牛帮我把这段C代码转成java的吧,谢谢

大王叫我来巡山 发布于 2017/03/11 19:01
阅读 114
收藏 0
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

void AudioStreamMerge(uint8_t* buf0, int buf_size0,
                      uint8_t* buf1, int buf_size1,
                      uint8_t* output, int output_size)
{
    int min_src_buf_size = buf_size0 < buf_size1 ? buf_size0 : buf_size1;
    int can_fill_size = min_src_buf_size < output_size ? min_src_buf_size : output_size;

    short* s0 = (short*)buf0;
    int s0_size = buf_size0 / 2;

    short* s1 = (short*)buf1;
    int s1_size = buf_size1 / 2;

    short* o1 = (short*)output;
    int sample_size = can_fill_size / 2;
    for (int i = 0; i < sample_size; i++)
    {
        int t0 = *(s0 + i);
        int t1 = *(s1 + i);
        int temp = t0 + t1 - (t0 * t1 >> 0x10);
        if (temp > 32767) 
            temp = 32767;
        else if (temp < -32768) 
            temp = -32768;

        *(o1+i) = temp;
    }

    if ((output_size > buf_size0 && output_size > buf_size1) &&
        buf_size0 != buf_size1)
    {
        if (buf_size0 > buf_size1)
            memcpy(output + can_fill_size, buf0+buf_size1, (buf_size0 - buf_size1));
        else
            memcpy(output + can_fill_size, buf1 + buf_size0, (buf_size1 - buf_size0));
    }
}

需要转成java语言的,谢谢大家了。

加载中
返回顶部
顶部