2013-11-15 5 views
-1
Unhandled exception at 0x779615de in main.exe: 0xC0000005: Access violation writing location 0x003d0038. 

wav 파일을 입력 한 후 오류 메시지가 나타납니다.main.exe의 0x779615de에서 처리되지 않은 예외 : 0xC0000005 : 액세스 위반 쓰기 위치 0x003f0014

아래 코드는 잘하면 일부 조언을 얻을 수 있습니다. "내가"단지 4221까지 반복

fft.h

#include <math.h> 
#include <stdio.h> 
#include <stddef.h> 
#include <stdlib.h> 

#define NR_END 1 
#define FREE_ARG char* 
#define M_PI 3.14159265358979323846264338327 

static double sqrarg; 
#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg * sqrarg) 
#define WINDOW(j,a,b) (1.0 - fabs((((j)-1)-(a))*(b))) //Bartlett 

void nrerror(char error_text []) 
/* Numerical Recipes standard error handle*/  
{ 
fprintf(stderr, "Numerical Recipes run time-time error...\n"); 
fprintf(stderr, "%s\n", error_text); 
fprintf(stderr, "...now exiting to system...\n"); 
exit(1); 
} 

#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr 

void four1(double data[], unsigned long nn, int isign) 
{ 
unsigned long n,mmax,m,j,istep,i; 
double wtemp, wr,wpr,wpi,wi,theta; 
double tempr, tempi; 

n=nn<<1; 
j=1; 
for(i=1;i<n;i+=2) 
{ 
    if(j > i){ 
     SWAP(data[j],data[i]); 
     SWAP(data[j+1],data[i+1]); 
    } 
    m=n >> 1; 
    while (m >= 2 && j >m) 
    { 
     j -=m; 
     m>>=1; 
    } 
    j +=m; 
} 
mmax=2; 
while (n > mmax) 
{ 
    istep = mmax << 1; 
    theta = isign*(6.28318530717959/mmax); 
    wtemp=sin(0.5*theta); 
    wpr = -2.0*wtemp*wtemp; 
    wpi = sin (theta); 
    wr=1.0; 
    wi=0.0; 
    for(m=1;m<mmax;m+=2) 
    { 
     for(i=m;i<=n;i+=istep) 
     { 
      j=i+mmax; 
      tempr=wr*data[j]-wi*data[j+1]; 
      tempi=wr*data[j+1]+wi*data[j]; 
      data[j]=data[i]-tempr; 
      data[j+i]=data[i+1]-tempi; 
      data[i]+=tempr; 
      data[i+1] +=tempi; 
     } 
      wr=(wtemp=wr)*wpr-wi*wpi+wr; 
      wi=wi*wpr+wtemp*wpi+wi; 
    } 
     mmax = istep; 
} 
} 

void realft(double data[], unsigned long n, int isign) 
{ 
void four1(double data[], unsigned long nm, int isign); 
unsigned long i,i1,i2,i3,i4,np3; 
double c1=0.5,c2,h1r,h1i,h2r,h2i; 
double wr,wi,wpr,wpi,wtemp,theta; 

theta=3.141592653589793/(double) (n>>1); 
if(isign ==1) 
{ 
    c2 = -0.5; 
    four1(data,n>>1,1); 
} 
else 
{ 
    c2=0.5; 
    theta=-theta; 
} 
wtemp = sin(0.5*theta); 
wpr = -2.0*wtemp*wtemp; 
wpi=sin(theta); 
wr=1.0+wpr; 
wi=wpi; 
np3=n+3; 
for(i=2;i<=(n>>2);i++) 
{ 
    i4=1+(i3=np3-(i2=1+(i1=i+i-1))); 
    h1r=c1*(data[i1]+data[i3]); 
    h1i=c1*(data[i2]-data[i4]); 
    h2r= -c2*(data[i2]+data[i4]); 
    h2i=c2*(data[i1]-data[i3]); 
    data[i1]=h1r+wr*h2r-wi*h2i; 
    data[i2]=h1i+wr*h2i+wi*h2r; 
    data[i3]=h1r-wr*h2r+wi*h2i; 
    data[i4]= -h1i+wr*h2i+wi*h2r; 
    wr=(wtemp=wr)*wpr-wi*wpi+wr; 
    wi=wi*wpr+wtemp*wpi+wi; 
} 
if(isign == 1) 
{ 
    data[1]=(h1r=data[1])+data[2]; 
    data[2] = h1r-data[2]; 
} 
else{ 
    data[1]=c1*((h1r=data[1])+data[2]); 
    data[2]=c1*(h1r-data[2]); 
    four1(data,n>>1,-1); 
} 
    } 

가능한 문제

"N"= 8192,하지만 당신을 감사하는 것은 다음 오류

for(i=m;i<=n;i+=istep) 
     { 
      j=i+mmax; 
      tempr=wr*data[j]-wi*data[j+1]; 
      tempi=wr*data[j+1]+wi*data[j]; 
      data[j]=data[i]-tempr; 
      data[j+i]=data[i+1]-tempi; 
      data[i]+=tempr; 
      data[i+1] +=tempi; 
     } 
에게 원인
+2

디버거를 사용하여 문제를 줄이지 않는 이유는 450 라인 이상의 코드를 게시하는 대신 대답을 얻을 수 있습니다. –

+0

TL; DR. 디버깅 기술을 배우거나 SSCCE (http://sscce.org/)를 보내야합니다. 특히 첫 번째 'S'라고 쓰고 있습니다 :-) – paxdiablo

+0

문제를 일으키는 범위를 좁혔습니다. – Syncho

답변

0

FORTRAN-cum-C/C++ FFT 코드 (헤더 파일 n o less!)는 여전히 1에서 시작하는 배열을 색인화하지만 C/C++ 색인은 0부터 시작합니다. 따라서 배열의 끝을 넘어 대부분 충돌이 발생합니다.

오, 이라는 (사용되지 않는) 함수를 선언하는 동안 또 #include <vector>을 갖는 것에 대한 특별한 명성이 있습니다. 그들은 매우 다른 두 가지 작업을 수행합니다 ....