0

我想知道如何确保在以下音频代码中利用 cpu 流水线:

int sample_count = 100;
// volume array - value to multiply audio sample by
double volume[4][4];
// fill volume array with values here

// audio sample array - really this is 125 samples by 16 channels but smaller here for clarity
double samples[sample_count][4];
// fill samples array with audio samples here
double tmp[4];

for (x=0;x<sample_count;x++) {
    tmp[0] = samples[x][0]*volume[0][0] + samples[x][1]*volume[1][0] + samples[x][2]*volume[2][0] + samples[x][3]*volume[3][0]; 
    tmp[1] = samples[x][0]*volume[0][1] + samples[x][1]*volume[1][1] + samples[x][2]*volume[2][1] + samples[x][3]*volume[3][1]; 
    tmp[2] = samples[x][0]*volume[0][2] + samples[x][1]*volume[1][2] + samples[x][2]*volume[2][2] + samples[x][3]*volume[3][2]; 
    tmp[3] = samples[x][0]*volume[0][3] + samples[x][1]*volume[1][3] + samples[x][2]*volume[2][3] + samples[x][3]*volume[3][3]; 

    samples[x][0] = tmp[0];
    samples[x][1] = tmp[1];
    samples[x][2] = tmp[2];
    samples[x][3] = tmp[3];
}

// write sample array out to hardware here.

如果没有立即清除,这会将 4 个输入通道通过 4x4 音量控制矩阵混合到 4 个输出通道中。

我实际上比上面的例子更密集地执行这个,我不确定如何定制我的代码以利用流水线(这似乎适合)。我是否应该一次在样本数组的一个“通道”上工作,以便可以多次操作相同的值(对于同一通道的连续样本)?但是,这样我将不得不检查 x 的 > sample_count 4 次。我可以使 tmp 二维且足够大以容纳完整的缓冲区,如果以这种方式处理它会使 cpu 管道有效。或者上面的代码管道会有效吗?有没有一种简单的方法来检查流水线是否正在发生?TIA。

4

0 回答 0