Well an access violation is a pretty clear indicator of an out-of-bounds array access.
You are not stepping out of bounds on frames, so you must be stepping out of bounds on Sample.
Let's put this another way: How big is Sample? I can't tell from the above code. (EDIT: actually I can... give me a bit and I'll review again. Sorry about that)
Also... change this:
1 2 3 4 5 6 7 8
|
for(int n = 0; n < FrmLen; n++)
{
// if(k!=0) // get rid of all this crap
// {
frames[k][n] = Sample[n +(k * FrmLen)]; // just do this
// }
// else frames[k][n] = Sample[n];
}
|
Don't try to micro-optimize like that. The computer can do math like it's nothing -- conditionals are usually slower. Not to mention that needlessly makes your code larger.
EDIT2:
Wait a minute, you're spinning on FrmLen, but you're allocating based on FrmPer. That's got to be the problem.
What are FrmPer / FrmLen? Like what do they represent? FrmLen seems like it'd be the length of a frame, which make sense, but then what does FrmPer do?
This line:
int nFrms = (nSamples - FrmPer) / FrmPer;
I wonder if that should be this instead:
int nFrms = (nSamples - FrmLen) / FrmLen;
I'm 99% sure that would fix the problem.
But you'd still have a problem if nSamples is less than FrmLen.