summaryrefslogtreecommitdiffstats
path: root/mufhd0/fixsin.cpp
blob: 4ac7955f0a705f47c36844d30811d32a79136fe1 (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
#ifndef FIXSIN
#define FIXSIN

/*
  16.16 fixed-point sine lookup tables...
  originally written by Scott Scriven
*/



#define FSINMAX 2047
#define SINFIX 16
#define FSINBITS 16


#include <math.h>

#ifndef PI
#define PI 3.14159265358979323846
#endif

int FSinTab[2048];
int FCosTab[2048];

int FSin(int angle);
int FCos(int angle);

void FCreateSines();




int FSin(int angle)
{
  return FSinTab[angle&FSINMAX];
}

int FCos(int angle)
{
  return FCosTab[angle&FSINMAX];
}

void FCreateSines()
{
  int i;
  double angle;


  for(i=0; i<2048; i++)
  {
    angle = (float)i * (PI/1024.0);

    FSinTab[i] = (int)(sin(angle) * (float)0x10000);
    FCosTab[i] = (int)(cos(angle) * (float)0x10000);
  }
}


#endif