/project/jni/sdl_sound/decoders/timidity/output.c

https://github.com/aichunyu/FFPlayer · C · 116 lines · 80 code · 11 blank · 25 comment · 24 complexity · 090c991112d8cdc534f859b183937f0a MD5 · raw file

  1. /*
  2. TiMidity -- Experimental MIDI to WAVE converter
  3. Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. output.c
  16. Audio output (to file / device) functions.
  17. */
  18. #if HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "SDL_sound.h"
  22. #define __SDL_SOUND_INTERNAL__
  23. #include "SDL_sound_internal.h"
  24. #include "options.h"
  25. #include "output.h"
  26. /*****************************************************************/
  27. /* Some functions to convert signed 32-bit data to other formats */
  28. void s32tos8(void *dp, Sint32 *lp, Sint32 c)
  29. {
  30. Sint8 *cp=(Sint8 *)(dp);
  31. Sint32 l;
  32. while (c--)
  33. {
  34. l=(*lp++)>>(32-8-GUARD_BITS);
  35. if (l>127) l=127;
  36. else if (l<-128) l=-128;
  37. *cp++ = (Sint8) (l);
  38. }
  39. }
  40. void s32tou8(void *dp, Sint32 *lp, Sint32 c)
  41. {
  42. Uint8 *cp=(Uint8 *)(dp);
  43. Sint32 l;
  44. while (c--)
  45. {
  46. l=(*lp++)>>(32-8-GUARD_BITS);
  47. if (l>127) l=127;
  48. else if (l<-128) l=-128;
  49. *cp++ = 0x80 ^ ((Uint8) l);
  50. }
  51. }
  52. void s32tos16(void *dp, Sint32 *lp, Sint32 c)
  53. {
  54. Sint16 *sp=(Sint16 *)(dp);
  55. Sint32 l;
  56. while (c--)
  57. {
  58. l=(*lp++)>>(32-16-GUARD_BITS);
  59. if (l > 32767) l=32767;
  60. else if (l<-32768) l=-32768;
  61. *sp++ = (Sint16)(l);
  62. }
  63. }
  64. void s32tou16(void *dp, Sint32 *lp, Sint32 c)
  65. {
  66. Uint16 *sp=(Uint16 *)(dp);
  67. Sint32 l;
  68. while (c--)
  69. {
  70. l=(*lp++)>>(32-16-GUARD_BITS);
  71. if (l > 32767) l=32767;
  72. else if (l<-32768) l=-32768;
  73. *sp++ = 0x8000 ^ (Uint16)(l);
  74. }
  75. }
  76. void s32tos16x(void *dp, Sint32 *lp, Sint32 c)
  77. {
  78. Sint16 *sp=(Sint16 *)(dp);
  79. Sint32 l;
  80. while (c--)
  81. {
  82. l=(*lp++)>>(32-16-GUARD_BITS);
  83. if (l > 32767) l=32767;
  84. else if (l<-32768) l=-32768;
  85. *sp++ = SDL_Swap16((Sint16)(l));
  86. }
  87. }
  88. void s32tou16x(void *dp, Sint32 *lp, Sint32 c)
  89. {
  90. Uint16 *sp=(Uint16 *)(dp);
  91. Sint32 l;
  92. while (c--)
  93. {
  94. l=(*lp++)>>(32-16-GUARD_BITS);
  95. if (l > 32767) l=32767;
  96. else if (l<-32768) l=-32768;
  97. *sp++ = SDL_Swap16(0x8000 ^ (Uint16)(l));
  98. }
  99. }