Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.3 KiB

  1. /* Copyright (C) 2002 Jean-Marc Valin
  2. File: mics.c
  3. Various utility routines for Speex
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. - Neither the name of the Xiph.org Foundation nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "misc.h"
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdio.h>
  31. #ifndef RELEASE
  32. void print_vec(float *vec, int len, char *name)
  33. {
  34. int i;
  35. printf ("%s ", name);
  36. for (i=0;i<len;i++)
  37. printf (" %f", vec[i]);
  38. printf ("\n");
  39. }
  40. #endif
  41. unsigned int be_int(unsigned int i)
  42. {
  43. unsigned int ret=i;
  44. #ifndef WORDS_BIGENDIAN
  45. ret = i>>24;
  46. ret += (i>>8)&0x0000ff00;
  47. ret += (i<<8)&0x00ff0000;
  48. ret += (i<<24);
  49. #endif
  50. return ret;
  51. }
  52. unsigned int le_int(unsigned int i)
  53. {
  54. unsigned int ret=i;
  55. #ifdef WORDS_BIGENDIAN
  56. ret = i>>24;
  57. ret += (i>>8)&0x0000ff00;
  58. ret += (i<<8)&0x00ff0000;
  59. ret += (i<<24);
  60. #endif
  61. return ret;
  62. }
  63. unsigned short be_short(unsigned short s)
  64. {
  65. unsigned short ret=s;
  66. #ifndef WORDS_BIGENDIAN
  67. ret = s>>8;
  68. ret += s<<8;
  69. #endif
  70. return ret;
  71. }
  72. unsigned short le_short(unsigned short s)
  73. {
  74. unsigned short ret=s;
  75. #ifdef WORDS_BIGENDIAN
  76. ret = s>>8;
  77. ret += s<<8;
  78. #endif
  79. return ret;
  80. }
  81. void *speex_alloc (int size)
  82. {
  83. return calloc(size,1);
  84. }
  85. void *speex_realloc (void *ptr, int size)
  86. {
  87. return realloc(ptr, size);
  88. }
  89. void speex_free (void *ptr)
  90. {
  91. free(ptr);
  92. }
  93. void *speex_move (void *dest, void *src, int n)
  94. {
  95. return memmove(dest,src,n);
  96. }
  97. void speex_error(char *str)
  98. {
  99. fprintf (stderr, "Fatal error: %s\n", str);
  100. exit(1);
  101. }
  102. void speex_warning(char *str)
  103. {
  104. fprintf (stderr, "warning: %s\n", str);
  105. }
  106. void speex_warning_int(char *str, int val)
  107. {
  108. fprintf (stderr, "warning: %s %d\n", str, val);
  109. }
  110. void speex_rand_vec(float std, float *data, int len)
  111. {
  112. int i;
  113. for (i=0;i<len;i++)
  114. data[i]+=3*std*((((float)rand())/RAND_MAX)-.5);
  115. }
  116. float speex_rand(float std)
  117. {
  118. return 3*std*((((float)rand())/RAND_MAX)-.5);
  119. }
  120. void _speex_putc(int ch, void *file)
  121. {
  122. FILE *f = (FILE *)file;
  123. fputc(ch, f);
  124. }