-
Notifications
You must be signed in to change notification settings - Fork 0
/
icos.c
81 lines (64 loc) · 1.54 KB
/
icos.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
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.141592653589792434
#endif
FILE *ifp; /* Input File Name */
#define COS_LENGTH 13
#define OUTPUT_LENGTH 85
float CosTransform[OUTPUT_LENGTH][COS_LENGTH];
float InputGain;
int MaxSamples;
char **progname;
main(argc, argv)
int argc;
char **argv;
{
int f, j, ByteCount, i, FrameCount;
float Data[COS_LENGTH], ReadIeeeFloatHighLow();
float *Output, max, min, scale, result;
if (argc < 2){
fprintf(stderr, "Syntax: %s input > output\n",
argv[0]);
exit(1);
}
ifp = fopen(argv[1], "r");
if (!ifp){
fprintf(stderr, "Can't open %s for reading input.\n", argv[1]);
exit(1);
}
for (f=0;f<COS_LENGTH;f++){
float gain = 1.0;
if (f != 0)
gain = 2.0;
for (j=0;j<OUTPUT_LENGTH;j++)
CosTransform[j][f] = gain*cos(M_PI*f*j/OUTPUT_LENGTH);
}
ByteCount = Read32BitsHighLow(ifp);
Output = (float *)malloc(ByteCount/4/COS_LENGTH*OUTPUT_LENGTH*
sizeof(*Output));
FrameCount = 0;
while (ByteCount > 0){
for (i=0;i<COS_LENGTH;i++)
Data[i] = ReadIeeeFloatHighLow(ifp);
for (j=0;j<OUTPUT_LENGTH;j++){
result = 0.0;
for (i=0;i<COS_LENGTH;i++)
result += Data[i] * CosTransform[j][i];
Output[FrameCount*OUTPUT_LENGTH+j] = result;
}
ByteCount -= 4 * COS_LENGTH;
FrameCount++;
}
max = min = Output[i];
for (i=0;i<FrameCount*OUTPUT_LENGTH;i++){
if (Output[i] > max)
max = Output[i];
if (Output[i] < min)
min = Output[i];
}
scale = 255/(max-min);
for (i=0;i<FrameCount*OUTPUT_LENGTH;i++){
putchar((int)floor((Output[i]-min)*scale));
}
}