| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#ifdef HAVE_CONFIG_H |
| 34 |
#include "config.h" |
| 35 |
#endif |
| 36 |
|
| 37 |
#include "misc.h" |
| 38 |
#include <stdlib.h> |
| 39 |
#include <string.h> |
| 40 |
#include <stdio.h> |
| 41 |
|
| 42 |
#ifndef RELEASE |
| 43 |
void print_vec(float *vec, int len, char *name) |
| 44 |
{ |
| 45 |
int i; |
| 46 |
printf ("%s ", name); |
| 47 |
for (i=0;i<len;i++) |
| 48 |
printf (" %f", vec[i]); |
| 49 |
printf ("\n"); |
| 50 |
} |
| 51 |
#endif |
| 52 |
|
| 53 |
#ifdef FIXED_DEBUG |
| 54 |
long long spx_mips=0; |
| 55 |
#endif |
| 56 |
|
| 57 |
|
| 58 |
spx_uint32_t be_int(spx_uint32_t i) |
| 59 |
{ |
| 60 |
spx_uint32_t ret=i; |
| 61 |
#ifndef WORDS_BIGENDIAN |
| 62 |
ret = i>>24; |
| 63 |
ret += (i>>8)&0x0000ff00; |
| 64 |
ret += (i<<8)&0x00ff0000; |
| 65 |
ret += (i<<24); |
| 66 |
#endif |
| 67 |
return ret; |
| 68 |
} |
| 69 |
|
| 70 |
spx_uint32_t le_int(spx_uint32_t i) |
| 71 |
{ |
| 72 |
spx_uint32_t ret=i; |
| 73 |
#ifdef WORDS_BIGENDIAN |
| 74 |
ret = i>>24; |
| 75 |
ret += (i>>8)&0x0000ff00; |
| 76 |
ret += (i<<8)&0x00ff0000; |
| 77 |
ret += (i<<24); |
| 78 |
#endif |
| 79 |
return ret; |
| 80 |
} |
| 81 |
|
| 82 |
#if BYTES_PER_CHAR == 2 |
| 83 |
void speex_memcpy_bytes(char *dst, char *src, int nbytes) |
| 84 |
{ |
| 85 |
int i; |
| 86 |
int nchars = nbytes/BYTES_PER_CHAR; |
| 87 |
for (i=0;i<nchars;i++) |
| 88 |
dst[i]=src[i]; |
| 89 |
if (nbytes & 1) { |
| 90 |
|
| 91 |
int last_i = nchars; |
| 92 |
char last_dst_char = dst[last_i]; |
| 93 |
char last_src_char = src[last_i]; |
| 94 |
last_dst_char &= 0xff00; |
| 95 |
last_dst_char |= (last_src_char & 0x00ff); |
| 96 |
dst[last_i] = last_dst_char; |
| 97 |
} |
| 98 |
} |
| 99 |
void speex_memset_bytes(char *dst, char c, int nbytes) |
| 100 |
{ |
| 101 |
int i; |
| 102 |
spx_int16_t cc = ((c << 8) | c); |
| 103 |
int nchars = nbytes/BYTES_PER_CHAR; |
| 104 |
for (i=0;i<nchars;i++) |
| 105 |
dst[i]=cc; |
| 106 |
if (nbytes & 1) { |
| 107 |
|
| 108 |
int last_i = nchars; |
| 109 |
char last_dst_char = dst[last_i]; |
| 110 |
last_dst_char &= 0xff00; |
| 111 |
last_dst_char |= (c & 0x00ff); |
| 112 |
dst[last_i] = last_dst_char; |
| 113 |
} |
| 114 |
} |
| 115 |
#else |
| 116 |
void speex_memcpy_bytes(char *dst, char *src, int nbytes) |
| 117 |
{ |
| 118 |
memcpy(dst, src, nbytes); |
| 119 |
} |
| 120 |
void speex_memset_bytes(char *dst, char src, int nbytes) |
| 121 |
{ |
| 122 |
memset(dst, src, nbytes); |
| 123 |
} |
| 124 |
#endif |
| 125 |
|
| 126 |
void *speex_alloc (int size) |
| 127 |
{ |
| 128 |
return calloc(size,1); |
| 129 |
} |
| 130 |
|
| 131 |
void *speex_realloc (void *ptr, int size) |
| 132 |
{ |
| 133 |
return realloc(ptr, size); |
| 134 |
} |
| 135 |
|
| 136 |
void speex_free (void *ptr) |
| 137 |
{ |
| 138 |
free(ptr); |
| 139 |
} |
| 140 |
|
| 141 |
void *speex_move (void *dest, void *src, int n) |
| 142 |
{ |
| 143 |
return memmove(dest,src,n); |
| 144 |
} |
| 145 |
|
| 146 |
void speex_error(const char *str) |
| 147 |
{ |
| 148 |
fprintf (stderr, "Fatal error: %s\n", str); |
| 149 |
exit(1); |
| 150 |
} |
| 151 |
|
| 152 |
void speex_warning(const char *str) |
| 153 |
{ |
| 154 |
fprintf (stderr, "warning: %s\n", str); |
| 155 |
} |
| 156 |
|
| 157 |
void speex_warning_int(const char *str, int val) |
| 158 |
{ |
| 159 |
fprintf (stderr, "warning: %s %d\n", str, val); |
| 160 |
} |
| 161 |
|
| 162 |
void speex_rand_vec(float std, spx_sig_t *data, int len) |
| 163 |
{ |
| 164 |
int i; |
| 165 |
for (i=0;i<len;i++) |
| 166 |
data[i]+=SIG_SCALING*3*std*((((float)rand())/RAND_MAX)-.5); |
| 167 |
} |
| 168 |
|
| 169 |
float speex_rand(float std) |
| 170 |
{ |
| 171 |
return 3*std*((((float)rand())/RAND_MAX)-.5); |
| 172 |
} |
| 173 |
|
| 174 |
void _speex_putc(int ch, void *file) |
| 175 |
{ |
| 176 |
FILE *f = (FILE *)file; |
| 177 |
fprintf(f, "%c", ch); |
| 178 |
} |