我有一些用C ++编写的代码,当我在笔记本电脑上编译它时,结果表明,我已经尝试编译并运行代码到RPI上,我得到了错误:
分段错误
程序(当前)如何运作:
当我尝试将数据拆分为块时,会发生分段错误。尺寸:
rawData - 57884 blockked - 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;
任何建议都将非常感谢:)!希望这是足够的描述。
答案 0 :(得分: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;
}