compute_basis.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include "../src/dct.h"
  6. #include "../src/filter.h"
  7. void usage(char *str) {
  8. fprintf(stderr,
  9. "usage: %s <log size - 2> <coeff | coeff420 | mag | mag420>\n", str);
  10. }
  11. #define OD_BASIS_SIZE (3*OD_BSIZE_MAX)
  12. #define OD_BASIS_PULSE 1024
  13. /* Computes the synthesis basis functions and their magnitudes. The lapping
  14. filter is selected exactly as it would in the codec, including the 4x4
  15. blocks that have 8x8 lapping on one side and 4x4 on the other. The exact
  16. lapping filters are controlled by the "left" and "right" variables. */
  17. int main(int argc, char **argv) {
  18. int i;
  19. int j;
  20. int n;
  21. int ln;
  22. int left;
  23. int right;
  24. int magnitude;
  25. int dec;
  26. od_coeff x0[OD_BASIS_SIZE];
  27. od_coeff y0[OD_BASIS_SIZE];
  28. od_coeff *x;
  29. od_coeff *y;
  30. if (argc != 3) {
  31. usage(argv[0]);
  32. return 1;
  33. }
  34. ln = atoi(argv[1]);
  35. dec = 0;
  36. if (strcmp("mag", argv[2]) == 0) {
  37. magnitude = 1;
  38. }
  39. else if (strcmp("coeff", argv[2]) == 0) {
  40. magnitude = 0;
  41. }
  42. else if (strcmp("mag420", argv[2]) == 0) {
  43. magnitude = 1;
  44. dec = 1;
  45. }
  46. else if (strcmp("coeff420", argv[2]) == 0) {
  47. magnitude = 0;
  48. dec = 1;
  49. }
  50. else {
  51. usage(argv[0]);
  52. return 1;
  53. }
  54. n = 4 << ln;
  55. /* The first lapping filter is applied based on a larger (unsplit)
  56. block size. */
  57. left = OD_FILT_SIZE(OD_MINI(OD_NBSIZES - 1, ln + 1), dec);
  58. right = OD_FILT_SIZE(ln, dec);
  59. for (i = 0; i < n; i++) {
  60. OD_CLEAR(x0, OD_BASIS_SIZE);
  61. OD_CLEAR(y0, OD_BASIS_SIZE);
  62. x = &x0[n];
  63. y = &y0[n];
  64. x[i] = OD_BASIS_PULSE;
  65. OD_IDCT_1D[ln](y, 1, x);
  66. /* We need to apply left before right for 4x4 because the wider lapping
  67. is always applied first. */
  68. OD_POST_FILTER[left](y - (2 << left), y - (2 << left));
  69. OD_POST_FILTER[right](y + n - (2 << right), y + n - (2 << right));
  70. if (magnitude) {
  71. double sum;
  72. sum = 0;
  73. for (j = 0; j < n + (2 << left) + (2 << right); j++) {
  74. sum += y[j - (2 << left)]*y[j - (2 << left)];
  75. }
  76. printf("%f ", sqrt(sum)/OD_BASIS_PULSE);
  77. }
  78. else {
  79. for (j = 0; j < n + (2 << left) + (2 << right); j++) {
  80. printf("%d ", y[j - (2 << left)]);
  81. }
  82. printf("\n");
  83. }
  84. }
  85. if (magnitude) printf("\n");
  86. return 0;
  87. }