gr_fxpt.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_GR_FXPT_H
00023 #define INCLUDED_GR_FXPT_H
00024
00025 #include <gr_types.h>
00026
00038 class gr_fxpt
00039 {
00040 static const int WORDBITS = 32;
00041 static const int NBITS = 10;
00042 static const float s_sine_table[1 << NBITS][2];
00043 static const float PI = 3.14159265358979323846;
00044 static const float TWO_TO_THE_31 = 2147483648.0;
00045 public:
00046
00047 static gr_int32
00048 float_to_fixed (float x)
00049 {
00050 return (gr_int32) ((float) x * TWO_TO_THE_31 / PI);
00051 }
00052
00053 static float
00054 fixed_to_float (gr_int32 x)
00055 {
00056 return x * (PI / TWO_TO_THE_31);
00057 }
00058
00062 static float
00063 sin (gr_int32 x)
00064 {
00065 gr_uint32 ux = x;
00066 int index = ux >> (WORDBITS - NBITS);
00067 return s_sine_table[index][0] * (ux >> 1) + s_sine_table[index][1];
00068 }
00069
00070
00071
00072
00073 static float
00074 cos (gr_int32 x)
00075 {
00076 gr_uint32 ux = x + 0x40000000;
00077 int index = ux >> (WORDBITS - NBITS);
00078 return s_sine_table[index][0] * (ux >> 1) + s_sine_table[index][1];
00079 }
00080
00081 };
00082
00083 #endif