sour.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 1996 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /*$Header*/
  7. /* Generate code to pack a bit array from a name:#bits description,
  8. * WAV #49 style.
  9. */
  10. #include <stdio.h>
  11. #include "taste.h"
  12. #include "proto.h"
  13. #include <limits.h>
  14. /* This module goes back to one Jeff Chilton used for his implementation
  15. * of the #49 WAV GSM format. (In his original patch 8, it replaced
  16. * bitter.c.)
  17. *
  18. * In Microsoft's WAV #49 version of the GSM format, two 32 1/2
  19. * byte GSM frames are packed together to make one WAV frame, and
  20. * the GSM parameters are packed into bytes right-to-left rather
  21. * than left-to-right.
  22. *
  23. * That is, where toast's GSM format writes
  24. *
  25. * aaaaaabb bbbbcccc cdddddee ...
  26. * ___1____ ___2____ ___3____
  27. *
  28. * for parameters a (6 bits), b (6 bits), c (5 bits), d (5 bits), e ..
  29. * the WAV format has
  30. *
  31. * bbaaaaaa ccccbbbb eedddddc ...
  32. * ___1____ ___2____ ___3____
  33. *
  34. * (This format looks a lot prettier if one pictures octets coming
  35. * in through a fifo queue from the left, rather than waiting in the
  36. * right-hand remainder of a C array.)
  37. */
  38. #define WORD_BITS 16 /* sizeof(uword) * CHAR_BIT on the
  39. * target architecture---if this isn't 16,
  40. * you're in trouble with this library anyway.
  41. */
  42. #define BYTE_BITS 8 /* CHAR_BIT on the target architecture---
  43. * if this isn't 8, you're in *deep* trouble.
  44. */
  45. void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
  46. {
  47. struct spex * sp = s_spex;
  48. int n_in = 0;
  49. printf("uword sr = 0;\n");
  50. for (; n_spex > 0; n_spex--, sp++) {
  51. /* insert old
  52. * new var value unused
  53. * here
  54. *
  55. * [____________xxxxxx**********]
  56. *
  57. * <----- n_in ------>
  58. */
  59. printf("sr = sr >> %d | %s << %d;\n",
  60. sp->varsize,
  61. sp->var,
  62. WORD_BITS - sp->varsize);
  63. n_in += sp->varsize;
  64. while (n_in >= BYTE_BITS) {
  65. printf("*c++ = sr >> %d;\n",
  66. WORD_BITS - n_in);
  67. n_in -= BYTE_BITS;
  68. }
  69. }
  70. while (n_in >= BYTE_BITS) {
  71. printf("*c++ = sr >> %d;\n", WORD_BITS - n_in);
  72. n_in -= BYTE_BITS;
  73. }
  74. if (n_in > 0) {
  75. fprintf(stderr, "warning: %d bits left over\n", n_in);
  76. }
  77. }