我有一些用C ++编写的代码,当我在笔记本电脑上对其进行编译时,结果显示,但是,我尝试将代码编译并运行到RPI上,但出现错误:


  分段故障


该程序(当前)的工作方式:


将(.wav)文件读入双精度向量(“ rawData”)
将rawData拆分为块(阻塞)


当我尝试将数据拆分为块时,就会发生分段错误。尺寸:

rawData-57884
被封锁-112800

现在我知道RPI只有256MB,这可能是问题所在,或者我没有正确处理数据。我还提供了一些代码,以帮助演示事情的运行方式:

(main.cpp):

int main()
{
int N = 600;
int M = 200;

float sumthresh = 0.035;
float zerocorssthres = 0.060;

Wav sampleWave;

if(!sampleWave.readAudio("repositry/example.wav", DOUBLE))
{
    cout << "Cannot open the file BOOM";

}

// Return the data
vector<double> rawData = sampleWave.returnRaw();
// THIS segments (typedef vector<double> iniMatrix;)
vector<iniMatrix> blockked = sampleWave.something(rawData, N, M);


cout << rawData.size();

return EXIT_SUCCESS;
}


(功能:某物)

int n = theData.size();
int maxblockstart = n - N;
int lastblockstart = maxblockstart - (maxblockstart % M);

int numblocks = (lastblockstart)/M + 1;
vector< vector<double> > subBlock;
vector<double> temp;
this->width = N;
this->height = numblocks;

subBlock.resize(600*187);
for(int i=0; (i < 600); i++)
{
    subBlock.push_back(vector<double>());
    for(int j=0; (j < 187); j++)
    {
        subBlock[i].push_back(theData[i*N+j]);
    }
}
return subBlock;


任何建议将不胜感激 :)!希望这是足够的描述。

最佳答案

您可能在某个地方溢出了一个数组(甚至在您发布的代码中也是如此)。我也不是很确定您打算如何处理阻塞,但是我想您想将wave文件拆分为600个样本块吗?

如果是这样,我认为您想要更多类似以下内容的东西:

std::vector<std::vector<double>>
SimpleWav::something(const std::vector<double>& data, int N) {

    //How many blocks of size N can we get?
    int num_blocks = data.size() / N;

    //Create the vector with enough empty slots for num_blocks blocks
    std::vector<std::vector<double>> blocked(num_blocks);

    //Loop over all the blocks
    for(int i = 0; i < num_blocks; i++) {
        //Resize the inner vector to fit this block
        blocked[i].resize(N);

        //Pull each sample for this block
        for(int j = 0; j < N; j++) {
            blocked[i][j] = data[i*N + j];
        }
    }

    return blocked;
}

10-08 11:16