Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有一种快速的方法可以将同一阵列以不同的偏移量复制到另一个阵列上数千次?_Java_Arrays_Performance_Audio - Fatal编程技术网

Java 有没有一种快速的方法可以将同一阵列以不同的偏移量复制到另一个阵列上数千次?

Java 有没有一种快速的方法可以将同一阵列以不同的偏移量复制到另一个阵列上数千次?,java,arrays,performance,audio,Java,Arrays,Performance,Audio,我试图创造一个声音混响效果。它工作得很好,但有一个问题:它以不同的偏移量和不同的音量复制一个巨大的阵列数千次,在4分钟的音频样本上处理一个小的混响效果需要10分钟。有没有办法加快这个过程?如果需要,我可以很容易地列出所有延误 编辑:这是我的代码。有没有更好的方法来达到相同或相似的结果?SoundSource是一个包含声音和位置的类。WaveNode包含WavePath实例的位置和阵列列表,这些实例定义了有关回波的各种参数。如果还有什么不清楚的,请告诉我 public static double[

我试图创造一个声音混响效果。它工作得很好,但有一个问题:它以不同的偏移量和不同的音量复制一个巨大的阵列数千次,在4分钟的音频样本上处理一个小的混响效果需要10分钟。有没有办法加快这个过程?如果需要,我可以很容易地列出所有延误

编辑:这是我的代码。有没有更好的方法来达到相同或相似的结果?SoundSource是一个包含声音和位置的类。WaveNode包含WavePath实例的位置和阵列列表,这些实例定义了有关回波的各种参数。如果还有什么不清楚的,请告诉我

public static double[][] render(int sampleLength, int sampleRate, int depth) //depth is number of echoes, must be at least 0
{
    init(sampleLength, sampleRate);

    for (int iSource = 0; iSource < sourceList.size(); iSource++)
    {
        renderNode(sourceList.get(iSource).getSoundSource(), sourceList.get(iSource), 0, depth);
    }

    double[][] r = sampleData.clone();
    sampleData = null;
    return r;
}

private static void renderNode(SoundSource source, WaveNode node, int curDepth, int maxDepth)
{
    SoundSource newSource;
    WaveNode newNode;
    WavePath path;

    addSource(source.clone(), node.smoothing, node.decay);

    if (curDepth < maxDepth)
    {
        for (int i = 0; i < node.getPathList().size(); i++)
        {
            path = node.getPathList().get(i);
            newNode = findReflection(path.destId);
            newSource = SoundSource.reflection(SoundSource.swapData(source, Filter.amplify(source.getSampleData(), path.decay)), newNode.getPos(), path.smoothing);
            renderNode(newSource, newNode, curDepth + 1, maxDepth);
        }
    }
}

private static void addSource(SoundSource source, double smoothing, double decay)
{
    Vector3d pos, pos2;
    double dist, volume, soundPos, sample;
    int delay;
    double[] sourceData;

    for (int channel = 0; channel < 2; channel++)
    {
        pos = source.getPos();
        pos2 = new Vector3d(pos.x, pos.y, pos.z);
        pos2.x += earDist / 2 - earDist * channel;

        dist = Math.max(pos2.length() + source.getSourceDist(), 0.000001);
        volume = decay / dist;
        delay = (int)(dist / 343.2 * sampleRate);

        sourceData = source.getSampleData();

        sample = 0;

        for (int j = 0; j < Math.min(sourceData.length, sampleLength - delay); j++)
        {
            sample = sourceData[j] / smoothing + sample * (1 - 1 / smoothing);
            sampleData[channel][j + delay] += sample * volume;
        }
    }
}
publicstaticdouble[]render(int-sampleLength,int-sampleRate,int-depth)//depth是回声的数量,必须至少为0
{
初始值(样本长度,取样器);
对于(int-isoource=0;isoource
如果是同一个数组,只是偏移量不同,是否每次都需要复制?是否可以偏移到同一个数组中并重用该数组?是将数组或其中的元素复制到另一个数组中?你能给我们看一些代码吗?请告诉我们你是如何做到这一点的。如果不了解您已经在做什么,我们无法真正告诉您如何改进它。请删除COBOL样式的变量声明部分,使其更具可读性。然后用乘法代替除法,您可能会获得10倍。一般来说,System.arraycopy是将元素从一个数组大容量复制到另一个数组的最快方法。