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.

89 lines
3.0 KiB

  1. #include <stdio.h>
  2. #include <memory.h>
  3. #define BUF 220 // input buffer size for test main
  4. #define OUT2(o,i,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13) \
  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+8]*t10 + (int)in[i+9]*t11 + \
  11. (int)in[i+8]*t12 + (int)in[i+9]*t13 ) >> 10; \
  12. if (t < -32768) out[o] = -32768; else if (t > 32767) out[o]=32767; else out[o] = t;
  13. //--------------------------------------------------------
  14. void segment11to8(short *in, short *out)
  15. {
  16. int t;
  17. OUT2( 0, 0, 7, -20, 12, 42,-140, 238,
  18. 745, 238,-140, 42, 12, -20, 7, 0);
  19. OUT2( 1, 1, 4, -4, -18, 62, -85, 0,
  20. 654, 510, -99, -27, 49, -26, 3, 1);
  21. OUT2( 2, 2, 0, 6, -26, 38, 0,-126,
  22. 422, 704, 70,-110, 61, -10, -9, 5);
  23. OUT2( 3, 4, 6, -15, 0, 55,-129, 150,
  24. 734, 330,-140, 24, 25, -24, 7, 0);
  25. OUT2( 4, 5, 2, 0, -24, 58, -56, -57,
  26. 589, 589, -57, -56, 58, -24, 0, 2);
  27. OUT2( 5, 7, 7, -24, 25, 24,-140, 330,
  28. 734, 150,-129, 55, 0, -15, 6, 0);
  29. OUT2( 6, 8, 5, -9, -10, 61,-110, 70,
  30. 704, 422,-126, 0, 38, -26, 6, 0);
  31. OUT2( 7, 9, 1, 3, -26, 49, -27, -99,
  32. 510, 654, 0, -85, 62, -18, -4, 4);
  33. }
  34. //--------------------------------------------------------
  35. void convert11to8(short *in, short *out, short *prev, int len)
  36. {
  37. /*
  38. Convert a buffer from 11KHz to 8KHz.
  39. Note: len is number of shorts in input buffer, which MUST
  40. be a multiple of 11 and at least 44.
  41. How the overhang works: The filter kernel for 1 section of
  42. 11 input samples requires KERNEL (=25) samples of the input. So we use 14
  43. samples of overhang from the previous frame, which means the
  44. beginning of this frame looks like:
  45. ppppppppppp ppp01234567 89abcdefghi 19.... 30.... / 41 42 43
  46. X X x x
  47. So we first have to do two special segments (the ones starting
  48. at X) then we do the rest (the x's) in a loop. For the example
  49. length=44 shown above, we'll do up & including 44-25=19, stopping on the
  50. last x shown. Then we save 30-43 in the overhang buffer so that
  51. 30 is the first group done on the next frame.
  52. */
  53. #define OVERHANG2 14
  54. #define KERNEL2 25
  55. int i,k;
  56. short tmp[KERNEL2+11];
  57. // Convert the first two segments, where segment= 11 samples of input
  58. memcpy(tmp,prev,sizeof(short)*OVERHANG2);
  59. memcpy(tmp+OVERHANG2,in,sizeof(short)*(KERNEL2+11-OVERHANG2));
  60. segment11to8(tmp,out);
  61. segment11to8(tmp+11,out+8);
  62. // Loop through the remaining segments
  63. k = 16;
  64. for (i=22-OVERHANG2; i<=len-KERNEL2; i+=11)
  65. {
  66. segment11to8(in+i,out+k);
  67. k += 8;
  68. }
  69. // Save OVERHANG2 samples for next time
  70. memcpy(prev,in+len-OVERHANG2,sizeof(short)*OVERHANG2);
  71. }