print_switch_table.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. function print_switch_table (p32, p16, p8, filename)
  2. file=fopen(filename, 'w');
  3. fprintf(file, "/* This file is generated by print_switch_table.m */\n");
  4. fprintf(file, "#include <ogg/os_types.h>\n");
  5. fprintf(file, "const ogg_uint16_t od_switch_size32_cdf[][3] = {\n");
  6. for k=1:length(p32)
  7. p = max(1,round(p32(:,k)*32768));
  8. s = sum(p);
  9. [a,b]=max(p);
  10. p(b) = p(b)+32768-s;
  11. if (sum(p)!=32768)
  12. fprintf(stderr, "failed to renormalize\n");
  13. end
  14. p = filter(1, [1,-1], p);
  15. fprintf(file, " {");
  16. fprintf(file, "%d, ", p(1:end-1));
  17. fprintf(file, "%d", p(end));
  18. fprintf(file, "}");
  19. if (k!=length(p32))
  20. fprintf(file,",");
  21. end
  22. fprintf(file, "\n");
  23. end
  24. fprintf(file, "};\n\n");
  25. fprintf(file, "const ogg_uint16_t od_switch_size16_cdf[][8] = {\n");
  26. for k=1:length(p16)
  27. p = max(1,round(p16(:,k)*32768));
  28. s = sum(p);
  29. [a,b]=max(p);
  30. p(b) = p(b)+32768-s;
  31. if (sum(p)!=32768)
  32. fprintf(stderr, "failed to renormalize\n");
  33. end
  34. p = filter(1, [1,-1], p);
  35. fprintf(file, " {");
  36. fprintf(file, "%d, ", p(1:end-1));
  37. fprintf(file, "%d", p(end));
  38. fprintf(file, "}");
  39. if (k!=length(p16))
  40. fprintf(file,",");
  41. end
  42. fprintf(file, "\n");
  43. end
  44. fprintf(file, "};\n\n");
  45. fprintf(file, "const ogg_uint16_t od_switch_size8_cdf[][16] = {\n");
  46. for k=1:length(p8)
  47. p = max(1,round(p8(:,k)*32768));
  48. s = sum(p);
  49. [a,b]=max(p);
  50. p(b) = p(b)+32768-s;
  51. if (sum(p)!=32768)
  52. fprintf(stderr, "failed to renormalize\n");
  53. end
  54. p = filter(1, [1,-1], p);
  55. fprintf(file, " {");
  56. fprintf(file, "%d, ", p(1:8));
  57. fprintf(file, "\n ");
  58. fprintf(file, "%d, ", p(9:end-1));
  59. fprintf(file, "%d", p(end));
  60. fprintf(file, "}");
  61. if (k!=length(p8))
  62. fprintf(file,",");
  63. end
  64. fprintf(file, "\n");
  65. end
  66. fprintf(file, "};\n");
  67. fclose(file);
  68. end