fork download
  1. #include <cmath>
  2. #include <vector>
  3. #include <limits>
  4. #include <cstdint>
  5. #include <fstream>
  6. #include <random>
  7. #include <string>
  8. #include <algorithm>
  9.  
  10. //FMで自分が何をコントロールしているのかさっぱりわからん。。。Orz
  11. //Becarefull wait a play generate file.
  12. //it's easy crash the your ear.
  13.  
  14. static const int Sample_ = 44100;
  15.  
  16. template<class Float>
  17. std::vector<Float> MakeBuffer(std::size_t SampleRate, std::size_t MilliSec) {
  18. std::vector<Float> v(static_cast<std::size_t>( SampleRate*(MilliSec / (static_cast<Float>(1000.0)))));
  19. return v;
  20. }
  21. template<class Float>
  22. bool MakeSinWave(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  23. Float Hz_ = Hz;
  24. Float SampleRate_ = SampleRate;
  25. Float One = SampleRate_ / Hz_;
  26. Float PI = 3.14159265359;//from google.
  27. Float Rad = ((2 * PI) / One);
  28. for (std::size_t i = 0; i < D.size(); i++) {
  29. D[i]=std::sin(Rad*std::fmod(static_cast<Float>(i), One));
  30. }
  31.  
  32. return true;
  33. }
  34. template<class Float>
  35. bool MakeSawWave(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  36. Float Hz_ = Hz;
  37. Float SampleRate_ = SampleRate;
  38. Float One = SampleRate_ / Hz_;
  39. Float Value = 2.0 / One;
  40.  
  41. for (std::size_t i = 0; i < D.size(); i++) {
  42. D[i]=std::fmod(Value*i,2)-1;
  43. }
  44.  
  45. return true;
  46. }
  47. template<class Float>
  48. bool MakeTriangleWave(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  49. Float Hz_ = Hz;
  50. Float SampleRate_ = SampleRate;
  51. Float One = SampleRate_ / Hz_;
  52. Float Value = 1.0 /(One/4);
  53. Float B = -1;
  54. Float Sign = 1;
  55. bool F = false;
  56. for (std::size_t i = 0; i < D.size(); i++) {
  57. if (std::abs(B + (Value*Sign)) > 1) {
  58. B -= (std::fmod(std::abs(B + (Value*Sign)), 1)*Sign);
  59. Sign *= -1;
  60. }
  61. else {
  62. B += Value*Sign;
  63. }
  64. D[i] = B;
  65. }
  66.  
  67. return true;
  68. }
  69. template<class Float>
  70. bool MakeSquareWave(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  71. Float Hz_ = Hz;
  72. Float SampleRate_ = SampleRate;
  73. Float One = SampleRate_ / Hz_;
  74. Float Value = 1;
  75. Float Sign = 1;
  76. Float A = 0;
  77. Float B = 0;
  78. for (std::size_t i = 0; i < D.size(); i++) {
  79. if (static_cast<int>(A) > static_cast<int>(B)) {
  80. B = A;
  81. Sign *= -1;
  82. }
  83. A = i / (One/2);
  84. D[i] = Value*Sign;
  85. }
  86.  
  87. return true;
  88. }
  89. template<class Float>
  90. bool MakeHzNoise(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  91. Float Hz_ = Hz;
  92. Float SampleRate_ = SampleRate;
  93. Float One = SampleRate_ / Hz_;
  94. Float Value = 1;
  95. Float A = 0;
  96. Float B = 0;
  97. std::random_device rd;
  98. std::mt19937 mt(rd());
  99. std::uniform_real_distribution<Float> URD(-1, 1);
  100. for (std::size_t i = 0; i < D.size(); i++) {
  101. if (static_cast<int>(A) > static_cast<int>(B)) {
  102. B = A;
  103. Value = URD(mt);
  104.  
  105. }
  106. A = i / (One/2);
  107. D[i] = Value;
  108. }
  109.  
  110. return true;
  111. }
  112. template<class Float>
  113. bool MakeParfectNoise(std::vector<Float>& D,std::size_t SampleRate, std::size_t Hz ) {
  114. Float Hz_ = Hz;
  115. Float SampleRate_ = SampleRate;
  116. Float One = SampleRate_ / Hz_;
  117. std::random_device rd;
  118. std::mt19937 mt(rd());
  119. std::uniform_real_distribution<Float> URD(-1, 1);
  120. for (std::size_t i = 0; i < D.size(); i++) {
  121. D[i] = URD(mt);
  122. }
  123.  
  124. return true;
  125. }
  126. template<class Float>
  127. Float Sin(const Float& D) {//[0,1]
  128. Float PI = 3.14159265359;//from google.
  129. Float Delta = std::fmod(std::abs(D), 1);
  130.  
  131. return std::sin(2*PI*Delta);
  132. }
  133. template<class Float>
  134. Float Saw(const Float& D) {//[0,1]
  135. Float Delta = std::fmod(std::abs(D)+0.5, 1);
  136.  
  137. return -1 + (Delta * 2);
  138. }
  139. template<class Float>
  140. Float Square(const Float& D) {//[0,1]
  141. Float Delta = std::fmod(std::abs(D), 1);
  142. return Delta > 0.5 ? 1 : -1;
  143. }
  144. template<class Float>
  145. Float Triangle(const Float& D) {//[0,1]
  146. Float Delta = std::fmod(std::abs(D), 1);
  147. std::uint64_t F = static_cast<std::uint64_t>(Delta / 0.25);
  148. Float V = std::fmod(Delta, 0.25)*4;
  149. switch (F)
  150. {
  151. case 0:
  152. return V;
  153. case 1:
  154. return 1 - V;
  155. case 2:
  156. return -V;
  157. case 3:
  158. return -1 + V;
  159. default:
  160. break;
  161. }
  162. return 0;
  163. }
  164. template<class Float>
  165. Float Trapezoid(const Float& D) {//[0,1]
  166. Float Delta = std::fmod(std::abs(D), 1);
  167. std::uint64_t F = static_cast<std::uint64_t>(Delta / (1/8.0));
  168. Float V = std::fmod(Delta, (1/8.0))*8;
  169. switch (F)
  170. {
  171. case 0:
  172. return V;
  173. case 1:
  174. case 2:
  175. return 1;
  176. case 3:
  177. return 1 - V;
  178. case 4:
  179. return - V;
  180. case 5:
  181. case 6:
  182. return -1;
  183. case 7:
  184. return -1 + V;
  185. default:
  186. break;
  187. }
  188. return 0;
  189. }
  190. template<class Float>
  191. Float Noize(const Float& D) {//[0,1]
  192. Float Delta = std::fmod(std::abs(D), 1);
  193. std::mt19937 mt(static_cast<unsigned int>(std::numeric_limits<unsigned int>::max()*Delta));
  194. std::uniform_real_distribution<Float> uid(-1, 1);
  195. return uid(mt);
  196. }
  197. template<class Float>
  198. Float PerfectNoize(const Float& D) {//[0,1]
  199. std::random_device rd;
  200. std::uniform_real_distribution<Float> uid(-1, 1);
  201. return uid(rd);
  202. }
  203. template <class Float , class F>
  204. bool GeneratorTmplate(std::vector<Float>& D, std::size_t SampleRate, std::size_t Hz,F Fun) {
  205. Float Hz_ = Hz;
  206. Float SampleRate_ = SampleRate;
  207. Float One = 1/(SampleRate_ / Hz_);
  208.  
  209. for (std::size_t i = 0; i < D.size(); i++) {
  210. D[i] = Fun(One*i);
  211. }
  212.  
  213. return true;
  214. }
  215.  
  216. //https://e...content-available-to-author-only...a.org/wiki/Frequency_modulation_synthesis#Spectral_analysis
  217. template <class Float>
  218. std::vector<Float> FM_(const std::vector<Float>& D,const std::vector<Float>& M, double FirstTheta, double SecandTheta ){ //, double Time) {
  219. std::vector<Float> R;
  220. double PI = 3.14159265358979323846;
  221. double Rad = 180.0 / PI;
  222.  
  223. for (std::size_t i = 1; i < D.size(); i++) {
  224. //double T = (M[i % M.size()] * std::sin((FirstTheta*Rad) + (SecandTheta*Rad)*i ))*(static_cast<double>(D.size()) / static_cast<double>(i));
  225. double T = (static_cast<double>(D.size()) / static_cast<double>(i));
  226. double Mul = std::sin((FirstTheta*Rad)*T + M[i % M.size()] * std::sin((SecandTheta*Rad))*T);
  227. R.push_back(D[i] *Mul);
  228. }
  229.  
  230. return R;
  231.  
  232. }
  233.  
  234. template<class Float,class F1,class F2>
  235. Float FMOne(const Float& A, const Float& B,const Float& InitA, const Float& InitB, const Float& Time, F1 Fun1, F2 Fun2) {
  236. return A*Fun1(InitA*Time + B*Fun2(InitB*Time));
  237. }
  238. template<class Float,class F1,class F2>
  239. std::vector<Float> FM(const std::vector<Float>& D, const std::vector<Float>& M, const Float& InitA, const Float& InitB, F1 Fun1, F2 Fun2) {
  240. std::vector<Float> R;
  241. for (std::size_t i = 1; i < D.size(); i++) {
  242. Float V = FMOne(D[i], M[i%M.size()], InitA, InitB, i / static_cast<Float>(D.size()), Fun1, Fun2);
  243. R.push_back(V);
  244. }
  245. return R;
  246. }
  247. template<class Float,class F1,class F2,class F3>
  248. Float FMOne2(const Float& A, F3 B,const Float& InitB, F1 Fun1,const Float& Init1, F2 Fun2,const Float& Init2 ,const Float& Time) {
  249. return A*Fun1(Init1*Time + B(Time*InitB)*Fun2(Init2*Time));
  250. }
  251. template<class Float,class F1,class F2,class F3>
  252. std::vector<Float> FM2(const std::vector<Float>& D, F3 B,const Float& InitB, F1 Fun1,const Float& Init1, F2 Fun2,const Float& Init2 ) {
  253. std::vector<Float> R;
  254. for (std::size_t i = 1; i < D.size(); i++) {
  255. Float V = FMOne2(D[i],B,InitB,Fun1,Init1,Fun2,Init2, i / static_cast<Float>(D.size()));
  256. R.push_back(V);
  257. }
  258. return R;
  259. }
  260. template<class Int,class Float>
  261. std::vector<Int> MakeWaveInstance(std::vector<Float>& F,double Volume) {
  262. std::vector<Int> R;
  263. for (auto o : F) {
  264. R.push_back(static_cast<Int>(o*(std::numeric_limits<Int>::max())*Volume));
  265. }
  266. return R;
  267. }
  268. template<class Int>
  269. bool WriteWaveFile(std::vector<Int>& D, std::uint64_t Hz, std::uint16_t Channel, std::string Name = "out.wav") {
  270. std::ofstream ofs(Name, std::ios::binary);
  271. char RIFF[] = "RIFF";
  272. char WAVE[] = "WAVE";
  273. char fmt[] = "fmt ";
  274. char data[] = "data";
  275. std::uint32_t FSize = (44 - 8) + (D.size() * sizeof(std::vector<Int>::value_type));
  276. std::uint32_t ui32 = 0;
  277. std::uint16_t ui16 = 0;
  278. ofs.write(RIFF, 4);
  279. ofs.write(reinterpret_cast<const char*>(&FSize), 4);//fsize-8.
  280. ofs.write(WAVE, 4);
  281. ofs.write(fmt, 4);
  282. ui32 = 16;
  283. ofs.write(reinterpret_cast<const char*>(&ui32), 4);//fmt chunk size
  284. ui16 = 1;
  285. ofs.write(reinterpret_cast<const char*>(&ui16), 2);//sound type. PCM = 1.
  286. ui16 = Channel;
  287. ofs.write(reinterpret_cast<const char*>(&ui16), 2);//Channnel count.
  288. ui32 = static_cast<std::uint32_t>(Hz);
  289. ofs.write(reinterpret_cast<const char*>(&ui32), 4);//Sampling Hz.
  290. ui32 = static_cast<std::uint32_t>(Hz*Channel*(sizeof(std::vector<Int>::value_type)));
  291. ofs.write(reinterpret_cast<const char*>(&ui32), 4);//data speed??
  292. ui16 = Channel*(sizeof(std::vector<Int>::value_type));
  293. ofs.write(reinterpret_cast<const char*>(&ui16), 2);//BlockSize??
  294. ui16 = (sizeof(std::vector<Int>::value_type) * 8);
  295. ofs.write(reinterpret_cast<const char*>(&ui16), 2);//Sampling Bit.
  296. ofs.write(data, 4);
  297. ui32 = static_cast<std::uint32_t>(D.size() * sizeof(std::vector<Int>::value_type));
  298. ofs.write(reinterpret_cast<const char*>(&ui32), 4);//Sample's ALL SIZE.max at 32bit.
  299.  
  300. ofs.write(reinterpret_cast<const char*>(&D[0]), D.size() * sizeof(std::vector<Int>::value_type));//WriteSamples.
  301.  
  302. return true;
  303. }
  304. template<class T>
  305. bool VolumeChenger(std::vector<T>& D ,double Percentage) {///1.0 => 100 Percent;
  306. for (auto o : D) {
  307. o *= Percentage;
  308. }
  309. return true;
  310. }
  311. template<class Float>
  312. bool VolumeNormalize(std::vector<Float>& D ) {
  313. Float Max=0;
  314. Float M = 0;
  315. for (std::size_t i = 0; i < D.size();i++) {
  316. Max = std::max<Float>(Max, std::abs(D[i]));
  317. }
  318. M = 1 / Max;
  319. for (auto o : D) {
  320. o *= M;
  321. }
  322. return true;
  323. }
  324. void Test(std::size_t SampleRate,std::size_t MilliSec,double Volume) {
  325. std::vector<std::int16_t> D;
  326. std::vector<double> B;
  327. std::string Path = "./wav/";
  328.  
  329. B = MakeBuffer<double>(SampleRate, MilliSec);
  330. MakeSinWave(B, Sample_, 220);
  331. //VolumeChenger(B, Volume);
  332. D = MakeWaveInstance<std::int16_t>(B, Volume);
  333. WriteWaveFile(D, Sample_, 1, (Path+"Sin.wav"));
  334.  
  335. B = MakeBuffer<double>(SampleRate, MilliSec);
  336. MakeSawWave(B, Sample_, 220);
  337. //VolumeChenger(B, Volume);
  338. D = MakeWaveInstance<std::int16_t>(B, Volume);
  339. WriteWaveFile(D, Sample_, 1, Path+"Saw.wav");
  340.  
  341. B = MakeBuffer<double>(SampleRate, MilliSec);
  342. MakeTriangleWave(B, Sample_, 220);
  343. //VolumeChenger(B, Volume);
  344. D = MakeWaveInstance<std::int16_t>(B, Volume);
  345. WriteWaveFile(D, Sample_, 1, Path+"Triangle.wav");
  346.  
  347. B = MakeBuffer<double>(SampleRate, MilliSec);
  348. MakeSquareWave(B, Sample_, 220);
  349. ///VolumeChenger(B, Volume);
  350. D = MakeWaveInstance<std::int16_t>(B, Volume);
  351. WriteWaveFile(D, Sample_, 1, Path+"Square.wav");
  352.  
  353. B = MakeBuffer<double>(SampleRate, MilliSec);
  354. MakeHzNoise(B, Sample_, 220);
  355. //VolumeChenger(B, Volume);
  356. D = MakeWaveInstance<std::int16_t>(B, Volume);
  357. WriteWaveFile(D, Sample_, 1, Path+"HzNoize.wav");
  358.  
  359. B = MakeBuffer<double>(SampleRate, MilliSec);
  360. MakeParfectNoise(B, Sample_, 220);
  361. //VolumeChenger(B, Volume);
  362. D = MakeWaveInstance<std::int16_t>(B, Volume);
  363. WriteWaveFile(D, Sample_, 1, Path+"PNoise.wav");
  364.  
  365. }
  366. void GeneratorTest() {
  367. std::vector<std::int16_t> D;
  368. std::vector<double> B1;
  369. std::vector<double> B2;
  370. std::vector<double> R;
  371. std::string Path = "./wav/";
  372.  
  373. std::size_t SampleRate=Sample_;
  374. std::size_t MilliSec = 2000;
  375. double Volume=1.0;
  376.  
  377. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  378. GeneratorTmplate(B1, Sample_, 220, Sin<double>);
  379. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  380. WriteWaveFile(D, Sample_, 1, Path+"SinF.wav");
  381.  
  382. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  383. GeneratorTmplate(B1, Sample_, 220, Saw<double>);
  384. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  385. WriteWaveFile(D, Sample_, 1, Path+"SawF.wav");
  386.  
  387. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  388. GeneratorTmplate(B1, Sample_, 220, Square<double>);
  389. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  390. WriteWaveFile(D, Sample_, 1, Path+"SquareF.wav");
  391.  
  392. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  393. GeneratorTmplate(B1, Sample_, 220, Triangle<double>);
  394. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  395. WriteWaveFile(D, Sample_, 1, Path+"TriangleF.wav");
  396.  
  397. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  398. GeneratorTmplate(B1, Sample_, 220, Trapezoid<double>);
  399. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  400. WriteWaveFile(D, Sample_, 1, Path+"TrapezoidF.wav");
  401.  
  402. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  403. GeneratorTmplate(B1, Sample_, 220, Noize<double>);
  404. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  405. WriteWaveFile(D, Sample_, 1, Path+"NoizeF.wav");
  406.  
  407. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  408. GeneratorTmplate(B1, Sample_, 220, PerfectNoize<double>);
  409. D = MakeWaveInstance<std::int16_t>(B1,Volume);
  410. WriteWaveFile(D, Sample_, 1, Path+"PNoizeF.wav");
  411. }
  412. void FMTest() {
  413. std::vector<std::int16_t> D;
  414. std::vector<double> B1;
  415. std::vector<double> B2;
  416. std::vector<double> R;
  417. std::string Path = "./wav/";
  418.  
  419. std::size_t SampleRate=Sample_;
  420. std::size_t MilliSec = 2000;
  421. double Volume=0.8;
  422.  
  423. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  424. MakeSawWave(B1, Sample_, 220);
  425. VolumeChenger(B1, 0.1);
  426. B2 = MakeBuffer<double>(SampleRate, MilliSec);
  427. MakeSinWave(B2, Sample_, 220);
  428. //MakeHzNoise(B2, Sample_, 220);
  429. //MakeSawWave(B2, Sample_, 220);
  430. VolumeChenger(B2, 0.1);
  431.  
  432. R = FM_(B1, B2, 30, 7);
  433. //R = FM_(R, B1, 30, 120);
  434.  
  435. //VolumeNormalize<double>(R);
  436. //VolumeChenger(B2, 1/3.0);
  437. D = MakeWaveInstance<std::int16_t>(R,Volume);
  438. WriteWaveFile(D, Sample_, 1, Path+"FM.wav");
  439. }
  440. void FMTest2() {
  441. std::vector<std::int16_t> D;
  442. std::vector<double> B1;
  443. std::vector<double> B2;
  444. std::vector<double> R;
  445. std::string Path = "./wav/";
  446.  
  447. std::size_t SampleRate=Sample_;
  448. std::size_t MilliSec = 2000;
  449. double Volume=0.8;
  450.  
  451. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  452. MakeSinWave(B1, Sample_, 220);
  453. VolumeChenger(B1, 0.1);
  454. B2 = MakeBuffer<double>(SampleRate, MilliSec);
  455. MakeTriangleWave(B2, Sample_, 220);
  456. //MakeHzNoise(B2, Sample_, 220);
  457. //MakeSawWave(B2, Sample_, 220);
  458. //VolumeChenger(B2, 0.1);
  459.  
  460. R = FM<double>(B1, B2, 30/360.0,3000,Sin<double>,Sin<double>);
  461. //R = FM(R, B1, 30, 120);
  462.  
  463. //VolumeNormalize<double>(R);
  464. //VolumeChenger(B2, 1/3.0);
  465. D = MakeWaveInstance<std::int16_t>(R,Volume);
  466. WriteWaveFile(D, Sample_, 1, Path+"FMG.wav");
  467. }
  468. void FMTest3() {
  469. std::vector<std::int16_t> D;
  470. std::vector<double> B1;
  471. std::vector<double> R;
  472. std::string Path = "./wav/";
  473.  
  474. std::size_t SampleRate=Sample_;
  475. std::size_t MilliSec = 2000;
  476. double Volume=0.8;
  477. std::uint16_t Channel = 1;
  478.  
  479. B1 = MakeBuffer<double>(SampleRate, MilliSec);
  480. MakeSinWave(B1, Sample_, 220);
  481.  
  482. R = FM2<double>(B1,Sin<double>,1, Sin<double>,30/360, Sin<double>,3000);
  483. D = MakeWaveInstance<std::int16_t>(R,Volume);
  484. WriteWaveFile(D, Sample_, Channel, Path+"FMG2.wav");
  485. }
  486.  
  487. int main() {
  488. //Test(Sample_,2000,0.8);
  489. //FMTest();
  490. //GeneratorTest();
  491. //FMTest2();
  492. //FMTest3();
  493. return true;
  494.  
  495. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘bool WriteWaveFile(std::vector<_RealType>&, uint64_t, uint16_t, std::__cxx11::string) [with Int = short int; uint64_t = long unsigned int; uint16_t = short unsigned int; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
prog.cpp:333:47:   required from here
prog.cpp:275:54: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  std::uint32_t FSize = (44 - 8) + (D.size() * sizeof(std::vector<Int>::value_type));
                                                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:275:54: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
prog.cpp:290:55: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  ui32 = static_cast<std::uint32_t>(Hz*Channel*(sizeof(std::vector<Int>::value_type)));
                                                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:290:55: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
prog.cpp:292:25: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  ui16 = Channel*(sizeof(std::vector<Int>::value_type));
                        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:292:25: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
prog.cpp:294:17: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  ui16 = (sizeof(std::vector<Int>::value_type) * 8);
                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:294:17: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
prog.cpp:297:54: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  ui32 = static_cast<std::uint32_t>(D.size() * sizeof(std::vector<Int>::value_type));
                                                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:297:54: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
prog.cpp:300:68: error: dependent-name ‘std::vector<_RealType>::value_type’ is parsed as a non-type, but instantiation yields a type
  ofs.write(reinterpret_cast<const char*>(&D[0]), D.size() * sizeof(std::vector<Int>::value_type));//WriteSamples.
                                                                   ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:300:68: note: say ‘typename std::vector<_RealType>::value_type’ if a type is meant
stdout
Standard output is empty