我需要将大小为N的一维数组转换为大小为A*B> N的二维数组,让我们以这种情况为例:
int oneDimensionalArray[6] = {7, 8, 10, 11, 12, 15};
//then the second array would be
int twoDimensionalArray[2][4] = {{7, 8, 10, 11},
{10, 11, 12, 15}};
这用于数字声音处理中所谓的重叠添加方法。我试过这种方法,结果不正确:
for(unsigned long i = 0; i < amountOfWindows; i++)
{
for(unsigned long j = hopSize; j < windowLength; j++)
{
//buffer without the overlapping
if( (i * amountOfWindows + j) >= bufferLength)
break;
windowedBuffer[i][j] = unwindowedBuffer[i * amountOfWindows + j];
}
}
for(unsigned long i = 1; i < amountOfWindows; i++ )
{
for(unsigned long j = 0; j < hopSize; j++)
{
// Filling the overlapping region
windowedBuffer[i][j] = windowedBuffer[i-1][windowLength - hopSize + i];
}
}
我也试着用模操作找到关系,但我找不到正确的一个。这是我尝试过的:
windowedBuffer[m][n % (windowLength - hopSize)] = unwindowedBuffer[n];
既然你已经知道hopSize
(从你的评论),你想要的只是:
for (size_t i = 0; i < amountOfWindows; ++i) {
for (size_t j = 0; j < windowLength; ++j) {
windowedBuffer[i][j] = unwindowedBuffer[i * hopSize + j];
}
}
其中amountOfWindows
、windowLength
、hopSize
为您的参数。