[ create a new paste ] login | about

Link: http://codepad.org/jRcGe3Nc    [ raw code | output | fork ]

C++, pasted on Jan 28:
#include "stdio.h"
#include "math.h"
int main(void)
{

  int32_t Np = 4093;
  int32_t amp_int = 8192;
  int32_t TL = 16385;
  int32_t last_idx=0;
  int32_t double_sample_value;
  int32_t lsb_sample_value;
  int32_t msb_sample_value;
  int32_t i;
  int32_t coeffs[16384];
  
  double Ts = (double) Np / TL;

  for(i=TL-1;i>=0;i--){
    double tm = fmod(2*M_PI*Ts*i, 2*M_PI);
    double tm_1 = fmod(2*M_PI*Ts*(i-1), 2*M_PI);

   double delta = tm - tm_1;
    if(abs(delta)>M_PI){
      last_idx = i-1;
      break;
    }
  }

  double c_ph = 2*M_PI - fmod(2*M_PI*Ts*last_idx, 2*M_PI) - 2*M_PI*Ts/2;

  double amp = 1.0;
  for(int i=1;i<TL;i++) { //1
    double c = cos(fmod(2*M_PI*Ts*(last_idx+i+1), 2*M_PI) + c_ph);
    
    int16_t c_fx = (int16_t)floor(amp_int*c)+8192;
    coeffs[i-1] = c_fx;
  }
 
  // Loading waveform
  for (i=0; i<8192; i++){//8192
    lsb_sample_value = (coeffs[i*2] & 0xffff);   //0xe000 ^
    msb_sample_value = (coeffs[i*2+1] & 0xffff); //0xe000 ^
    double_sample_value = (msb_sample_value << 16 ) | lsb_sample_value;
    coeffs[i] =double_sample_value;
    if(i<128){
    std::cout << std::hex << lsb_sample_value << std::endl;
    std::cout << std::hex << msb_sample_value << std::endl;
}    
  }
    
  // -----------------------------------------------------------------
  // Done with the load. Release the force
  return 0;

}


Output:
96a
94d
3687
36c1
987
930
366a
36dd
9a4
914
364d
36fa
9c1
8f7
362f
3716
9df
8db
3612
3732
9fc
8bf
35f4
374e
a1a
8a3
35d6
376a
a38
887
35b8
3786
a56
86b
359a
37a2
a74
850
357c
37bd
a92
834
355e
37d8
ab0
819
353f
37f3
acf
7fe
3521
380e
aee
7e3
3502
3829
b0c
7c8
34e3
3844
b2b
7ae
34c4
385f
b4b
793
34a5
3879
b6a
779
3486
3893
b89
75f
3466
38ad
ba9
745
3447
38c7
bc8
72b
3427
38e1
be8
711
3407
38fb
c08
6f8
33e7
3914
c28
6de
33c7
392d
c48
6c5
33a7
3946
c68
6ac
3387
395f
c88
693
3366
3978
ca9
67b
3346
3991
cc9
662
3325
39a9
cea
64a
3304
39c2
d0b
631
32e4
39da
d2c
619
32c3
39f2
d4d
601
32a1
3a0a
d6e
5ea
3280
3a21
d90
5d2
325f
3a39
db1
5bb
323d
3a50
dd3
5a3
321c
3a67
df4
58c
31fa
3a7e
e16
575
31d8
3a95
e38
55f
31b6
3aac
e5a
548
3194
3ac2
e7c
532
3172
3ad8
e9e
51c
3150
3aef
ec1
505
312d
3b04
ee3
4f0
310b
3b1a
f06
4da
30e8
3b30
f28
4c4
30c5
3b45
f4b
4af
30a3
3b5b
f6e
49a
3080
3b70
f91
485
305d
3b85
fb4
470
3039
3b99
fd7
45b
3016
3bae
ffb
447
2ff3
3bc2
101e
432
2fcf
3bd7
1041
41e
2fac
3beb
1065
40a
2f88
3bff
1089
3f7
2f64
3c12
10ad
3e3
2f41
3c26
10d0
3d0
2f1d
3c39
10f4
3bc
2ef9
3c4c
1119
3a9
2ed4
3c5f
113d
396
2eb0
3c72
1161
384
2e8c
3c85
1185
371
2e67
3c97


Create a new paste based on this one


Comments: