0

我有一些用 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;

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

4

1 回答 1

2

您可能在某处超出了数组(甚至可能不在您发布的代码中)。我也不确定您要对阻塞做什么,但我想您想将波形文件拆分为 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;
}
于 2012-10-15T19:51:13.870 回答