jack1 codebase
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.

678 lines
18KB

  1. /*
  2. Copyright (C) 2000 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #define _ISOC9X_SOURCE 1
  16. #define _ISOC99_SOURCE 1
  17. #define __USE_ISOC9X 1
  18. #define __USE_ISOC99 1
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <memory.h>
  23. #include <stdlib.h>
  24. #include <stdint.h>
  25. #include <limits.h>
  26. #include <endian.h>
  27. #include <jack/memops.h>
  28. /* Notes about these *_SCALING values.
  29. the MAX_<N>BIT values are floating point. when multiplied by
  30. a full-scale normalized floating point sample value (-1.0..+1.0)
  31. they should give the maxium value representable with an integer
  32. sample type of N bits. Note that this is asymmetric. Sample ranges
  33. for signed integer, 2's complement values are -(2^(N-1) to +(2^(N-1)-1)
  34. Complications
  35. -------------
  36. If we use +2^(N-1) for the scaling factors, we run into a problem:
  37. if we start with a normalized float value of -1.0, scaling
  38. to 24 bits would give -8388608 (-2^23), which is ideal.
  39. But with +1.0, we get +8388608, which is technically out of range.
  40. We never multiply a full range normalized value by this constant,
  41. but we could multiply it by a positive value that is close enough to +1.0
  42. to produce a value > +(2^(N-1)-1.
  43. There is no way around this paradox without wasting CPU cycles to determine
  44. which scaling factor to use (i.e. determine if its negative or not,
  45. use the right factor).
  46. So, for now (October 2008) we use 2^(N-1)-1 as the scaling factor.
  47. */
  48. #define SAMPLE_24BIT_SCALING 8388607.0f
  49. #define SAMPLE_16BIT_SCALING 32767.0f
  50. /* these are just values to use if the floating point value was out of range
  51. advice from Fons Adriaensen: make the limits symmetrical
  52. */
  53. #define SAMPLE_24BIT_MAX 8388607
  54. #define SAMPLE_24BIT_MIN -8388607
  55. #define SAMPLE_24BIT_MAX_F 8388607.0f
  56. #define SAMPLE_24BIT_MIN_F -8388607.0f
  57. #define SAMPLE_16BIT_MAX 32767
  58. #define SAMPLE_16BIT_MIN -32767
  59. #define SAMPLE_16BIT_MAX_F 32767.0f
  60. #define SAMPLE_16BIT_MIN_F -32767.0f
  61. /* these mark the outer edges of the range considered "within" range
  62. for a floating point sample value. values outside (and on the boundaries)
  63. of this range will be clipped before conversion; values within this
  64. range will be scaled to appropriate values for the target sample
  65. type.
  66. */
  67. #define NORMALIZED_FLOAT_MIN -1.0f
  68. #define NORMALIZED_FLOAT_MAX 1.0f
  69. /* define this in case we end up on a platform that is missing
  70. the real lrintf functions
  71. */
  72. #define f_round(f) lrintf(f)
  73. #define float_16(s, d)\
  74. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  75. (d) = SAMPLE_16BIT_MIN;\
  76. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  77. (d) = SAMPLE_16BIT_MAX;\
  78. } else {\
  79. (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
  80. }
  81. /* call this when "s" has already been scaled (e.g. when dithering)
  82. */
  83. #define float_16_scaled(s, d)\
  84. if ((s) <= SAMPLE_16BIT_MIN_F) {\
  85. (d) = SAMPLE_16BIT_MIN_F;\
  86. } else if ((s) >= SAMPLE_16BIT_MAX_F) { \
  87. (d) = SAMPLE_16BIT_MAX;\
  88. } else {\
  89. (d) = f_round ((s));\
  90. }
  91. #define float_24u32(s, d) \
  92. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  93. (d) = SAMPLE_24BIT_MIN << 8;\
  94. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  95. (d) = SAMPLE_24BIT_MAX << 8;\
  96. } else {\
  97. (d) = f_round ((s) * SAMPLE_24BIT_SCALING) << 8;\
  98. }
  99. /* call this when "s" has already been scaled (e.g. when dithering)
  100. */
  101. #define float_24u32_scaled(s, d)\
  102. if ((s) <= SAMPLE_24BIT_MIN_F) {\
  103. (d) = SAMPLE_24BIT_MIN << 8;\
  104. } else if ((s) >= SAMPLE_24BIT_MAX_F) { \
  105. (d) = SAMPLE_24BIT_MAX << 8; \
  106. } else {\
  107. (d) = f_round ((s)) << 8; \
  108. }
  109. #define float_24(s, d) \
  110. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  111. (d) = SAMPLE_24BIT_MIN;\
  112. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  113. (d) = SAMPLE_24BIT_MAX;\
  114. } else {\
  115. (d) = f_round ((s) * SAMPLE_24BIT_SCALING);\
  116. }
  117. /* call this when "s" has already been scaled (e.g. when dithering)
  118. */
  119. #define float_24_scaled(s, d)\
  120. if ((s) <= SAMPLE_24BIT_MIN_F) {\
  121. (d) = SAMPLE_24BIT_MIN;\
  122. } else if ((s) >= SAMPLE_24BIT_MAX_F) { \
  123. (d) = SAMPLE_24BIT_MAX; \
  124. } else {\
  125. (d) = f_round ((s)); \
  126. }
  127. /* Linear Congruential noise generator. From the music-dsp list
  128. * less random than rand(), but good enough and 10x faster
  129. */
  130. inline unsigned int fast_rand() {
  131. static unsigned int seed = 22222;
  132. seed = (seed * 96314165) + 907633515;
  133. return seed;
  134. }
  135. /* functions for native float sample data */
  136. void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) {
  137. while (nsamples--) {
  138. *dst = *((float *) src);
  139. dst++;
  140. src += src_skip;
  141. }
  142. }
  143. void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) {
  144. while (nsamples--) {
  145. *((float *) dst) = *src;
  146. dst += dst_skip;
  147. src++;
  148. }
  149. }
  150. /* NOTES on function naming:
  151. foo_bar_d<TYPE>_s<TYPE>
  152. the "d<TYPE>" component defines the destination type for the operation
  153. the "s<TYPE>" component defines the source type for the operation
  154. TYPE can be one of:
  155. S - sample is a jack_default_audio_sample_t, currently (October 2008) a 32 bit floating point value
  156. Ss - like S but reverse endian from the host CPU
  157. 32u24 - sample is an signed 32 bit integer value, but data is in upper 24 bits only
  158. 32u24s - like 32u24 but reverse endian from the host CPU
  159. 24 - sample is an signed 24 bit integer value
  160. 24s - like 24 but reverse endian from the host CPU
  161. 16 - sample is an signed 16 bit integer value
  162. 16s - like 16 but reverse endian from the host CPU
  163. For obvious reasons, the reverse endian versions only show as source types.
  164. This covers all known sample formats at 16 bits or larger.
  165. */
  166. /* functions for native integer sample data */
  167. void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  168. {
  169. int32_t z;
  170. while (nsamples--) {
  171. float_24u32 (*src, z);
  172. #if __BYTE_ORDER == __LITTLE_ENDIAN
  173. dst[0]=(char)(z>>24);
  174. dst[1]=(char)(z>>16);
  175. dst[2]=(char)(z>>8);
  176. dst[3]=(char)(z);
  177. #elif __BYTE_ORDER == __BIG_ENDIAN
  178. dst[0]=(char)(z);
  179. dst[1]=(char)(z>>8);
  180. dst[2]=(char)(z>>16);
  181. dst[3]=(char)(z>>24);
  182. #endif
  183. dst += dst_skip;
  184. src++;
  185. }
  186. }
  187. void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  188. {
  189. while (nsamples--) {
  190. float_24u32 (*src, *((int32_t*) dst));
  191. dst += dst_skip;
  192. src++;
  193. }
  194. }
  195. void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  196. {
  197. /* ALERT: signed sign-extension portability !!! */
  198. while (nsamples--) {
  199. int x;
  200. #if __BYTE_ORDER == __LITTLE_ENDIAN
  201. x = (unsigned char)(src[0]);
  202. x <<= 8;
  203. x |= (unsigned char)(src[1]);
  204. x <<= 8;
  205. x |= (unsigned char)(src[2]);
  206. x <<= 8;
  207. x |= (unsigned char)(src[3]);
  208. #elif __BYTE_ORDER == __BIG_ENDIAN
  209. x = (unsigned char)(src[3]);
  210. x <<= 8;
  211. x |= (unsigned char)(src[2]);
  212. x <<= 8;
  213. x |= (unsigned char)(src[1]);
  214. x <<= 8;
  215. x |= (unsigned char)(src[0]);
  216. #endif
  217. *dst = (x >> 8) / SAMPLE_24BIT_SCALING;
  218. dst++;
  219. src += src_skip;
  220. }
  221. }
  222. void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  223. {
  224. /* ALERT: signed sign-extension portability !!! */
  225. while (nsamples--) {
  226. *dst = (*((int *) src) >> 8) / SAMPLE_24BIT_SCALING;
  227. dst++;
  228. src += src_skip;
  229. }
  230. }
  231. void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  232. {
  233. int32_t z;
  234. while (nsamples--) {
  235. float_24 (*src, z);
  236. #if __BYTE_ORDER == __LITTLE_ENDIAN
  237. dst[0]=(char)(z>>16);
  238. dst[1]=(char)(z>>8);
  239. dst[2]=(char)(z);
  240. #elif __BYTE_ORDER == __BIG_ENDIAN
  241. dst[0]=(char)(z);
  242. dst[1]=(char)(z>>8);
  243. dst[2]=(char)(z>>16);
  244. #endif
  245. dst += dst_skip;
  246. src++;
  247. }
  248. }
  249. void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  250. {
  251. int32_t z;
  252. while (nsamples--) {
  253. float_24 (*src, z);
  254. #if __BYTE_ORDER == __LITTLE_ENDIAN
  255. memcpy (dst, &z, 3);
  256. #elif __BYTE_ORDER == __BIG_ENDIAN
  257. memcpy (dst, (char *)&z + 1, 3);
  258. #endif
  259. dst += dst_skip;
  260. src++;
  261. }
  262. }
  263. void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  264. {
  265. /* ALERT: signed sign-extension portability !!! */
  266. while (nsamples--) {
  267. int x;
  268. #if __BYTE_ORDER == __LITTLE_ENDIAN
  269. x = (unsigned char)(src[0]);
  270. x <<= 8;
  271. x |= (unsigned char)(src[1]);
  272. x <<= 8;
  273. x |= (unsigned char)(src[2]);
  274. /* correct sign bit and the rest of the top byte */
  275. if (src[0] & 0x80) {
  276. x |= 0xff << 24;
  277. }
  278. #elif __BYTE_ORDER == __BIG_ENDIAN
  279. x = (unsigned char)(src[2]);
  280. x <<= 8;
  281. x |= (unsigned char)(src[1]);
  282. x <<= 8;
  283. x |= (unsigned char)(src[0]);
  284. /* correct sign bit and the rest of the top byte */
  285. if (src[0] & 0x80) {
  286. x |= 0xff << 24;
  287. }
  288. #endif
  289. *dst = x / SAMPLE_24BIT_SCALING;
  290. dst++;
  291. src += src_skip;
  292. }
  293. }
  294. void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  295. {
  296. /* ALERT: signed sign-extension portability !!! */
  297. while (nsamples--) {
  298. int x;
  299. #if __BYTE_ORDER == __LITTLE_ENDIAN
  300. memcpy((char*)&x + 1, src, 3);
  301. #elif __BYTE_ORDER == __BIG_ENDIAN
  302. memcpy(&x, src, 3);
  303. #endif
  304. x >>= 8;
  305. *dst = x / SAMPLE_24BIT_SCALING;
  306. dst++;
  307. src += src_skip;
  308. }
  309. }
  310. void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  311. {
  312. int16_t tmp;
  313. while (nsamples--) {
  314. // float_16 (*src, tmp);
  315. if (*src <= NORMALIZED_FLOAT_MIN) {
  316. tmp = SAMPLE_16BIT_MIN;
  317. } else if (*src >= NORMALIZED_FLOAT_MAX) {
  318. tmp = SAMPLE_16BIT_MAX;
  319. } else {
  320. tmp = (int16_t) f_round (*src * SAMPLE_16BIT_SCALING);
  321. }
  322. #if __BYTE_ORDER == __LITTLE_ENDIAN
  323. dst[0]=(char)(tmp>>8);
  324. dst[1]=(char)(tmp);
  325. #elif __BYTE_ORDER == __BIG_ENDIAN
  326. dst[0]=(char)(tmp);
  327. dst[1]=(char)(tmp>>8);
  328. #endif
  329. dst += dst_skip;
  330. src++;
  331. }
  332. }
  333. void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  334. {
  335. while (nsamples--) {
  336. float_16 (*src, *((int16_t*) dst));
  337. dst += dst_skip;
  338. src++;
  339. }
  340. }
  341. void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  342. {
  343. jack_default_audio_sample_t val;
  344. int16_t tmp;
  345. while (nsamples--) {
  346. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float) UINT_MAX - 0.5f;
  347. float_16_scaled (val, tmp);
  348. #if __BYTE_ORDER == __LITTLE_ENDIAN
  349. dst[0]=(char)(tmp>>8);
  350. dst[1]=(char)(tmp);
  351. #elif __BYTE_ORDER == __BIG_ENDIAN
  352. dst[0]=(char)(tmp);
  353. dst[1]=(char)(tmp>>8);
  354. #endif
  355. dst += dst_skip;
  356. src++;
  357. }
  358. }
  359. void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  360. {
  361. jack_default_audio_sample_t val;
  362. while (nsamples--) {
  363. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float)UINT_MAX - 0.5f;
  364. float_16_scaled (val, *((int16_t*) dst));
  365. dst += dst_skip;
  366. src++;
  367. }
  368. }
  369. void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  370. {
  371. jack_default_audio_sample_t val;
  372. int16_t tmp;
  373. while (nsamples--) {
  374. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  375. float_16_scaled (val, tmp);
  376. #if __BYTE_ORDER == __LITTLE_ENDIAN
  377. dst[0]=(char)(tmp>>8);
  378. dst[1]=(char)(tmp);
  379. #elif __BYTE_ORDER == __BIG_ENDIAN
  380. dst[0]=(char)(tmp);
  381. dst[1]=(char)(tmp>>8);
  382. #endif
  383. dst += dst_skip;
  384. src++;
  385. }
  386. }
  387. void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  388. {
  389. jack_default_audio_sample_t val;
  390. while (nsamples--) {
  391. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  392. float_16_scaled (val, *((int16_t*) dst));
  393. dst += dst_skip;
  394. src++;
  395. }
  396. }
  397. void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  398. {
  399. jack_default_audio_sample_t x;
  400. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  401. jack_default_audio_sample_t xp; /* x' */
  402. float r;
  403. float rm1 = state->rm1;
  404. unsigned int idx = state->idx;
  405. int16_t tmp;
  406. while (nsamples--) {
  407. x = *src * SAMPLE_16BIT_SCALING;
  408. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  409. /* Filter the error with Lipshitz's minimally audible FIR:
  410. [2.033 -2.165 1.959 -1.590 0.6149] */
  411. xe = x
  412. - state->e[idx] * 2.033f
  413. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  414. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  415. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  416. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  417. xp = xe + r - rm1;
  418. rm1 = r;
  419. float_16_scaled (xp, tmp);
  420. /* Intrinsic z^-1 delay */
  421. idx = (idx + 1) & DITHER_BUF_MASK;
  422. state->e[idx] = xp - xe;
  423. #if __BYTE_ORDER == __LITTLE_ENDIAN
  424. dst[0]=(char)(tmp>>8);
  425. dst[1]=(char)(tmp);
  426. #elif __BYTE_ORDER == __BIG_ENDIAN
  427. dst[0]=(char)(tmp);
  428. dst[1]=(char)(tmp>>8);
  429. #endif
  430. dst += dst_skip;
  431. src++;
  432. }
  433. state->rm1 = rm1;
  434. state->idx = idx;
  435. }
  436. void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  437. {
  438. jack_default_audio_sample_t x;
  439. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  440. jack_default_audio_sample_t xp; /* x' */
  441. float r;
  442. float rm1 = state->rm1;
  443. unsigned int idx = state->idx;
  444. while (nsamples--) {
  445. x = *src * SAMPLE_16BIT_SCALING;
  446. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  447. /* Filter the error with Lipshitz's minimally audible FIR:
  448. [2.033 -2.165 1.959 -1.590 0.6149] */
  449. xe = x
  450. - state->e[idx] * 2.033f
  451. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  452. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  453. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  454. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  455. xp = xe + r - rm1;
  456. rm1 = r;
  457. float_16_scaled (xp, *((int16_t*) dst));
  458. /* Intrinsic z^-1 delay */
  459. idx = (idx + 1) & DITHER_BUF_MASK;
  460. state->e[idx] = *((int16_t*) dst) - xe;
  461. dst += dst_skip;
  462. src++;
  463. }
  464. state->rm1 = rm1;
  465. state->idx = idx;
  466. }
  467. void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  468. {
  469. short z;
  470. /* ALERT: signed sign-extension portability !!! */
  471. while (nsamples--) {
  472. #if __BYTE_ORDER == __LITTLE_ENDIAN
  473. z = (unsigned char)(src[0]);
  474. z <<= 8;
  475. z |= (unsigned char)(src[1]);
  476. #elif __BYTE_ORDER == __BIG_ENDIAN
  477. z = (unsigned char)(src[1]);
  478. z <<= 8;
  479. z |= (unsigned char)(src[0]);
  480. #endif
  481. *dst = z / SAMPLE_16BIT_SCALING;
  482. dst++;
  483. src += src_skip;
  484. }
  485. }
  486. void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  487. {
  488. /* ALERT: signed sign-extension portability !!! */
  489. while (nsamples--) {
  490. *dst = (*((short *) src)) / SAMPLE_16BIT_SCALING;
  491. dst++;
  492. src += src_skip;
  493. }
  494. }
  495. void memset_interleave (char *dst, char val, unsigned long bytes,
  496. unsigned long unit_bytes,
  497. unsigned long skip_bytes)
  498. {
  499. switch (unit_bytes) {
  500. case 1:
  501. while (bytes--) {
  502. *dst = val;
  503. dst += skip_bytes;
  504. }
  505. break;
  506. case 2:
  507. while (bytes) {
  508. *((short *) dst) = (short) val;
  509. dst += skip_bytes;
  510. bytes -= 2;
  511. }
  512. break;
  513. case 4:
  514. while (bytes) {
  515. *((int *) dst) = (int) val;
  516. dst += skip_bytes;
  517. bytes -= 4;
  518. }
  519. break;
  520. default:
  521. while (bytes) {
  522. memset(dst, val, unit_bytes);
  523. dst += skip_bytes;
  524. bytes -= unit_bytes;
  525. }
  526. break;
  527. }
  528. }
  529. /* COPY FUNCTIONS: used to move data from an input channel to an
  530. output channel. Note that we assume that the skip distance
  531. is the same for both channels. This is completely fine
  532. unless the input and output were on different audio interfaces that
  533. were interleaved differently. We don't try to handle that.
  534. */
  535. void
  536. memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
  537. {
  538. memcpy (dst, src, src_bytes);
  539. }
  540. void
  541. memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  542. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  543. {
  544. while (src_bytes) {
  545. *((short *) dst) = *((short *) src);
  546. dst += dst_skip_bytes;
  547. src += src_skip_bytes;
  548. src_bytes -= 2;
  549. }
  550. }
  551. void
  552. memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes,
  553. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  554. {
  555. while (src_bytes) {
  556. memcpy(dst, src, 3);
  557. dst += dst_skip_bytes;
  558. src += src_skip_bytes;
  559. src_bytes -= 3;
  560. }
  561. }
  562. void
  563. memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  564. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  565. {
  566. while (src_bytes) {
  567. *((int *) dst) = *((int *) src);
  568. dst += dst_skip_bytes;
  569. src += src_skip_bytes;
  570. src_bytes -= 4;
  571. }
  572. }