我有一些用 C++ 编写的代码,当我在我的笔记本电脑上编译它时,结果显示,然而,我试图在 RPI 上编译和运行代码,但我得到了错误:
Segmentation fault
程序(当前)的工作方式:
- 将 (.wav) 文件读入 double vector (“rawData”)
- 将原始数据拆分成 block (blockked)
当我尝试将数据拆分为 block 时发生段错误。尺寸:
原始数据 - 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 个样本 block ?
如果是这样,我想你想要更像下面这样的东西:
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;
}
关于c++ - Raspberry Pi C++ 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12902041/