回答編集履歴

1

追記

2019/11/21 13:26

投稿

asm
asm

スコア15149

test CHANGED
@@ -27,3 +27,87 @@
27
27
 
28
28
 
29
29
  何が違うのかは前回説明したと思います。
30
+
31
+
32
+
33
+
34
+
35
+ ---
36
+
37
+
38
+
39
+
40
+
41
+ 適当に試してみましたが、440Hz付近になります。
42
+
43
+
44
+
45
+ ```c
46
+
47
+ case MM_WIM_DATA: {
48
+
49
+ bTmp = (int16_t*)realloc(bSave, dwLength + ((PWAVEHDR)lp)->dwBytesRecorded);
50
+
51
+ if (blReset || !bTmp) {
52
+
53
+ waveInClose(hWaveIn);
54
+
55
+ blReset = FALSE;
56
+
57
+
58
+
59
+ return 0;
60
+
61
+ }
62
+
63
+ bSave = bTmp;
64
+
65
+ memcpy(bSave + dwLength/2, ((PWAVEHDR)lp)->lpData, ((PWAVEHDR)lp)->dwBytesRecorded);
66
+
67
+ dwLength += ((PWAVEHDR)lp)->dwBytesRecorded;
68
+
69
+
70
+
71
+
72
+
73
+ double* fftbuffer = (double*)malloc(sizeof(double) * ((LPWAVEHDR)lp)->dwBytesRecorded /2);
74
+
75
+ const int NLEN = ((PWAVEHDR)lp)->dwBytesRecorded / 2;
76
+
77
+ if( NLEN > 4096 ){
78
+
79
+ for (dwCount = 0; dwCount < 4096; dwCount++)
80
+
81
+ fftbuffer[dwCount] = ((int16_t*)((PWAVEHDR)lp)->lpData)[dwCount];
82
+
83
+ fft1(fftbuffer, zeroData, 4096, 0, 0);
84
+
85
+ int imax = 0; double max = fftbuffer[0]*fftbuffer[0] + zeroData[0] * zeroData[0];
86
+
87
+ for (int i = 0; i < 4096; i++){
88
+
89
+ if(fftbuffer[i]*fftbuffer[i] + zeroData[i]*zeroData[i] > max){
90
+
91
+ imax = i;
92
+
93
+ max = fftbuffer[i]*fftbuffer[i] + zeroData[i]*zeroData[i];
94
+
95
+ }
96
+
97
+ }
98
+
99
+ cout << 48000.0 / 4096 * imax << max << endl;
100
+
101
+ }
102
+
103
+ waveInAddBuffer(hWaveIn, (PWAVEHDR)lp, sizeof(WAVEHDR));
104
+
105
+ free(fftbuffer);
106
+
107
+
108
+
109
+ return 0;
110
+
111
+ }
112
+
113
+ ```