comparison minijss/jssmod.c @ 1129:e466d10dae6d

Change API of jssDecodeSample{8,16}() functions to return dmlib error codes instead of plain boolean value. Change some of the relevant places to use this return value.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2015 06:31:54 +0200
parents e22d4ceb6414
children aa3738b121d1
comparison
equal deleted inserted replaced
1128:0194c8a26aa8 1129:e466d10dae6d
124 #endif 124 #endif
125 125
126 126
127 /* Decodes a given 8-bit sample 127 /* Decodes a given 8-bit sample
128 */ 128 */
129 BOOL jssDecodeSample8(Uint8 * data, const size_t len, const int ops) 129 int jssDecodeSample8(Uint8 * data, const size_t len, const int ops)
130 { 130 {
131 size_t count = len; 131 size_t count = len;
132 Sint8 t, value = 0; 132 Sint8 t, value = 0;
133 133
134 while (count--) 134 while (count--)
141 if (ops & jsampFlipSign) 141 if (ops & jsampFlipSign)
142 t ^= 0x80; 142 t ^= 0x80;
143 143
144 *(data++) = t; 144 *(data++) = t;
145 } 145 }
146 return TRUE; 146 return DMERR_OK;
147 } 147 }
148 148
149 149
150 /* Decodes a given 16-bit sample 150 /* Decodes a given 16-bit sample
151 */ 151 */
152 BOOL jssDecodeSample16(Uint16 * data, const size_t len, const int ops) 152 int jssDecodeSample16(Uint16 * data, const size_t len, const int ops)
153 { 153 {
154 if (ops & jsampSplit) 154 if (ops & jsampSplit)
155 { 155 {
156 size_t count, bufSize = len * sizeof(Uint16); 156 size_t count, bufSize = len * sizeof(Uint16);
157 Uint8 *bp1, *bp2; 157 Uint8 *bp1, *bp2;
158 Sint16 *tmpBuf, *sdata; 158 Sint16 *tmpBuf, *sdata;
159 159 int ret;
160 if (!jssDecodeSample8((Uint8 *) data, bufSize, ops)) 160
161 return FALSE; 161 if ((ret = jssDecodeSample8((Uint8 *) data, bufSize, ops)) != DMERR_OK)
162 162 return ret;
163 tmpBuf = dmMalloc(bufSize); 163
164 if (tmpBuf == NULL) return FALSE; 164 if ((tmpBuf = dmMalloc(bufSize)) == NULL)
165 return DMERR_MALLOC;
166
165 memcpy(tmpBuf, data, bufSize); 167 memcpy(tmpBuf, data, bufSize);
166 168
167 sdata = (Sint16 *) data; 169 sdata = (Sint16 *) data;
168 bp1 = (Uint8 *) tmpBuf; 170 bp1 = (Uint8 *) tmpBuf;
169 bp2 = bp1 + len; 171 bp2 = bp1 + len;
196 t ^= 0x8000; 198 t ^= 0x8000;
197 199
198 *(sdata++) = t; 200 *(sdata++) = t;
199 } 201 }
200 } 202 }
201 return TRUE; 203 return DMERR_OK;
202 } 204 }
203 205
204 206
205 /* Convert sample data from U8 to S16 207 /* Convert sample data from U8 to S16
206 */ 208 */
208 { 210 {
209 size_t count = len; 211 size_t count = len;
210 Uint8 *in = (Uint8 *) src; 212 Uint8 *in = (Uint8 *) src;
211 Sint16 *out; 213 Sint16 *out;
212 214
213 *dst = out = dmMalloc(sizeof(Sint16) * len); 215 if ((*dst = out = dmMalloc(sizeof(Sint16) * len)) == NULL)
214 if (out == NULL)
215 return DMERR_MALLOC; 216 return DMERR_MALLOC;
216 217
217 while (count--) 218 while (count--)
218 { 219 {
219 *(out++) = (*(in++) * 256) - 32768; 220 *(out++) = (*(in++) * 256) - 32768;