Leaked source code of windows server 2003
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.

112 lines
4.8 KiB

  1. #include <stdio.h>
  2. #include <memory.h>
  3. #define BUF 240 // input buffer size for test main
  4. #define OUTPUT(o,i,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16) \
  5. t = ( (int)in[i]*t0 + (int)in[i+1]*t1 + \
  6. (int)in[i+2]*t2 + (int)in[i+3]*t3 + \
  7. (int)in[i+4]*t4 + (int)in[i+5]*t5 + \
  8. (int)in[i+6]*t6 + (int)in[i+7]*t7 + \
  9. (int)in[i+8]*t8 + (int)in[i+9]*t9 + \
  10. (int)in[i+10]*t10 + (int)in[i+11]*t11 + \
  11. (int)in[i+12]*t12 + (int)in[i+13]*t13 + \
  12. (int)in[i+14]*t14 + (int)in[i+15]*t15 + \
  13. (int)in[i+16]*t16 ) >> 10; \
  14. if (t < -32768) out[o] = -32768; else if (t > 32767) out[o]=32767; else out[o] = t;
  15. //--------------------------------------------------------
  16. void segment8to11(short *in, short *out)
  17. {
  18. int t;
  19. OUTPUT( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1024, 0, 0, 0, 0, 0, 0, 0, 0);
  20. OUTPUT( 1, 1, -5, 11, -20, 32, -49, 77,-134, 335, 903,-187, 97, -60, 39, -24, 15, -8, 3);
  21. OUTPUT( 2, 1, 2, -9, 17, -29, 47, -73, 116,-213, 708, 589,-199, 111, -70, 45, -28, 16, -8);
  22. OUTPUT( 3, 2, 2, -6, 11, -18, 29, -45, 73,-145, 969, 213, -91, 53, -34, 22, -13, 7, -3);
  23. OUTPUT( 4, 3, -2, 4, -7, 11, -17, 26, -45, 99,1010, -82, 40, -24, 16, -10, 6, -3, 1);
  24. OUTPUT( 5, 4, -7, 14, -25, 40, -61, 97,-172, 463, 814,-210, 112, -69, 45, -28, 17, -8, 3);
  25. OUTPUT( 6, 4, 3, -8, 17, -28, 45, -69, 112,-210, 814, 463,-172, 97, -61, 40, -25, 14, -7);
  26. OUTPUT( 7, 5, 1, -3, 6, -10, 16, -24, 40, -82,1010, 99, -45, 26, -17, 11, -7, 4, -2);
  27. OUTPUT( 8, 6, -3, 7, -13, 22, -34, 53, -91, 213, 969,-145, 73, -45, 29, -18, 11, -6, 2);
  28. OUTPUT( 9, 7, -8, 16, -28, 45, -70, 111,-199, 589, 708,-213, 116, -73, 47, -29, 17, -9, 2);
  29. OUTPUT( 10, 7, 3, -8, 15, -24, 39, -60, 97,-187, 903, 335,-134, 77, -49, 32, -20, 11, -5);
  30. /* original
  31. out[0] = in[4];
  32. OUTPUT(1, 0, 3, -20, 52,-116, 327, 899,-174, 75, -32, 9);
  33. OUTPUT(2, 1, 9, -36, 85,-192, 701, 581,-178, 79, -32, 7);
  34. OUTPUT(3, 2, 8, -25, 58,-136, 968, 206, -77, 35, -13, 1);
  35. OUTPUT(4, 2, 0, -6, 17, -37, 96,1010, -78, 32, -14, 5);
  36. OUTPUT(5, 3, 5, -27, 68,-151, 454, 809,-192, 84, -36, 10);
  37. OUTPUT(6, 4, 10, -36, 84,-192, 809, 454,-151, 68, -27, 5);
  38. OUTPUT(7, 5, 5, -14, 32, -78,1010, 96, -37, 17, -6, 0);
  39. OUTPUT(8, 5, 1, -13, 35, -77, 206, 968,-136, 58, -25, 8);
  40. OUTPUT(9, 6, 7, -32, 79,-178, 581, 701,-192, 85, -36, 9);
  41. OUTPUT(10, 7, 9, -32, 75,-174, 899, 327,-116, 52, -20, 3);
  42. */
  43. /* From MD
  44. OUTPUT( 1, 0, 10, -16, 26, -44, 98,1000, -81, 39, -24, 15,);
  45. OUTPUT( 2, 0, 21, -32, 51, -88, 208, 951,-142, 71, -43, 28,);
  46. OUTPUT( 3, 0, 30, -47, 74,-130, 326, 879,-182, 94, -57, 37,);
  47. OUTPUT( 4, 0, 37, -58, 93,-165, 448, 788,-202, 107, -66, 42,);
  48. OUTPUT( 5, 0, 42, -66, 106,-191, 568, 683,-205, 111, -69, 44,);
  49. OUTPUT( 6, 0, 44, -69, 111,-205, 683, 568,-191, 106, -66, 42,);
  50. OUTPUT( 7, 0, 42, -66, 107,-202, 788, 448,-165, 93, -58, 37,);
  51. OUTPUT( 8, 0, 37, -57, 94,-182, 879, 326,-130, 74, -47, 30,);
  52. OUTPUT( 9, 0, 28, -43, 71,-142, 951, 208, -88, 51, -32, 21,);
  53. OUTPUT(10, 0, 15, -24, 39, -81,1000, 98, -44, 26, -16, 10,);
  54. */
  55. }
  56. //--------------------------------------------------------
  57. void convert8to11(short *in, short *out, short *prev, int len)
  58. {
  59. /*
  60. Convert a buffer from 8KHz to 11KHz.
  61. Note: len is number of shorts in input buffer, which MUST
  62. be a multiple of 8 and at least 32.
  63. How the overhang works: The filter kernel for 1 section of
  64. 8 samples requires KERNEL (=17) samples of the input. So we use 16
  65. samples of overhang from the previous frame, which means the
  66. beginning of this frame looks like:
  67. pppppppp pppppppp 01234567 89abcdef 16...... 24......
  68. X X x x
  69. So we first have to do two special segments (the ones starting
  70. at X) then we do the rest (the x's) in a loop. For the example
  71. length=32 shown above, we'll do up to 32-24=8, stopping on the
  72. last x shown. Then we save 16-31 in the overhang buffer so that
  73. 16 is the first group done on the next frame.
  74. */
  75. #define OVERHANG 16
  76. #define KERNEL 24
  77. int i,k;
  78. short tmp[KERNEL+8];
  79. // Convert the first two segments, where segment= 8 samples of input
  80. memcpy(tmp,prev,sizeof(short)*OVERHANG);
  81. memcpy(tmp+OVERHANG,in,sizeof(short)*(KERNEL+8-OVERHANG));
  82. segment8to11(tmp,out);
  83. segment8to11(tmp+8,out+11);
  84. // Loop through the remaining segments
  85. k = 22;
  86. for (i=16-OVERHANG; i<=len-KERNEL; i+=8)
  87. {
  88. segment8to11(in+i,out+k);
  89. k += 11;
  90. }
  91. // Save overhang samples for next time
  92. memcpy(prev,in+len-OVERHANG,sizeof(short)*OVERHANG);
  93. }