반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { FILE *fp; short *buffer; long int file_length; short max = 0; short min = 0; short level = 0; short dB = 0; int i = 0; int jum=0; float count = 0; int plus = 0; int minus =0; float period =0; int flag_first = 0; int onezero=0; fp = fopen("a.pcm","rb"); if(fp == NULL) //파일열기 이상있는지 체크 { printf("파일오픈 실패!\n"); return 0; } fseek(fp, 0L, SEEK_END);//파일끝으로 이동; printf("파일의 끝은(파일의크기) %d 입니다.\n",ftell(fp)); //fseek 후 파일 포인터 위치 확인 file_length = ftell(fp); //파일 길이 fseek(fp, 0L, SEEK_SET);//다시파일의 맨 앞으로 이동 buffer = (short*)malloc(file_length); //파일길이만큼 동적메모리 생성 fread(buffer,2,file_length/2,fp); //버퍼에 받기 fclose(fp); //파일닫기 for (i=0; i<file_length/2; i++)//점갯수만큼 비교 { if (!(i<46545*0.6)) // 600ms 범위 제외 { if (buffer[i] > max) //최대값 max = buffer[i]; if (buffer[i] < min) //최소값 min = buffer[i]; count++; //점갯수 jum++; //점갯수 //////////////////주기,주파수//////////////////////////// if(buffer[i] > 0 && flag_first == 0) //처음 숫자가 양수면 onezero = 1; flag_first= 1; if(buffer[i] < 0 && flag_first ==0) //처음 숫자가 음수면 onezero = -1; flag_first=-1; if (flag_first == 1) { if (buffer[i] < 0 && onezero > 0) //현재 값이 음수이고, 전에 언젠가 양수가 있었으면 주기증가 { period++; onezero = -1; } if (buffer[i] > 0) { onezero = 1; } } if (flag_first ==-1) { if(buffer[i]>0 && onezero <0) { period++; onezero = 1; } if(buffer[i]<0) { onezero=-1; } } } } level = (max-min)/2; dB = -96 + (20 * log10(level*2) ); //dB = -96 + (20 * log10(level*2)); printf("max : %d\n",max); printf("min : %d\n",min); printf("level : %d\n",level); printf("dB : %ddB\n",dB); printf("600ms제외한 점 갯수 :%d\n",jum); printf("시간: %f초 \n", count/46545); printf("주기 갯수 : %f \n",period); printf("주파수 : %f\n",period/(count/46545)); } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { FILE *fp; short *buffer; long int file_length; short max = 0; short min = 0; short level = 0; short dB = 0; int i = 0; int jum=0; float count = 0; int plus = 0; int minus =0; float period =0; int flag_first = 0; int onezero=0; fp = fopen("a.pcm","rb"); if(fp == NULL) //파일열기 이상있는지 체크 { printf("파일오픈 실패!\n"); return 0; } fseek(fp, 0L, SEEK_END);//파일끝으로 이동; printf("파일의 끝은(파일의크기) %d 입니다.\n",ftell(fp)); //fseek 후 파일 포인터 위치 확인 file_length = ftell(fp); //파일 길이 fseek(fp, 0L, SEEK_SET);//다시파일의 맨 앞으로 이동 buffer = (short*)malloc(file_length); //파일길이만큼 동적메모리 생성 fread(buffer,2,file_length/2,fp); //버퍼에 받기 fclose(fp); //파일닫기 for (i=0; i<file_length/2; i++)//점갯수만큼 비교 { if (!(i<46545*0.6)) // 600ms 범위 제외 { if (buffer[i] > max) //최대값 max = buffer[i]; if (buffer[i] < min) //최소값 min = buffer[i]; count++; //점갯수 jum++; //점갯수 //////////////////주기,주파수//////////////////////////// if(buffer[i] > 0 && flag_first == 0) //처음 숫자가 양수면 onezero = 1; flag_first= 1; if(buffer[i] < 0 && flag_first ==0) //처음 숫자가 음수면 onezero = -1; flag_first=-1; if (flag_first == 1) // 처음수 양수일때 { if (buffer[i] < 0 && onezero > 0) //현재 값이 음수이고, 전에 언젠가 양수가 있었으면 주기증가 { period++; onezero = -1; } if (buffer[i] > 0) { onezero = 1; } } if (flag_first ==-1) //처음수 음수일때 { if(buffer[i]>0 && onezero <0) { period++; onezero = 1; } if(buffer[i]<0) { onezero=-1; } } } } level = (max-min)/2; dB = -96 + (20 * log10(level*2) ); //dB = -96 + (20 * log10(level*2)); printf("max : %d\n",max); printf("min : %d\n",min); printf("level : %d\n",level); printf("dB : %ddB\n",dB); printf("600ms제외한 점 갯수 :%d\n",jum); printf("시간: %f초 \n", count/46545); printf("주기갯수 : %f \n",(period-1)); printf("주기 : %f \n",(period-1)/(count/46545)); printf("주파수 : %f\n",1/((period-1)/(count/46545))); } | cs |
반응형