PageRenderTime 91ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/AVS_Transcoder_SDK/kernel/audio/AudioTransCoder_Lame/av3enc/src/sam_cbc_huffman.cpp

https://gitlab.com/jchwei/avs-transcoder
C++ | 928 lines | 682 code | 112 blank | 134 comment | 118 complexity | cbbf6486e62cb23b4b329ae017973051 MD5 | raw file
  1. /*
  2. ***********************************************************************
  3. * COPYRIGHT AND WARRANTY INFORMATION
  4. *
  5. * Copyright 2004, Audio Video Coding Standard, Part III
  6. *
  7. * This software module was originally developed by
  8. *
  9. * JungHoe Kim (kjh94@samsung.com), Samsung AIT
  10. *
  11. * edited by
  12. *
  13. * Lei Miao (win.miaolei@samsung.com), Samsung AIT
  14. * Lei Miao, CBC Multi-channel extension, 2005-09-19
  15. * Lei Miao, CBC codebook reduction, 2005-12-22
  16. *
  17. * DISCLAIMER OF WARRANTY
  18. *
  19. * These software programs are available to the users without any
  20. * license fee or royalty on an "as is" basis. The AVS disclaims
  21. * any and all warranties, whether express, implied, or statutory,
  22. * including any implied warranties of merchantability or of fitness
  23. * for a particular purpose. In no event shall the contributors or
  24. * the AVS be liable for any incidental, punitive, or consequential
  25. * damages of any kind whatsoever arising from the use of this program.
  26. *
  27. * This disclaimer of warranty extends to the user of this program
  28. * and user's customers, employees, agents, transferees, successors,
  29. * and assigns.
  30. *
  31. * The AVS does not represent or warrant that the program furnished
  32. * hereunder are free of infringement of any third-party patents.
  33. * Commercial implementations of AVS, including shareware, may be
  34. * subject to royalty fees to patent holders. Information regarding
  35. * the AVS patent policy is available from the AVS Web site at
  36. * http://www.avs.org.cn
  37. *
  38. * THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
  39. ************************************************************************
  40. */
  41. #include "stdlib.h"
  42. #include "stdio.h"
  43. #include <memory.h>
  44. #include <math.h>
  45. /* codebook reduction */
  46. unsigned int codeBook[36][7][16] = {
  47. {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  48. {{1, 0, 6, 22, 7, 20, 21, 36, 1, 47, 19, 187, 8, 92, 37, 186}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  49. {{5, 15, 9, 8, 13, 3, 7, 29, 0, 5, 4, 28, 6, 25, 2, 24}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  50. {{1, 2, 6, 5, 7, 28, 15, 19, 0, 16, 29, 75, 6, 36, 17, 74}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  51. {{1, 6, 2, 9, 3, 23, 31, 17, 0, 29, 28, 16, 10, 61, 22, 60}, {1, 24, 0, 28, 13, 59, 15, 19, 8, 116, 11, 36, 25, 117, 10, 37}, {4, 3, 59, 6, 2, 6, 4, 28, 11, 10, 14, 58, 15, 0, 15, 5}, {6, 14, 1, 10, 0, 8, 4, 19, 15, 7, 5, 22, 6, 47, 18, 46}, {4, 11, 2, 14, 61, 14, 4, 60, 3, 10, 6, 0, 6, 15, 31, 5}, {1, 4, 15, 26, 14, 27, 10, 22, 1, 24, 1, 1, 25, 47, 0, 46}, {1, 8, 13, 25, 0, 10, 15, 11, 24, 117, 59, 116, 28, 36, 19, 37}},
  52. {{1, 7, 5, 5, 6, 17, 4, 39, 0, 16, 18, 31, 6, 38, 14, 30}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  53. {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {12, 36, 15, 17, 14, 16, 5, 23, 13, 37, 4, 22, 3, 19, 0, 10}, {10, 0, 244, 121, 14, 6, 120, 125, 11, 1, 245, 123, 4, 1, 124, 63}, {2, 1, 0, 12, 14, 8, 6, 55, 15, 11, 9, 15, 10, 26, 14, 54}, {10, 11, 14, 4, 244, 245, 121, 123, 2, 3, 6, 0, 120, 126, 127, 62}, {6, 5, 1, 29, 2, 31, 30, 18, 3, 0, 8, 39, 28, 2, 3, 38}, {12, 13, 14, 3, 15, 4, 5, 0, 36, 37, 16, 19, 17, 22, 23, 10}},
  54. {{1, 0, 7, 26, 1, 110, 24, 222, 2, 446, 108, 894, 25, 1790, 109, 1791}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  55. {{1, 0, 5, 14, 6, 61, 31, 39, 1, 36, 60, 76, 8, 154, 37, 155}, {0, 14, 2, 12, 27, 124, 30, 52, 126, 854, 127, 426, 107, 855, 125, 212}, {2, 7, 1, 26, 3, 2, 7, 24, 0, 55, 12, 109, 2, 25, 13, 108}, {2, 14, 3, 30, 0, 26, 4, 62, 1, 63, 27, 103, 5, 50, 24, 102}, {1, 0, 5, 9, 1, 110, 25, 111, 7, 16, 1, 17, 26, 109, 24, 108}, {1, 15, 4, 25, 1, 0, 10, 47, 14, 2, 24, 6, 13, 46, 22, 7}, {0, 47, 9, 35, 7, 46, 10, 45, 13, 138, 44, 136, 12, 139, 16, 137}},
  56. {{0, 12, 9, 26, 10, 16, 22, 61, 14, 63, 17, 60, 27, 47, 62, 46}, {5, 4, 6, 3, 14, 30, 0, 2, 7, 62, 8, 63, 5, 13, 9, 12}, {0, 2, 17, 16, 1, 3, 20, 24, 13, 11, 18, 19, 14, 15, 25, 21}, {2, 13, 14, 7, 12, 9, 3, 23, 15, 8, 6, 1, 10, 2, 0, 22}, {1, 12, 2, 14, 17, 18, 16, 21, 3, 13, 0, 15, 20, 23, 22, 19}, {5, 15, 13, 7, 14, 4, 8, 2, 0, 3, 6, 19, 5, 25, 24, 18}, {6, 7, 14, 4, 5, 8, 15, 9, 1, 1, 2, 13, 5, 0, 3, 12}},
  57. {{1, 7, 5, 2, 6, 17, 1, 37, 1, 16, 19, 3, 3, 36, 0, 2}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  58. {{2, 14, 5, 3, 6, 27, 2, 24, 0, 31, 30, 14, 4, 15, 26, 25}, {6, 44, 4, 45, 0, 42, 2, 46, 14, 40, 1, 43, 15, 41, 3, 47}, {2, 3, 78, 35, 0, 5, 34, 38, 14, 15, 79, 36, 1, 6, 37, 16}, {3, 14, 0, 11, 15, 5, 4, 18, 1, 12, 8, 19, 10, 26, 55, 54}, {2, 14, 0, 1, 79, 78, 34, 37, 3, 15, 5, 6, 35, 36, 38, 16}, {6, 4, 15, 28, 1, 29, 1, 21, 3, 5, 4, 47, 0, 20, 22, 46}, {6, 11, 0, 14, 4, 1, 2, 3, 60, 40, 42, 41, 61, 43, 63, 62}},
  59. {{22, 1, 0, 6, 23, 5, 4, 15, 2, 7, 3, 13, 10, 12, 14, 4}, {31, 0, 11, 3, 8, 1, 3, 29, 9, 2, 2, 28, 1, 30, 6, 10}, {27, 10, 0, 3, 11, 3, 2, 26, 9, 1, 1, 24, 2, 7, 25, 8}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {27, 8, 10, 2, 0, 2, 1, 26, 11, 1, 3, 7, 3, 25, 24, 9}, {2, 15, 13, 6, 12, 9, 7, 1, 14, 10, 8, 23, 3, 0, 2, 22}, {31, 10, 8, 0, 11, 2, 3, 6, 4, 5, 6, 30, 7, 28, 29, 9}},
  60. {{1, 2, 7, 25, 0, 97, 26, 193, 1, 385, 99, 1537, 27, 1536, 98, 769}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  61. {{1, 3, 2, 7, 1, 15, 0, 6, 2, 28, 5, 58, 6, 118, 4, 119}, {1, 2, 0, 6, 29, 112, 15, 115, 226, 1817, 228, 909, 459, 1816, 458, 455}, {3, 0, 11, 5, 4, 6, 4, 40, 14, 122, 31, 246, 21, 60, 41, 247}, {2, 15, 2, 0, 3, 3, 12, 5, 1, 19, 27, 17, 14, 16, 26, 18}, {2, 12, 6, 13, 2, 123, 15, 60, 0, 491, 14, 244, 31, 980, 14, 981}, {0, 17, 5, 16, 7, 14, 6, 15, 9, 37, 8, 36, 5, 39, 6, 38}, {1, 251, 30, 249, 0, 500, 14, 248, 2, 2005, 127, 2007, 6, 2004, 126, 2006}},
  62. {{1, 0, 4, 11, 6, 62, 29, 57, 1, 123, 63, 122, 10, 113, 60, 112}, {1, 5, 7, 0, 13, 2, 9, 3, 17, 33, 51, 49, 32, 97, 50, 96}, {7, 4, 0, 7, 1, 11, 4, 24, 10, 11, 27, 52, 6, 53, 25, 10}, {6, 14, 1, 5, 0, 8, 10, 22, 15, 23, 7, 9, 6, 18, 19, 8}, {7, 10, 13, 3, 12, 23, 4, 14, 4, 2, 0, 22, 6, 11, 15, 10}, {2, 3, 15, 21, 14, 2, 11, 24, 0, 8, 3, 25, 9, 26, 27, 20}, {1, 17, 9, 6, 7, 52, 12, 7, 5, 33, 2, 106, 0, 107, 27, 32}},
  63. {{1, 5, 2, 8, 3, 1, 3, 26, 7, 27, 0, 5, 12, 18, 19, 4}, {0, 11, 4, 5, 12, 4, 14, 7, 27, 52, 30, 53, 31, 21, 6, 20}, {1, 3, 16, 20, 2, 14, 30, 21, 12, 9, 17, 26, 0, 11, 31, 27}, {3, 13, 12, 10, 11, 8, 3, 0, 15, 5, 4, 2, 9, 29, 1, 28}, {2, 10, 1, 0, 17, 16, 28, 24, 3, 11, 13, 15, 19, 18, 25, 29}, {4, 12, 13, 6, 15, 11, 4, 3, 14, 2, 5, 21, 7, 0, 1, 20}, {0, 30, 9, 6, 5, 8, 13, 4, 12, 56, 31, 10, 7, 57, 29, 11}},
  64. {{1, 0, 6, 22, 7, 18, 21, 95, 1, 46, 19, 83, 8, 94, 40, 82}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  65. {{0, 13, 9, 24, 10, 63, 22, 61, 14, 17, 16, 47, 25, 60, 62, 46}, {1, 2, 6, 28, 15, 58, 0, 59, 11, 13, 9, 15, 8, 12, 10, 14}, {7, 4, 6, 5, 3, 2, 4, 7, 12, 11, 40, 41, 13, 0, 42, 43}, {6, 15, 0, 9, 1, 4, 5, 47, 14, 6, 7, 22, 8, 21, 20, 46}, {7, 12, 2, 13, 5, 40, 4, 41, 4, 11, 3, 0, 6, 42, 7, 43}, {6, 3, 2, 29, 15, 8, 0, 22, 1, 28, 1, 21, 9, 20, 47, 46}, {1, 11, 15, 3, 6, 10, 0, 9, 2, 33, 58, 32, 28, 34, 59, 35}},
  66. {{1, 11, 10, 3, 9, 28, 0, 30, 12, 1, 29, 26, 8, 27, 31, 2}, {14, 17, 1, 23, 10, 18, 2, 0, 12, 16, 15, 19, 13, 22, 3, 1}, {10, 14, 12, 14, 13, 2, 15, 30, 12, 0, 13, 23, 1, 4, 22, 31}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {10, 11, 13, 0, 12, 13, 14, 24, 14, 1, 2, 4, 15, 25, 30, 31}, {2, 0, 12, 8, 15, 7, 9, 29, 13, 3, 10, 23, 6, 28, 2, 22}, {2, 9, 12, 13, 1, 14, 0, 3, 20, 16, 17, 21, 23, 22, 30, 31}},
  67. {{28, 4, 29, 10, 0, 6, 7, 13, 1, 9, 5, 11, 8, 12, 15, 1}, {2, 22, 10, 23, 8, 26, 0, 3, 9, 27, 15, 4, 14, 5, 3, 12}, {2, 10, 24, 27, 8, 0, 26, 4, 9, 15, 25, 3, 14, 3, 5, 11}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {2, 8, 9, 14, 24, 27, 25, 4, 10, 15, 0, 3, 26, 5, 3, 11}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {2, 9, 8, 14, 10, 13, 0, 3, 24, 30, 31, 4, 25, 3, 5, 11}},
  68. {{6, 11, 6, 5, 9, 30, 0, 7, 14, 31, 1, 3, 2, 4, 8, 10}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  69. {{2, 7, 5, 3, 6, 26, 1, 31, 12, 30, 28, 29, 4, 27, 0, 2}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  70. {{0, 11, 31, 27, 8, 19, 26, 61, 12, 20, 21, 60, 28, 59, 18, 58}, {3, 5, 1, 4, 13, 0, 14, 1, 9, 24, 10, 30, 8, 25, 11, 31}, {3, 2, 0, 1, 15, 13, 29, 2, 8, 9, 22, 23, 10, 12, 28, 3}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {3, 8, 13, 10, 31, 22, 1, 30, 2, 9, 14, 12, 0, 23, 3, 2}, {0, 11, 13, 7, 12, 9, 10, 4, 14, 5, 6, 2, 8, 31, 3, 30}, {3, 10, 13, 8, 1, 9, 14, 11, 5, 24, 0, 25, 4, 30, 1, 31}},
  71. {{1, 6, 3, 9, 2, 23, 3, 17, 7, 0, 1, 16, 10, 5, 22, 4}, {0, 9, 5, 6, 14, 25, 13, 24, 8, 11, 7, 61, 31, 60, 4, 10}, {6, 2, 1, 0, 1, 15, 29, 28, 11, 9, 15, 13, 10, 8, 14, 12}, {4, 13, 14, 5, 15, 4, 10, 1, 12, 3, 7, 0, 6, 23, 2, 22}, {6, 11, 1, 10, 31, 11, 28, 9, 3, 8, 0, 9, 30, 8, 29, 10}, {2, 11, 13, 6, 15, 7, 10, 2, 12, 3, 8, 29, 9, 1, 0, 28}, {1, 10, 14, 30, 4, 3, 13, 0, 11, 2, 24, 63, 2, 3, 25, 62}},
  72. {{1, 7, 5, 6, 6, 17, 4, 39, 0, 16, 18, 38, 7, 23, 10, 22}, {2, 0, 6, 3, 7, 13, 5, 12, 4, 63, 2, 62, 30, 58, 28, 59}, {0, 4, 6, 28, 2, 13, 23, 22, 12, 7, 63, 61, 10, 29, 62, 60}, {5, 12, 14, 6, 15, 4, 8, 2, 0, 3, 5, 19, 7, 26, 27, 18}, {0, 9, 2, 8, 7, 13, 25, 12, 5, 31, 13, 30, 29, 57, 24, 56}, {4, 12, 14, 4, 15, 5, 10, 1, 11, 3, 7, 27, 6, 0, 2, 26}, {2, 3, 7, 0, 6, 2, 5, 29, 15, 3, 13, 57, 4, 2, 12, 56}},
  73. {{1, 0, 5, 30, 6, 18, 29, 39, 1, 62, 63, 38, 8, 115, 56, 114}, {3, 0, 4, 3, 10, 14, 6, 8, 5, 47, 2, 46, 22, 31, 9, 30}, {1, 5, 8, 30, 1, 14, 25, 24, 9, 31, 3, 55, 0, 26, 2, 54}, {6, 11, 1, 7, 0, 4, 6, 20, 14, 31, 5, 21, 8, 19, 30, 18}, {1, 9, 1, 1, 8, 63, 25, 62, 5, 0, 14, 26, 30, 55, 24, 54}, {4, 12, 14, 5, 15, 10, 7, 0, 13, 3, 6, 1, 4, 23, 2, 22}, {3, 4, 8, 18, 5, 2, 3, 11, 0, 39, 14, 30, 6, 31, 10, 38}},
  74. {{1, 0, 6, 23, 7, 45, 21, 40, 1, 44, 17, 67, 9, 32, 41, 66}, {3, 1, 5, 6, 9, 11, 8, 8, 1, 1, 15, 0, 14, 19, 10, 18}, {2, 3, 12, 26, 2, 15, 29, 5, 3, 28, 3, 55, 0, 4, 2, 54}, {6, 0, 15, 8, 1, 7, 4, 21, 11, 29, 5, 19, 6, 20, 28, 18}, {1, 12, 1, 1, 8, 1, 18, 53, 5, 29, 15, 27, 28, 52, 19, 0}, {5, 12, 1, 5, 0, 7, 6, 30, 13, 31, 4, 28, 8, 19, 29, 18}, {3, 1, 9, 15, 5, 0, 8, 5, 2, 27, 14, 8, 3, 9, 12, 26}},
  75. {{1, 0, 6, 15, 7, 27, 14, 17, 2, 25, 9, 49, 5, 16, 26, 48}, {0, 4, 5, 27, 31, 24, 26, 50, 28, 122, 59, 123, 60, 102, 58, 103}, {2, 3, 3, 31, 2, 14, 24, 61, 13, 1, 60, 11, 0, 25, 4, 10}, {7, 13, 11, 7, 0, 6, 8, 19, 2, 2, 3, 18, 10, 51, 24, 50}, {2, 7, 1, 1, 4, 59, 12, 22, 6, 0, 15, 10, 28, 23, 13, 58}, {5, 12, 4, 1, 1, 7, 13, 12, 15, 5, 1, 13, 4, 28, 29, 0}, {0, 21, 30, 47, 6, 59, 28, 46, 4, 41, 58, 88, 31, 40, 45, 89}},
  76. {{1, 2, 6, 6, 7, 11, 7, 9, 1, 10, 0, 17, 1, 2, 3, 16}, {0, 2, 15, 24, 26, 109, 58, 119, 28, 205, 118, 204, 55, 108, 50, 103}, {3, 3, 2, 36, 2, 5, 3, 0, 8, 19, 297, 296, 3, 2, 149, 75}, {1, 8, 15, 26, 5, 29, 12, 28, 1, 55, 0, 54, 9, 2, 7, 6}, {2, 27, 1, 13, 0, 16, 12, 35, 7, 53, 12, 9, 7, 34, 5, 52}, {2, 0, 15, 3, 6, 14, 1, 2, 1, 29, 28, 31, 2, 13, 12, 30}, {0, 58, 28, 236, 6, 22, 10, 119, 4, 377, 95, 376, 15, 237, 46, 189}},
  77. {{1, 0, 6, 60, 1, 123, 29, 245, 2, 114, 115, 977, 31, 489, 56, 976}, {1, 10, 1, 23, 6, 22, 1, 0, 3, 2, 29, 28, 31, 30, 9, 8}, {0, 4, 58, 119, 6, 15, 118, 45, 44, 47, 46, 41, 28, 40, 43, 42}, {2, 29, 1, 28, 31, 30, 25, 24, 27, 26, 5, 4, 7, 6, 1, 0}, {0, 48, 15, 51, 28, 99, 98, 105, 2, 104, 27, 107, 29, 106, 101, 100}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {1, 9, 3, 8, 3, 11, 1, 10, 0, 21, 20, 23, 9, 22, 17, 16}},
  78. {{1, 0, 3, 20, 3, 17, 16, 42, 2, 87, 86, 37, 11, 36, 39, 38}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {2, 12, 27, 26, 5, 4, 7, 6, 1, 0, 3, 2, 29, 28, 31, 30}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {6, 14, 31, 30, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {6, 14, 31, 30, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2}},
  79. {{1, 1, 3, 0, 2, 3, 2, 21, 3, 20, 23, 22, 17, 16, 19, 18}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  80. {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  81. {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
  82. {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}},
  120. {{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}}
  121. };
  122. #define SI_NUM (30+1)
  123. unsigned int codeBookSi[SI_NUM] = {
  124. 103653, 51827, 12957, 808, 504, 246, 121, 120, 203, 122, 247, 51, 127, 14, 13,
  125. 0, 4, 5, 24, 62, 100, 253, 405, 1011, 1010, 1618, 3238, 6479, 25912, 207305, 207304};
  126. unsigned int codeBookLenSi[SI_NUM] = {
  127. 17, 16, 14, 10, 9, 8, 7, 7, 8, 7, 8, 6, 7, 4, 4, 1, 3, 3, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 15, 18, 18};
  128. #define SF_NUM 128
  129. unsigned int codeBookSf[SF_NUM] = {
  130. 61533, 61532, 61535, 61534, 61529, 61528, 61531, 61530, 153365, 153364, 153367, 153366, 153361, 153360, 153363, 153362,
  131. 153373, 153372, 153375, 153374, 153369, 153368, 153371, 153370, 15381, 15380, 19173, 19172, 4935, 9590, 4934, 2466,
  132. 2310, 960, 4794, 1217, 1219, 1232, 2311, 481, 1185, 617, 1199, 241, 312, 309, 598, 89,
  133. 153, 289, 33, 45, 79, 20, 31, 75, 14, 39, 8, 25, 8, 13, 3, 7,
  134. 1, 5, 0, 5, 24, 6, 38, 18, 9, 73, 23, 17, 145, 61, 43, 32,
  135. 297, 157, 155, 121, 88, 85, 597, 576, 313, 305, 169, 1192, 1186, 1193, 1187, 1184,
  136. 168, 2309, 2308, 1218, 1216, 1923, 9591, 3844, 19175, 153349, 76697, 153348, 153351, 153350, 153345, 153344,
  137. 153347, 153346, 153357, 153356, 153359, 153358, 153353, 153352, 153355, 153354, 153397, 153396, 153399, 153398, 153393, 153392};
  138. unsigned int codeBookLenSf[SF_NUM] = {
  139. 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
  140. 19, 19, 19, 19, 19, 19, 19, 19, 17, 17, 16, 16, 15, 15, 15, 14,
  141. 13, 13, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10,
  142. 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4,
  143. 1, 4, 4, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  144. 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
  145. 11, 13, 13, 13, 13, 14, 15, 15, 16, 19, 18, 19, 19, 19, 19, 19,
  146. 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
  147. };
  148. //bs
  149. int BitstreamOpen(FILE *fname);
  150. void BitstreamClose(void);
  151. void output_byte(long byte,int len);
  152. void start_outputing_bits();
  153. void done_outputing_bits();
  154. void FlushBuffer(void);
  155. void FlushBufferWithLength(void);
  156. int GetBitstreamSize(void);
  157. int ByteAlign(void);
  158. //~bs
  159. void BSHCInit(FILE *name);
  160. void BSHCClose(void);
  161. int EncodeBSHCQuant(int model,int upper,int cur);
  162. int EncodeBSHCSi(int siVal);
  163. int EncodeBSHCSf(int sfVal);
  164. int EncodeBSHCBin(int ms);
  165. void EncodeBSHCStart(void);
  166. void EncodeBSHCEnd(void);
  167. void EncodeBSHCPutBits(int val,int len);
  168. int EncodeBSHCGetSize();
  169. void EncodeBSHCHeader(int ch,int freq);
  170. int EncodeBSHCByteAlign(void);
  171. int BSHCModelSelect(int bshcModel,int bpl);
  172. void EncodeBSHCFlush(void);
  173. int WriteAASFHeader(int ch,int freq,int bitrate,int aasf_flag); //for AASF
  174. extern void FlushAASFHeaderBuffer();
  175. extern void get_end_band (
  176. int signal_type,
  177. int num_window_groups,
  178. int window_group_length[],
  179. int maxSfb,
  180. short *swb_offset[],
  181. int top_layer,
  182. int base_maxSfb[],
  183. int end_sfb[],
  184. int end_freq[],
  185. int end_cband[]
  186. );
  187. void BSHCInit(FILE *name)
  188. {
  189. BitstreamOpen(name);
  190. }
  191. void BSHCClose(void)
  192. {
  193. BitstreamClose();
  194. }
  195. void EncodeBSHCStart(void)
  196. {
  197. start_outputing_bits();
  198. }
  199. void EncodeBSHCEnd(void)
  200. {
  201. done_outputing_bits();
  202. }
  203. void EncodeBSHCFlush(void)
  204. {
  205. FlushBufferWithLength();
  206. }
  207. void EncodeBSHCHeader(int ch,int freq)
  208. {
  209. output_byte('A',8);
  210. output_byte('V',8);
  211. output_byte('S',8);
  212. output_byte('3',8);
  213. output_byte(ch,4);
  214. output_byte(freq,4);
  215. FlushBuffer();
  216. }
  217. /************************************************************************/
  218. /* AASF header */
  219. /************************************************************************/
  220. /* quick search element */
  221. typedef struct{
  222. int no_search_points;
  223. int search_point_dcption_present;
  224. unsigned int search_point_offset[128];
  225. int search_dcption_size[128];
  226. unsigned char search_point_dcption[128][64];
  227. }Quick_search_element;
  228. /* general info element */
  229. typedef struct{
  230. unsigned char Title[32];
  231. unsigned char Artist[32];
  232. unsigned char Album[32];
  233. unsigned char Year[4];
  234. unsigned char Genre;
  235. unsigned char Comment[32];
  236. unsigned char Composer[32];
  237. unsigned char Encoded_by[32];
  238. }General_info_element; /* 197 bytes, fixed length */
  239. /* lyrics element */
  240. typedef struct{
  241. int synchronised_id;
  242. unsigned char text_coding;
  243. unsigned char language[3];
  244. int lyrics_size;
  245. char* lyrics_text;
  246. int timestamp_format; /* 0 -- MPEG frames, 1 -- ms */
  247. int lyrics_timestamp;
  248. }Lyrics_element;
  249. /* user defined text element */
  250. typedef struct{
  251. unsigned char text_coding;
  252. unsigned char language[3];
  253. int user_text_size;
  254. char* user_define_text;
  255. }User_text_element;
  256. int WriteAASFHeader(int ch,int freq,int bitrate,int aasf_flag)
  257. {
  258. int num_stream_element;
  259. int quick_searching_flag;
  260. // int drm_flag; // wlei [20060320]
  261. int general_info_flag;
  262. int text_info_flag;
  263. int lyrics_present;
  264. int user_define_present;
  265. int bitstream_type = 1;
  266. int bitused = 0;
  267. int byteused;
  268. int i, j;
  269. Quick_search_element m_quick_search;
  270. General_info_element m_general_info;
  271. Lyrics_element m_lyrics;
  272. User_text_element m_user_text;
  273. lyrics_present = 1;
  274. user_define_present = 1;
  275. //defaut only one stream
  276. num_stream_element = 1;
  277. /* write AVS AASF ID */
  278. output_byte('A',8);
  279. output_byte('A',8);
  280. output_byte('S',8);
  281. output_byte('F',8);
  282. bitused += 32;
  283. /* write AASF header size */
  284. output_byte(0, 24);
  285. bitused += 24;
  286. /* NUM_STREAM_ELEMENT */
  287. output_byte(num_stream_element,8);
  288. bitused += 8;
  289. for(i = 0; i < num_stream_element; i++)
  290. {
  291. //aasf_flag = 0x40; //0100 0000
  292. //aasf_flag = 0x80; /* with quick search flag, 1000 0000 */
  293. //aasf_flag = 0xA0; /* with general info flag, 1010 0000 */
  294. aasf_flag = 0x0;
  295. /* write AASF flag */
  296. output_byte(aasf_flag, 8);
  297. bitused += 8;
  298. /* get flag status */
  299. quick_searching_flag = (aasf_flag>>7)&0x1;
  300. // drm_flag = (aasf_flag>>6)&0x1; // wlei [20060320]
  301. general_info_flag = (aasf_flag>>5)&0x1;
  302. text_info_flag = (aasf_flag>>4)&0x1;
  303. // wlei [20060223]
  304. /* raw stream length */
  305. output_byte(0, 32);
  306. bitused += 32;
  307. /* version */
  308. output_byte(0,2);
  309. /* coding profile */
  310. output_byte(0,2);
  311. /* sampling freq. index */
  312. //output_byte(freq+3,4);
  313. output_byte(freq, 4);
  314. /* bitrate */
  315. output_byte(bitrate, 23);
  316. /* bitstream type */
  317. output_byte(bitstream_type, 1);
  318. bitused += 32;
  319. /* buffer fullness */
  320. if(bitstream_type == 0)
  321. {
  322. /* dull */
  323. output_byte(0, 20);
  324. bitused += 20;
  325. }
  326. /* channel config */
  327. if(ch <= 2)
  328. output_byte(ch-1, 2);
  329. else if(ch == 6) /* 5.1 ch */
  330. output_byte(2, 2);
  331. else
  332. output_byte(3, 2);
  333. // bitused += 4; // wlei [20060223]
  334. bitused += 2;
  335. /* decoding information alignment */
  336. EncodeBSHCByteAlign();
  337. bitused = ((bitused+7)>>3)<<3;
  338. if(quick_searching_flag)
  339. {
  340. /* initialization */
  341. m_quick_search.no_search_points = 2;
  342. m_quick_search.search_point_dcption_present = 1;
  343. for(i = 0; i < m_quick_search.no_search_points; i++)
  344. {
  345. /* dummy value */
  346. m_quick_search.search_point_offset[i] = (i+1)*1024;
  347. m_quick_search.search_dcption_size[i] = 5;
  348. sprintf((char*)(m_quick_search.search_point_dcption[i]), "test");
  349. }
  350. /* write quick search info. */
  351. output_byte(m_quick_search.no_search_points, 7);
  352. output_byte(m_quick_search.search_point_dcption_present, 1);
  353. bitused += 8;
  354. for(i = 0; i < m_quick_search.no_search_points; i++)
  355. {
  356. output_byte(m_quick_search.search_point_offset[i], 32);
  357. bitused += 32;
  358. if(m_quick_search.search_point_dcption_present)
  359. {
  360. output_byte(m_quick_search.search_dcption_size[i], 8);
  361. for(j = 0; j < m_quick_search.search_dcption_size[i]; j ++)
  362. {
  363. output_byte(m_quick_search.search_point_dcption[i][j], 8);
  364. bitused += 8;
  365. }
  366. }
  367. }
  368. /* donot need byte alignment */
  369. }
  370. // wlei [20060320]
  371. // if(drm_flag)
  372. // {
  373. // }
  374. if(general_info_flag)
  375. {
  376. /* initialization */
  377. memcpy(m_general_info.Title, "NoName song", 12);
  378. memcpy(m_general_info.Artist, "NoName guy", 11);
  379. memcpy(m_general_info.Album, "NoName album", 13);
  380. memcpy(m_general_info.Year, "2005", 5);
  381. m_general_info.Genre = 0;
  382. memcpy(m_general_info.Comment, "comment", 8);
  383. memcpy(m_general_info.Composer, "NoName guy2", 12);
  384. memcpy(m_general_info.Encoded_by, "NoName encoder", 15);
  385. /* Title, 32 bytes */
  386. for(i = 0; i < 32; i ++)
  387. output_byte(m_general_info.Title[i], 8);
  388. /* Artist, 32 bytes */
  389. for(i = 0; i < 32; i ++)
  390. output_byte(m_general_info.Artist[i], 8);
  391. /* Album, 32 bytes */
  392. for(i = 0; i < 32; i ++)
  393. output_byte(m_general_info.Album[i], 8);
  394. /* Year, 4 bytes */
  395. for(i = 0; i < 4; i ++)
  396. output_byte(m_general_info.Year[i], 8);
  397. /* Genre, 1 bytes */
  398. output_byte(m_general_info.Genre, 8);
  399. /* Comment, 32 bytes */
  400. for(i = 0; i < 32; i ++)
  401. output_byte(m_general_info.Comment[i], 8);
  402. /* Composer, 32 bytes */
  403. for(i = 0; i < 32; i ++)
  404. output_byte(m_general_info.Composer[i], 8);
  405. /* Encoded_by, 32 bytes */
  406. for(i = 0; i < 32; i ++)
  407. output_byte(m_general_info.Encoded_by[i], 8);
  408. bitused += 1576; //197 bytes
  409. }
  410. if(text_info_flag)
  411. {
  412. output_byte(lyrics_present, 1);
  413. bitused += 1;
  414. if(lyrics_present)
  415. {
  416. /* initialization */
  417. // m_lyrics.synchronised_id = 0; /* non-sync */
  418. m_lyrics.synchronised_id = 1; /* sync */
  419. m_lyrics.lyrics_size = 12;
  420. m_lyrics.lyrics_text = (char *)malloc(m_lyrics.lyrics_size);
  421. memcpy(m_lyrics.lyrics_text, "lyrics text", 12);
  422. /* synchronised_id */
  423. output_byte(m_lyrics.synchronised_id, 1);
  424. /* text coding */
  425. output_byte(m_lyrics.text_coding, 8);
  426. /* language */
  427. for(i = 0; i < 3; i ++)
  428. output_byte(m_lyrics.language[i], 8);
  429. /* synchronised or not */
  430. if(m_lyrics.synchronised_id == 0)
  431. {
  432. /* lyrics size */
  433. output_byte(m_lyrics.lyrics_size, 22);
  434. /* lyrics text */
  435. for(i = 0; i < m_lyrics.lyrics_size; i ++)
  436. output_byte(m_lyrics.lyrics_text[i], 8);
  437. }
  438. else
  439. {
  440. /* timestamp format */
  441. output_byte(m_lyrics.timestamp_format, 2);
  442. bitused += 2;
  443. memcpy(m_lyrics.lyrics_text, "lyrics", 7);
  444. m_lyrics.lyrics_timestamp = 1;
  445. m_lyrics.lyrics_size = 7;
  446. /* lyrics size */
  447. output_byte(m_lyrics.lyrics_size+4, 22);
  448. /* lyrics text */
  449. for(i = 0; i < m_lyrics.lyrics_size; i ++)
  450. output_byte(m_lyrics.lyrics_text[i], 8);
  451. /* timestamp */
  452. output_byte(m_lyrics.lyrics_timestamp, 32);
  453. bitused += 32;
  454. }
  455. free(m_lyrics.lyrics_text);
  456. bitused += (m_lyrics.lyrics_size*8+1+8+24+22);
  457. }
  458. output_byte(user_define_present, 1);
  459. bitused += 1;
  460. if(user_define_present)
  461. {
  462. /* initialization */
  463. m_user_text.user_text_size = 17;
  464. m_user_text.user_define_text = (char *)malloc(m_user_text.user_text_size);
  465. memcpy(m_user_text.user_define_text, "user define text", 17);
  466. /* text coding */
  467. output_byte(m_user_text.text_coding, 8);
  468. /* language */
  469. for(i = 0; i < 3; i ++)
  470. output_byte(m_user_text.language[i], 8);
  471. /* user text size */
  472. output_byte(m_user_text.user_text_size, 22);
  473. /* user text info */
  474. for(i = 0; i < m_user_text.user_text_size; i ++)
  475. output_byte(m_user_text.user_define_text[i], 8);
  476. free(m_user_text.user_define_text);
  477. bitused += (m_user_text.user_text_size+8+24+22);
  478. }
  479. /* reserved_bit */
  480. output_byte(0, 1);
  481. bitused += 1;
  482. /* text information alignment */
  483. EncodeBSHCByteAlign();
  484. bitused = ((bitused+7)>>3)<<3;
  485. }
  486. }
  487. byteused = (bitused+7)>>3;
  488. FlushAASFHeaderBuffer();
  489. return byteused;
  490. }
  491. int EncodeBSHCQuant(int model,int upper,int cur)
  492. {
  493. output_byte((long)codeBook[model][upper][cur],codeBookLen[model][upper][cur]);
  494. return codeBookLen[model][upper][cur];
  495. }
  496. int EncodeBSHCSi(int siVal)
  497. {
  498. output_byte((long)codeBookSi[siVal],codeBookLenSi[siVal]);
  499. return codeBookLenSi[siVal];
  500. }
  501. int EncodeBSHCSf(int sfVal)
  502. {
  503. output_byte((long)codeBookSf[sfVal],codeBookLenSf[sfVal]);
  504. return codeBookLenSf[sfVal];
  505. }
  506. int EncodeBSHCBin(int ms)
  507. {
  508. if(ms==1)
  509. output_byte(1,1);
  510. else
  511. output_byte(0,1);
  512. return 1;
  513. }
  514. void EncodeBSHCPutBits(int val,int len)
  515. {
  516. output_byte((long)val,len);
  517. }
  518. int EncodeBSHCGetSize(void)
  519. {
  520. //in bits
  521. return GetBitstreamSize();
  522. }
  523. int EncodeBSHCByteAlign(void)
  524. {
  525. return ByteAlign();
  526. }
  527. int BSHCModelSelect(int bshcModel,int bpl)
  528. {
  529. int modelNum;
  530. int msb; /*model decision*/
  531. if(bshcModel >= 9)
  532. msb = bshcModel -4;
  533. else
  534. {
  535. msb = (bshcModel+1)/2;
  536. }
  537. if(msb==1)
  538. {
  539. modelNum = bshcModel;
  540. }
  541. if(msb==2)
  542. {
  543. if(bpl==2 && bshcModel==3) modelNum = 3;
  544. if(bpl==1 && bshcModel==3) modelNum = 4;
  545. if(bpl==2 && bshcModel==4) modelNum = 5;
  546. if(bpl==1 && bshcModel==4) modelNum = 6;
  547. }
  548. if(msb==3)
  549. {
  550. if(bpl==3 && bshcModel==5) modelNum = 7;
  551. if(bpl==2 && bshcModel==5) modelNum = 8;
  552. if(bpl==1 && bshcModel==5) modelNum = 9;
  553. if(bpl==3 && bshcModel==6) modelNum = 10;
  554. if(bpl==2 && bshcModel==6) modelNum = 11;
  555. if(bpl==1 && bshcModel==6) modelNum = 12;
  556. }
  557. if(msb==4)
  558. {
  559. if(bpl==4 && bshcModel==7) modelNum = 13;
  560. if(bpl==3 && bshcModel==7) modelNum = 14;
  561. if(bpl==2 && bshcModel==7) modelNum = 15;
  562. if(bpl==1 && bshcModel==7) modelNum = 16;
  563. if(bpl==4 && bshcModel==8) modelNum = 17;
  564. if(bpl==3 && bshcModel==8) modelNum = 18;
  565. if(bpl==2 && bshcModel==8) modelNum = 19;
  566. if(bpl==1 && bshcModel==8) modelNum = 20;
  567. }
  568. if(msb>4)
  569. {
  570. modelNum = 20+bpl;
  571. }
  572. return modelNum;
  573. }
  574. int BSHCFindModelBase(int msb)
  575. {
  576. int modelNum; /*model decision*/
  577. if(msb<=4)
  578. {
  579. modelNum = msb*msb-msb+1;
  580. }
  581. else
  582. {
  583. modelNum = 20;
  584. }
  585. return modelNum;
  586. }
  587. static int my_log2(int value)
  588. {
  589. int i, step;
  590. if(value < 0) {
  591. fprintf(stderr, "my_log2:error : %d\n", value);
  592. return 0;
  593. }
  594. if(value == 0) return 0;
  595. step = 2;
  596. for(i = 1; i < 24; i++) {
  597. if(value < step) return i;
  598. step *= 2;
  599. }
  600. return ( 1 + (int)(log10((double)value)/log10(2.0)));
  601. }
  602. int get_msb_of_samples (
  603. int sample[],
  604. int num_sample
  605. )
  606. {
  607. int i;
  608. int bal;
  609. int max = 0;
  610. for (i = 0; i < num_sample; i++) {
  611. if (abs(sample[i])>max)
  612. max = abs(sample[i]);
  613. }
  614. if(max > 0) bal = my_log2(max);
  615. else bal = 0;
  616. return bal;
  617. }
  618. void get_cband_msb (
  619. int num_window_groups,
  620. int *sample[],
  621. int max_cband[],
  622. int *band_qbit[]
  623. )
  624. {
  625. int g, cband, offset;
  626. for(g=0; g<num_window_groups; g++)
  627. for (cband = 0; cband < max_cband[g]; cband++) {
  628. offset = 32 * cband;
  629. band_qbit[g][cband] = get_msb_of_samples(&(sample[g][offset]), 32);
  630. }
  631. }
  632. int siCodeMode = 0;
  633. extern int cb_tab[16];
  634. void BSHCFindModel(
  635. int nch,
  636. int signal_type,
  637. int num_window_groups,
  638. int window_group_length[],
  639. int *sample[][8],
  640. int *scalefactors[][8],
  641. int maxSfb,
  642. short *swb_offset[],
  643. int top_layer,
  644. int *bshc_model[2][8]
  645. )
  646. {
  647. int ch, g;
  648. int cband;
  649. int end_cband[8]; /* Array Size : 64 -> 8 shpark 2000.04.20 */
  650. int end_sfb[8];
  651. int end_freq[8];
  652. int scf_model;
  653. int used_bits=0;
  654. int u_bits;
  655. int base_maxSfb[8]; /* maxsfb in each group */
  656. int band_snf[2][128];
  657. int *cband_qbit[2][8];
  658. int model;
  659. int curMask;
  660. int upperMask,bplMask;
  661. int bpl;
  662. int t1,t2,t3,t4;
  663. int cbBitCount1,cbBitCount2;
  664. int idx,i;
  665. int prevSi[2];
  666. int prevSf[2];
  667. if(maxSfb == 0) {
  668. used_bits = (int)((used_bits + 7) / 8) * 8;
  669. return;
  670. }
  671. /* Calculate base_maxSfb & maximum cband, qband, frequency */
  672. get_end_band (signal_type, num_window_groups, window_group_length,
  673. maxSfb, swb_offset, top_layer, base_maxSfb, end_sfb,
  674. end_freq, end_cband);
  675. /* Determine the arithmetic model for the Slice-Bits */
  676. for(ch = 0; ch < nch; ch++) {
  677. cband_qbit[ch][0] = &(band_snf[ch][0]);
  678. for (g = 1; g < num_window_groups; g++) {
  679. cband_qbit[ch][g] = cband_qbit[ch][g-1] + end_cband[g-1];
  680. }
  681. get_cband_msb ( num_window_groups, sample[ch], end_cband,
  682. cband_qbit[ch]);
  683. /*bshc model selection*/
  684. for (g = 0; g < num_window_groups; g++)
  685. for(cband=0;cband<end_cband[g];cband++)
  686. {
  687. if(cband_qbit[ch][g][cband]==0)
  688. bshc_model[ch][g][cband] = 0;
  689. else if(cband_qbit[ch][g][cband]>=5)
  690. {
  691. bshc_model[ch][g][cband] = (cband_qbit[ch][g][cband]+4);
  692. }
  693. else
  694. {
  695. /*BSHCFindModelBase(cband_qbit[ch][g][cband])*/
  696. /*count cband bits*/
  697. bshc_model[ch][g][cband] = cband_qbit[ch][g][cband]*2-1;
  698. for(cbBitCount1=0,i=0;i<8;i++)
  699. {
  700. idx = cband*32+i*4;
  701. for(upperMask=0,bpl=cband_qbit[ch][g][cband];bpl>0;bpl--)
  702. {
  703. bplMask = 1<<(bpl-1);
  704. if(abs(sample[ch][g][idx]) & bplMask)
  705. t1 = 1;
  706. else t1 = 0;
  707. if(abs(sample[ch][g][idx+1]) & bplMask)
  708. t2 = 1;
  709. else t2 = 0;
  710. if(abs(sample[ch][g][idx+2]) & bplMask)
  711. t3 = 1;
  712. else t3 = 0;
  713. if(abs(sample[ch][g][idx+3]) & bplMask)
  714. t4 = 1;
  715. else t4 = 0;
  716. curMask = (t1<<3) + (t2<<2) + (t3<<1) +t4;
  717. model = BSHCFindModelBase(cband_qbit[ch][g][cband])+(cband_qbit[ch][g][cband]-bpl);
  718. /* codebook reduction */
  719. upperMask = cb_tab[upperMask];
  720. cbBitCount1 += codeBookLen[model][upperMask][curMask];
  721. upperMask = curMask;
  722. }
  723. }
  724. bshc_model[ch][g][cband] = cband_qbit[ch][g][cband]*2;
  725. for(cbBitCount2=0,i=0;i<8;i++)
  726. {
  727. idx = cband*32+i*4;
  728. for(upperMask=0,bpl= cband_qbit[ch][g][cband];bpl>0;bpl--)
  729. {
  730. bplMask = 1<<(bpl-1);
  731. if(abs(sample[ch][g][idx]) & bplMask)
  732. t1 = 1;
  733. else t1 = 0;
  734. if(abs(sample[ch][g][idx+1]) & bplMask)
  735. t2 = 1;
  736. else t2 = 0;
  737. if(abs(sample[ch][g][idx+2]) & bplMask)
  738. t3 = 1;
  739. else t3 = 0;
  740. if(abs(sample[ch][g][idx+3]) & bplMask)
  741. t4 = 1;
  742. else t4 = 0;
  743. curMask = (t1<<3) + (t2<<2) + (t3<<1) +t4;
  744. model = BSHCFindModelBase(cband_qbit[ch][g][cband])+(2*cband_qbit[ch][g][cband]-bpl);
  745. /* codebook reduction */
  746. upperMask = cb_tab[upperMask];
  747. cbBitCount2 += codeBookLen[model][upperMask][curMask];
  748. upperMask = curMask;
  749. }
  750. }
  751. if(cbBitCount2>cbBitCount1)
  752. {
  753. bshc_model[ch][g][cband] = cband_qbit[ch][g][cband]*2-1;
  754. cbBitCount2 = cbBitCount1;
  755. }
  756. used_bits += cbBitCount2;
  757. }
  758. }
  759. }
  760. }
  761. /*+----------------------------------------------------+
  762. | |
  763. | AATF header write |
  764. | |
  765. +----------------------------------------------------+*/
  766. #define SYNCWORD 0x00000001
  767. #define ID 0x00000000
  768. #define CODING_PROFILE 0x00000000
  769. #define DECODING_STATUS_PRESENT 0x00000001
  770. #define DRM_PRESENT 0x00000000
  771. #define GENERAL_INFO_PRESENT 0x00000000
  772. #define TEXT_INFO_PRESENT 0x00000000
  773. #define BITSTREAM_TYPE 0x00000001
  774. #define CHANNEL_CONFIG 0x00000000
  775. #define LYRICS_PRESENT 0x00000001
  776. /* vacant function */
  777. int aatf_error_check()
  778. {
  779. return 0;
  780. }
  781. /* vacant function */
  782. int aatf_raw_data_block_error_check()
  783. {
  784. return 0;
  785. }
  786. /* vacant function */
  787. int aatf_header_error_check()
  788. {
  789. return 0;
  790. }
  791. /* vacant function */
  792. // wlei [20060320]
  793. //int DRM_element()
  794. //{
  795. // return 0;
  796. int general_info_element()
  797. {
  798. int i;
  799. General_info_element m_general_info;
  800. memcpy(m_general_info.Title, "NoName song", 12);
  801. memcpy(m_general_info.Artist, "NoName guy", 11);
  802. memcpy(m_general_info.Album, "NoName album", 13);
  803. memcpy(m_general_info.Year, "2005", 5);
  804. m_general_info.Genre = 0;
  805. memcpy(m_general_info.Comment, "comment", 8);
  806. memcpy(m_general_info.Composer, "NoName guy2", 12);
  807. memcpy(m_general_info.Encoded_by, "NoName encoder", 15);
  808. /* Title, 32 bytes */
  809. for(i = 0; i < 32; i ++)
  810. output_byte(m_general_info.Title[i], 8);
  811. /* Artist, 32 bytes */
  812. for(i = 0; i < 32; i ++)
  813. output_byte(m_general_info.Artist[i], 8);
  814. /* Album, 32 bytes */
  815. for(i = 0; i < 32; i ++)
  816. output_byte(m_general_info.Album[i], 8)