You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
9.5KB

  1. #include <stdint.h>
  2. // These audio waveforms have a period of 256 points, plus a 257th
  3. // point that is a duplicate of the first point. This duplicate
  4. // is needed because the waveform generator uses linear interpolation
  5. // between each point and the next point in the waveform.
  6. const int16_t AudioWaveformSine[257] = {
  7. 0, 804, 1608, 2410, 3212, 4011, 4808, 5602, 6393, 7179,
  8. 7962, 8739, 9512, 10278, 11039, 11793, 12539, 13279, 14010, 14732,
  9. 15446, 16151, 16846, 17530, 18204, 18868, 19519, 20159, 20787, 21403,
  10. 22005, 22594, 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790,
  11. 27245, 27683, 28105, 28510, 28898, 29268, 29621, 29956, 30273, 30571,
  12. 30852, 31113, 31356, 31580, 31785, 31971, 32137, 32285, 32412, 32521,
  13. 32609, 32678, 32728, 32757, 32767, 32757, 32728, 32678, 32609, 32521,
  14. 32412, 32285, 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571,
  15. 30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683, 27245, 26790,
  16. 26319, 25832, 25329, 24811, 24279, 23731, 23170, 22594, 22005, 21403,
  17. 20787, 20159, 19519, 18868, 18204, 17530, 16846, 16151, 15446, 14732,
  18. 14010, 13279, 12539, 11793, 11039, 10278, 9512, 8739, 7962, 7179,
  19. 6393, 5602, 4808, 4011, 3212, 2410, 1608, 804, 0, -804,
  20. -1608, -2410, -3212, -4011, -4808, -5602, -6393, -7179, -7962, -8739,
  21. -9512,-10278,-11039,-11793,-12539,-13279,-14010,-14732,-15446,-16151,
  22. -16846,-17530,-18204,-18868,-19519,-20159,-20787,-21403,-22005,-22594,
  23. -23170,-23731,-24279,-24811,-25329,-25832,-26319,-26790,-27245,-27683,
  24. -28105,-28510,-28898,-29268,-29621,-29956,-30273,-30571,-30852,-31113,
  25. -31356,-31580,-31785,-31971,-32137,-32285,-32412,-32521,-32609,-32678,
  26. -32728,-32757,-32767,-32757,-32728,-32678,-32609,-32521,-32412,-32285,
  27. -32137,-31971,-31785,-31580,-31356,-31113,-30852,-30571,-30273,-29956,
  28. -29621,-29268,-28898,-28510,-28105,-27683,-27245,-26790,-26319,-25832,
  29. -25329,-24811,-24279,-23731,-23170,-22594,-22005,-21403,-20787,-20159,
  30. -19519,-18868,-18204,-17530,-16846,-16151,-15446,-14732,-14010,-13279,
  31. -12539,-11793,-11039,-10278, -9512, -8739, -7962, -7179, -6393, -5602,
  32. -4808, -4011, -3212, -2410, -1608, -804, 0
  33. };
  34. #if 0
  35. #! /usr/bin/perl
  36. use Math::Trig ':pi';
  37. $len = 256;
  38. print "const int16_t AudioWaveformSine[257] = {\n";
  39. for ($i=0; $i <= $len; $i++) {
  40. $f = sin($i / $len * 2 * pi);
  41. $d = sprintf "%.0f", $f * 32767.0;
  42. #print $d;
  43. printf "%6d", $d + 0;
  44. print "," if ($i < $len);
  45. print "\n" if ($i % 10) == 9;
  46. }
  47. print "\n" unless ($len % 10) == 9;
  48. print "};\n";
  49. #endif
  50. const int16_t AudioWaveformTriangle[257] = {
  51. 0, 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 4608,
  52. 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728,
  53. 10240, 10752, 11264, 11776, 12288, 12800, 13312, 13824, 14336, 14848,
  54. 15360, 15872, 16384, 16895, 17407, 17919, 18431, 18943, 19455, 19967,
  55. 20479, 20991, 21503, 22015, 22527, 23039, 23551, 24063, 24575, 25087,
  56. 25599, 26111, 26623, 27135, 27647, 28159, 28671, 29183, 29695, 30207,
  57. 30719, 31231, 31743, 32255, 32767, 32255, 31743, 31231, 30719, 30207,
  58. 29695, 29183, 28671, 28159, 27647, 27135, 26623, 26111, 25599, 25087,
  59. 24575, 24063, 23551, 23039, 22527, 22015, 21503, 20991, 20479, 19967,
  60. 19455, 18943, 18431, 17919, 17407, 16895, 16384, 15872, 15360, 14848,
  61. 14336, 13824, 13312, 12800, 12288, 11776, 11264, 10752, 10240, 9728,
  62. 9216, 8704, 8192, 7680, 7168, 6656, 6144, 5632, 5120, 4608,
  63. 4096, 3584, 3072, 2560, 2048, 1536, 1024, 512, 0, -512,
  64. -1024, -1536, -2048, -2560, -3072, -3584, -4096, -4608, -5120, -5632,
  65. -6144, -6656, -7168, -7680, -8192, -8704, -9216, -9728,-10240,-10752,
  66. -11264,-11776,-12288,-12800,-13312,-13824,-14336,-14848,-15360,-15872,
  67. -16384,-16895,-17407,-17919,-18431,-18943,-19455,-19967,-20479,-20991,
  68. -21503,-22015,-22527,-23039,-23551,-24063,-24575,-25087,-25599,-26111,
  69. -26623,-27135,-27647,-28159,-28671,-29183,-29695,-30207,-30719,-31231,
  70. -31743,-32255,-32767,-32255,-31743,-31231,-30719,-30207,-29695,-29183,
  71. -28671,-28159,-27647,-27135,-26623,-26111,-25599,-25087,-24575,-24063,
  72. -23551,-23039,-22527,-22015,-21503,-20991,-20479,-19967,-19455,-18943,
  73. -18431,-17919,-17407,-16895,-16384,-15872,-15360,-14848,-14336,-13824,
  74. -13312,-12800,-12288,-11776,-11264,-10752,-10240, -9728, -9216, -8704,
  75. -8192, -7680, -7168, -6656, -6144, -5632, -5120, -4608, -4096, -3584,
  76. -3072, -2560, -2048, -1536, -1024, -512, 0
  77. };
  78. #if 0
  79. #! /usr/bin/perl
  80. $len = 256;
  81. print "const int16_t AudioWaveformTriangle[257] = {\n";
  82. for ($i=0; $i <= $len; $i++) {
  83. $f = 0;
  84. if ($i < $len / 4) {
  85. $f = $i / ($len / 4);
  86. } elsif ($i < $len * 3 / 4) {
  87. $f = 2 - $i / ($len / 4);
  88. } else {
  89. $f = $i / ($len / 4) - 4;
  90. #print "$i $f\n";
  91. }
  92. $d = sprintf "%.0f", $f * 32767.0;
  93. printf "%6d", $d + 0;
  94. print "," if ($i < $len);
  95. print "\n" if ($i % 10) == 9;
  96. }
  97. print "\n" unless ($len % 10) == 9;
  98. print "};\n";
  99. #endif
  100. const int16_t AudioWaveformSquare[257] = {
  101. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  102. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  103. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  104. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  105. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  106. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  107. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  108. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  109. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  110. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  111. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  112. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,
  113. 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767,-32767,-32767,
  114. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  115. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  116. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  117. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  118. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  119. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  120. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  121. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  122. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  123. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  124. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  125. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  126. -32767,-32767,-32767,-32767,-32767,-32767, 32767
  127. };
  128. #if 0
  129. #! /usr/bin/perl
  130. $len = 256;
  131. print "const int16_t AudioWaveformSquare[257] = {\n";
  132. for ($i=0; $i <= $len; $i++) {
  133. $f = 1.0;
  134. if ($i < $len / 2) {
  135. $f = 1.0;
  136. } elsif ($i < $len) {
  137. $f = -1.0;
  138. }
  139. $d = sprintf "%.0f", $f * 32767.0;
  140. printf "%6d", $d + 0;
  141. print "," if ($i < $len);
  142. print "\n" if ($i % 10) == 9;
  143. }
  144. print "\n" unless ($len % 10) == 9;
  145. print "};\n";
  146. #endif
  147. const int16_t AudioWaveformSawtooth[257] = {
  148. 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304,
  149. 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864,
  150. 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424,
  151. 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984,
  152. 10240, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544,
  153. 12800, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104,
  154. 15360, 15616, 15872, 16128, 16384, 16639, 16895, 17151, 17407, 17663,
  155. 17919, 18175, 18431, 18687, 18943, 19199, 19455, 19711, 19967, 20223,
  156. 20479, 20735, 20991, 21247, 21503, 21759, 22015, 22271, 22527, 22783,
  157. 23039, 23295, 23551, 23807, 24063, 24319, 24575, 24831, 25087, 25343,
  158. 25599, 25855, 26111, 26367, 26623, 26879, 27135, 27391, 27647, 27903,
  159. 28159, 28415, 28671, 28927, 29183, 29439, 29695, 29951, 30207, 30463,
  160. 30719, 30975, 31231, 31487, 31743, 31999, 32255, 32511,-32767,-32511,
  161. -32255,-31999,-31743,-31487,-31231,-30975,-30719,-30463,-30207,-29951,
  162. -29695,-29439,-29183,-28927,-28671,-28415,-28159,-27903,-27647,-27391,
  163. -27135,-26879,-26623,-26367,-26111,-25855,-25599,-25343,-25087,-24831,
  164. -24575,-24319,-24063,-23807,-23551,-23295,-23039,-22783,-22527,-22271,
  165. -22015,-21759,-21503,-21247,-20991,-20735,-20479,-20223,-19967,-19711,
  166. -19455,-19199,-18943,-18687,-18431,-18175,-17919,-17663,-17407,-17151,
  167. -16895,-16639,-16384,-16128,-15872,-15616,-15360,-15104,-14848,-14592,
  168. -14336,-14080,-13824,-13568,-13312,-13056,-12800,-12544,-12288,-12032,
  169. -11776,-11520,-11264,-11008,-10752,-10496,-10240, -9984, -9728, -9472,
  170. -9216, -8960, -8704, -8448, -8192, -7936, -7680, -7424, -7168, -6912,
  171. -6656, -6400, -6144, -5888, -5632, -5376, -5120, -4864, -4608, -4352,
  172. -4096, -3840, -3584, -3328, -3072, -2816, -2560, -2304, -2048, -1792,
  173. -1536, -1280, -1024, -768, -512, -256, 0
  174. };
  175. #if 0
  176. #! /usr/bin/perl
  177. $len = 256;
  178. print "const int16_t AudioWaveformSawtooth[257] = {\n";
  179. for ($i=0; $i <= $len; $i++) {
  180. $f = 0;
  181. if ($i < $len / 2) {
  182. $f = $i / $len * 2;
  183. } else {
  184. $f = -2 + $i / $len * 2;
  185. #print "$i $f\n";
  186. }
  187. $d = sprintf "%.0f", $f * 32767.0;
  188. printf "%6d", $d + 0;
  189. print "," if ($i < $len);
  190. print "\n" if ($i % 10) == 9;
  191. }
  192. print "\n" unless ($len % 10) == 9;
  193. print "};\n";
  194. #endif