-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
194 lines (169 loc) · 4.94 KB
/
main.c
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* @Author: your name
* @Date: 2021-04-10 14:42:57
* @LastEditTime: 2021-04-11 18:35:40
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \GCC-PHAT\main.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "DelaySum.h"
#include "enframe.h"
#include "hamming.h"
#include "kiss_fftr.h"
#include "kiss_fft.h"
#include "kiss_fftr.h"
#include "my_math.h"
int main()
{
FILE *fp = NULL;
int32_t filesize;
int32_t result;
int32_t samples = 4096;
int8_t N = 8;
int32_t *buffer;
uint32_t fs = 48000;
fp = fopen("C:\\Users\\IRON\\Desktop\\tdoa_c\\GCC-PHAT\\bin\\voice.bin", "rb+");
if (fp == NULL)
{
printf("can't open file");
return 0;
}
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
rewind(fp);
buffer = (int32_t *)malloc(sizeof(char) * filesize);
if (buffer == NULL)
{
fputs("Memory error", stderr);
exit(2);
}
// copy the file into the buffer:
result = fread(buffer, sizeof(int32_t), filesize / 4, fp);
if (result != filesize / 4)
{
fputs("Reading error", stderr);
exit(3);
}
fclose(fp);
printf("read ok!");
float *data[N];
for (uint16_t i = 0; i < N; i++)
{
data[i] = (float *)malloc(sizeof(float) * samples);
}
for (uint16_t i = 0; i < N; i++)
{
for (uint32_t j = 0; j < samples; j++)
{
*(data[i] + j) = (float)*(buffer + i + 8 * j) ;
}
}
//分帧
int16_t winlength = 512;
int16_t step = 256;
int16_t fn = (samples - winlength) / step + 1; //计算帧数fn
float **data_framed[N];
for (uint16_t i = 0; i < N; i++)
{
data_framed[i] = (float **)malloc(sizeof(float *) * fn);
for (uint16_t j = 0; j < fn; j++)
{
*(data_framed[i] + j) = (float *)malloc(sizeof(float) * winlength);
}
}
for (uint16_t i = 0; i < N; i++)
{
enframe(data[i], data_framed[i], samples, winlength, step);
}
for (uint16_t i = 0; i < N; i++)
{
free(data[i]);
}
//加窗
for (uint16_t i = 0; i < N; i++)
{
for (uint16_t j = 0; j < fn; j++)
{
for (uint16_t k = 0; k < winlength; k++)
{
*(*(data_framed[i] + j) + k) = *(*(data_framed[i] + j) + k) * win[k];
}
}
}
// //debug
// for (uint16_t k= 0; k<winlength ; k++)
// {
// printf("%lf\n",*(*data_framed[1]+k));
// }
double E[90][360] ;
float r = 0.04;
//帧数据缓冲区
float *framedata[N];
for (uint16_t i = 0; i < N; i++)
{
framedata[i] = (float *)malloc(sizeof(float) * winlength);
}
//接收数据内存
float *yout = (float *)malloc(winlength * sizeof(float));
//空域扫描
for (int16_t pitch = 60; pitch > 0; pitch--)
{
for (int16_t yaw = 0; yaw < 360; yaw++)
{
//多帧
for (int16_t frame = 0; frame < 1; frame++)
{
//取出一帧数据
for (int16_t i = 0; i < N; i++)
{
for (int16_t k = 0; k < winlength; k++)
{
*(framedata[i] + k) = *(*(data_framed[i] + frame) + k);
}
}
// DEBUG
// float temp[N][winlength];
// for(uint16_t i = 0; i < N; i++)
// {
// for (uint16_t k= 0; k<winlength ; k++)
// {
// temp[i][k] = *(framedata[i]+k);
// }
//
// }
// for (uint16_t k= 0; k<winlength ; k++)
// {
// printf("%lf\n",temp[2][k]);
// }
//
// printf("/////////////frame:%d\n",frame);
// DSA计算
DelaySumURA(framedata[N], yout, fs, N, winlength, r, yaw, pitch);
// for (uint16_t j = 0; j < winlength; j++)
// {
// E[pitch-1][yaw] = E[pitch-1][yaw] + yout[j] * yout[j]/10000;
// }
//DEBUG
if (yaw == 90 && pitch == 60 && frame == 0)
{
for (uint16_t j = 0; j < winlength; j++) {
printf("%f\n", yout[j]);
}
printf("end\n");
}
}
// E[pitch-1][yaw] = E[pitch-1][yaw] / fn;
}
// for (uint16_t i = 0; i < 360; i++)
// {
// printf("%f\n",E[pitch-1][i] );
// }
// printf("///////////////////%d\n",pitch);
}
free(yout);
getchar();
return 0;
}