Leaked source code of windows server 2003
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.

395 lines
11 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: slib_render.c,v $
  7. * Revision 1.1.2.3 1996/10/28 17:32:35 Hans_Graves
  8. * MME-1402, 1431, 1435: Timestamp related changes.
  9. * [1996/10/28 17:23:09 Hans_Graves]
  10. *
  11. * Revision 1.1.2.2 1996/10/12 17:18:58 Hans_Graves
  12. * Move render related code out of slib_api.c
  13. * [1996/10/11 21:19:37 Hans_Graves]
  14. *
  15. * $EndLog$
  16. */
  17. /*
  18. #define _SLIBDEBUG_
  19. */
  20. #define SLIB_INTERNAL
  21. #include "slib.h"
  22. #include "SC_err.h"
  23. #include "SC_conv.h"
  24. #ifdef _SLIBDEBUG_
  25. #include "sc_debug.h"
  26. #define _DEBUG_ 0 /* detailed debuging statements */
  27. #define _VERBOSE_ 1 /* show progress */
  28. #define _VERIFY_ 1 /* verify correct operation */
  29. #define _WARN_ 1 /* warnings about strange behavior */
  30. #endif
  31. SlibStatus_t slibConvertAudio(SlibInfo_t *Info,
  32. void *inbuf, unsigned dword inbufsize,
  33. unsigned int insps, unsigned int inbps,
  34. void **poutbuf, unsigned dword *poutbufsize,
  35. unsigned int outsps, unsigned int outbps,
  36. unsigned int channels)
  37. {
  38. char *fromptr, *toptr;
  39. unsigned dword outbufsize, samples, count;
  40. unsigned dword ratio, spsratio;
  41. char *outbuf;
  42. if (inbps==outbps && insps==outsps)/* input and output formats are the same */
  43. {
  44. if (*poutbuf==NULL)
  45. {
  46. SlibAllocSubBuffer(inbuf, inbufsize);
  47. *poutbuf=inbuf;
  48. }
  49. else
  50. memcpy(*poutbuf, inbuf, inbufsize);
  51. *poutbufsize=inbufsize;
  52. return(SlibErrorNone);
  53. }
  54. samples = inbufsize/(inbps/2);
  55. ratio=(insps*inbps*256)/(outsps*outbps);
  56. outbufsize = (inbufsize*256)/ratio;
  57. spsratio=(insps*256)/outsps;
  58. if (spsratio!=64 && spsratio!=128 && spsratio!=256 && spsratio!=512)
  59. return(SlibErrorUnsupportedFormat);
  60. if (*poutbuf==NULL)
  61. {
  62. outbuf=SlibAllocBuffer(outbufsize);
  63. *poutbuf=outbuf;
  64. if (outbuf==NULL)
  65. return(SlibErrorMemory);
  66. }
  67. else
  68. outbuf=*poutbuf;
  69. *poutbufsize=outbufsize;
  70. fromptr = (char *)inbuf;
  71. toptr = (char *)outbuf;
  72. if (inbps==16 && outbps==8) /* 16 bit -> 8 bit */
  73. {
  74. fromptr++;
  75. if (spsratio==64) /* insps==outsps/4 */
  76. {
  77. if (channels==1)
  78. for (count=inbufsize/2; count; count--, fromptr+=2)
  79. {
  80. *toptr++ = *fromptr+128;
  81. *toptr++ = *fromptr+128;
  82. *toptr++ = *fromptr+128;
  83. *toptr++ = *fromptr+128;
  84. }
  85. else
  86. for (count=inbufsize/4; count; count--, fromptr+=4)
  87. {
  88. *toptr++ = fromptr[0]+128;
  89. *toptr++ = fromptr[2]+128;
  90. *toptr++ = fromptr[0]+128;
  91. *toptr++ = fromptr[2]+128;
  92. *toptr++ = fromptr[0]+128;
  93. *toptr++ = fromptr[2]+128;
  94. *toptr++ = fromptr[0]+128;
  95. *toptr++ = fromptr[2]+128;
  96. }
  97. return(SlibErrorNone);
  98. }
  99. else if (spsratio==128) /* insps==outsps/2 */
  100. {
  101. if (channels==1)
  102. for (count=inbufsize/2; count; count--, fromptr+=2)
  103. {
  104. *toptr++ = *fromptr+128;
  105. *toptr++ = *fromptr+128;
  106. }
  107. else
  108. for (count=inbufsize/4; count; count--, fromptr+=4)
  109. {
  110. *toptr++ = fromptr[0]+128;
  111. *toptr++ = fromptr[2]+128;
  112. *toptr++ = fromptr[0]+128;
  113. *toptr++ = fromptr[2]+128;
  114. }
  115. return(SlibErrorNone);
  116. }
  117. else if (spsratio==256) /* insps==outsps */
  118. {
  119. for (count=inbufsize/2; count; count--, fromptr+=2)
  120. *toptr++ = *fromptr+128;
  121. return(SlibErrorNone);
  122. }
  123. else if (spsratio==512) /* insps==outsps*2 */
  124. {
  125. if (channels==1)
  126. for (count=inbufsize/4; count; count--, fromptr+=4)
  127. *toptr++ = *fromptr+128;
  128. else
  129. for (count=inbufsize/8; count; count--, fromptr+=8)
  130. {
  131. *toptr++ = fromptr[0]+128;
  132. *toptr++ = fromptr[2]+128;
  133. }
  134. return(SlibErrorNone);
  135. }
  136. }
  137. else if (inbps==8 && outbps==16) /* 8 bit -> 16 bit */
  138. {
  139. unsigned word left, right;
  140. if (spsratio==64) /* insps==outsps/4 */
  141. {
  142. if (channels==1)
  143. for (count=inbufsize; count; count--, fromptr++)
  144. {
  145. left=(*fromptr-128)<<8;
  146. *toptr++ = left&0xFF;
  147. *toptr++ = left>>8;
  148. *toptr++ = left&0xFF;
  149. *toptr++ = left>>8;
  150. *toptr++ = left&0xFF;
  151. *toptr++ = left>>8;
  152. *toptr++ = left&0xFF;
  153. *toptr++ = left>>8;
  154. }
  155. else /* stereo */
  156. for (count=inbufsize/2; count; count--, fromptr+=2)
  157. {
  158. left=(fromptr[0]-128)<<8;
  159. right=(fromptr[1]-128)<<8;
  160. *toptr++ = left&0xFF;
  161. *toptr++ = left>>8;
  162. *toptr++ = right&0xFF;
  163. *toptr++ = right>>8;
  164. *toptr++ = left&0xFF;
  165. *toptr++ = left>>8;
  166. *toptr++ = right&0xFF;
  167. *toptr++ = right>>8;
  168. *toptr++ = left&0xFF;
  169. *toptr++ = left>>8;
  170. *toptr++ = right&0xFF;
  171. *toptr++ = right>>8;
  172. *toptr++ = left&0xFF;
  173. *toptr++ = left>>8;
  174. *toptr++ = right&0xFF;
  175. *toptr++ = right>>8;
  176. }
  177. return(SlibErrorNone);
  178. }
  179. else if (spsratio==128) /* insps==outsps/2 */
  180. {
  181. if (channels==1)
  182. for (count=inbufsize; count; count--, fromptr++)
  183. {
  184. left=(*fromptr-128)<<8;
  185. *toptr++ = left&0xFF;
  186. *toptr++ = left>>8;
  187. *toptr++ = left&0xFF;
  188. *toptr++ = left>>8;
  189. }
  190. else /* stereo */
  191. for (count=inbufsize/2; count; count--, fromptr+=2)
  192. {
  193. left=(fromptr[0]-128)<<8;
  194. right=(fromptr[1]-128)<<8;
  195. *toptr++ = left&0xFF;
  196. *toptr++ = left>>8;
  197. *toptr++ = right&0xFF;
  198. *toptr++ = right>>8;
  199. *toptr++ = left&0xFF;
  200. *toptr++ = left>>8;
  201. *toptr++ = right&0xFF;
  202. *toptr++ = right>>8;
  203. }
  204. return(SlibErrorNone);
  205. }
  206. else if (spsratio==256) /* insps==outsps */
  207. {
  208. if (channels==1)
  209. for (count=inbufsize; count; count--, fromptr++)
  210. {
  211. left=(*fromptr-128)<<8;
  212. *toptr++ = left&0xFF;
  213. *toptr++ = left>>8;
  214. }
  215. else /* stereo */
  216. for (count=inbufsize/2; count; count--, fromptr+=2)
  217. {
  218. left=(fromptr[0]-128)<<8;
  219. right=(fromptr[1]-128)<<8;
  220. *toptr++ = left&0xFF;
  221. *toptr++ = left>>8;
  222. *toptr++ = right&0xFF;
  223. *toptr++ = right>>8;
  224. }
  225. return(SlibErrorNone);
  226. }
  227. else if (spsratio==512) /* insps==outsps*2 */
  228. {
  229. if (channels==1)
  230. for (count=inbufsize/2; count; count--, fromptr+=2)
  231. {
  232. left=(*fromptr-128)<<8;
  233. *toptr++ = left&0xFF;
  234. *toptr++ = left>>8;
  235. }
  236. else /* stereo */
  237. for (count=inbufsize/4; count; count--, fromptr+=4)
  238. {
  239. left=(fromptr[0]-128)<<8;
  240. right=(fromptr[1]-128)<<8;
  241. *toptr++ = left&0xFF;
  242. *toptr++ = left>>8;
  243. *toptr++ = right&0xFF;
  244. *toptr++ = right>>8;
  245. }
  246. return(SlibErrorNone);
  247. }
  248. }
  249. else if (inbps==16 && outbps==16) /* 16 bit -> 16 bit */
  250. {
  251. if (spsratio==64) /* insps==outsps/4 */
  252. {
  253. if (channels==1)
  254. for (count=inbufsize/2; count; count--, fromptr+=2)
  255. {
  256. *toptr++ = fromptr[0];
  257. *toptr++ = fromptr[1];
  258. *toptr++ = fromptr[0];
  259. *toptr++ = fromptr[1];
  260. *toptr++ = fromptr[0];
  261. *toptr++ = fromptr[1];
  262. *toptr++ = fromptr[0];
  263. *toptr++ = fromptr[1];
  264. }
  265. else /* stereo */
  266. for (count=inbufsize/4; count; count--, fromptr+=4)
  267. {
  268. *toptr++ = fromptr[0];
  269. *toptr++ = fromptr[1];
  270. *toptr++ = fromptr[2];
  271. *toptr++ = fromptr[3];
  272. *toptr++ = fromptr[0];
  273. *toptr++ = fromptr[1];
  274. *toptr++ = fromptr[2];
  275. *toptr++ = fromptr[3];
  276. *toptr++ = fromptr[0];
  277. *toptr++ = fromptr[1];
  278. *toptr++ = fromptr[2];
  279. *toptr++ = fromptr[3];
  280. *toptr++ = fromptr[0];
  281. *toptr++ = fromptr[1];
  282. *toptr++ = fromptr[2];
  283. *toptr++ = fromptr[3];
  284. }
  285. return(SlibErrorNone);
  286. }
  287. else if (spsratio==128) /* insps==outsps/2 */
  288. {
  289. if (channels==1)
  290. for (count=inbufsize/2; count; count--, fromptr+=2)
  291. {
  292. *toptr++ = fromptr[0];
  293. *toptr++ = fromptr[1];
  294. *toptr++ = fromptr[0];
  295. *toptr++ = fromptr[1];
  296. }
  297. else /* stereo */
  298. for (count=inbufsize/4; count; count--, fromptr+=4)
  299. {
  300. *toptr++ = fromptr[0];
  301. *toptr++ = fromptr[1];
  302. *toptr++ = fromptr[2];
  303. *toptr++ = fromptr[3];
  304. *toptr++ = fromptr[0];
  305. *toptr++ = fromptr[1];
  306. *toptr++ = fromptr[2];
  307. *toptr++ = fromptr[3];
  308. }
  309. return(SlibErrorNone);
  310. }
  311. else if (spsratio==512) /* insps==outsps*2 */
  312. {
  313. if (channels==1)
  314. for (count=inbufsize/4; count; count--, fromptr+=4)
  315. {
  316. *toptr++ = fromptr[0];
  317. *toptr++ = fromptr[1];
  318. }
  319. else /* stereo */
  320. for (count=inbufsize/8; count; count--, fromptr+=8)
  321. {
  322. *toptr++ = fromptr[0];
  323. *toptr++ = fromptr[1];
  324. *toptr++ = fromptr[2];
  325. *toptr++ = fromptr[3];
  326. }
  327. return(SlibErrorNone);
  328. }
  329. }
  330. else if (inbps==8 && outbps==8) /* 8 bit -> 8 bit */
  331. {
  332. if (spsratio==64) /* insps==outsps/4 */
  333. {
  334. if (channels==1)
  335. for (count=inbufsize; count; count--, fromptr++)
  336. {
  337. *toptr++ = *fromptr;
  338. *toptr++ = *fromptr;
  339. *toptr++ = *fromptr;
  340. *toptr++ = *fromptr;
  341. }
  342. else /* stereo */
  343. for (count=inbufsize/2; count; count--, fromptr+=2)
  344. {
  345. *toptr++ = fromptr[0];
  346. *toptr++ = fromptr[1];
  347. *toptr++ = fromptr[0];
  348. *toptr++ = fromptr[1];
  349. *toptr++ = fromptr[0];
  350. *toptr++ = fromptr[1];
  351. *toptr++ = fromptr[0];
  352. *toptr++ = fromptr[1];
  353. }
  354. return(SlibErrorNone);
  355. }
  356. else if (spsratio==128) /* insps==outsps/2 */
  357. {
  358. if (channels==1)
  359. for (count=inbufsize; count; count--, fromptr++)
  360. {
  361. *toptr++ = *fromptr;
  362. *toptr++ = *fromptr;
  363. }
  364. else /* stereo */
  365. for (count=inbufsize/2; count; count--, fromptr+=2)
  366. {
  367. *toptr++ = fromptr[0];
  368. *toptr++ = fromptr[1];
  369. *toptr++ = fromptr[0];
  370. *toptr++ = fromptr[1];
  371. }
  372. return(SlibErrorNone);
  373. }
  374. else if (spsratio==512) /* insps==outsps*2 */
  375. {
  376. if (channels==1)
  377. for (count=inbufsize/2; count; count--, fromptr+=2)
  378. *toptr++ = *fromptr;
  379. else /* stereo */
  380. for (count=inbufsize/4; count; count--, fromptr+=4)
  381. {
  382. *toptr++ = fromptr[0];
  383. *toptr++ = fromptr[1];
  384. }
  385. return(SlibErrorNone);
  386. }
  387. }
  388. *poutbufsize=0;
  389. return(SlibErrorUnsupportedFormat);
  390. }