summaryrefslogtreecommitdiff
path: root/tests/test6/test6.c
blob: 2cb70741a913e0a5adb2046efd0562bd5c6af71b (plain)
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
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

//#if 1 //(UGLY_IEEE754_FLOAT32_HACK :-)
/*
static inline float todB_a(const float *x){
	return (float)((*(int *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f;
}
*/
static inline float todB_a(const float *x){
	union {
		//int32_t i;
		int i;
		float f;
	} ix;
	ix.f = *x;
	ix.i = ix.i&0x7fffffff;
	return (float)(ix.i * 7.17711438e-7f -764.6161886f);
}
//#else

static inline float todB_a2(const float *x){
	return (*(x)==0?-400.f:logf(*(x)**(x))*4.34294480f);
}

//#endif
void test_todb_a() {
	float f, dbav[32]={0.f}, dbaf[32]={0.f};
	int i=0;
	for(f=1024000.f;f>1.f;f/=2.f) {
		dbaf[31-i]=f;
		dbav[31-i]=todB_a(&f);
		i++;
	}
	for (i=0;i<32;i++)
		printf("f==%f\tv==%f\n", dbaf[i], dbav[i]);

}

void dump_testfile() {
	int i,n;
	float f[256];
	FILE *fh=fopen("./test.raw", "r");
	if (fh==NULL) return;
	while ( (n=fread(f, sizeof(float), 256, fh)) > 0 ) {
		for(i=0;i<n;i++) {
			printf("%+.3f\t", f[i]);
		}
	}
	fclose(fh);
}

int main() {
	//test_todb_a();
	dump_testfile();

	return 0;
}