jack2 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.

1232 lines
34KB

  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 <stdbool.h>
  26. #include <limits.h>
  27. #ifdef __linux__
  28. #include <endian.h>
  29. #endif
  30. #include "memops.h"
  31. #if defined (__SSE2__) && !defined (__sun__)
  32. #include <emmintrin.h>
  33. #ifdef __SSE4_1__
  34. #include <smmintrin.h>
  35. #endif
  36. #endif
  37. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  38. #include <arm_neon.h>
  39. #endif
  40. /* Notes about these *_SCALING values.
  41. the MAX_<N>BIT values are floating point. when multiplied by
  42. a full-scale normalized floating point sample value (-1.0..+1.0)
  43. they should give the maxium value representable with an integer
  44. sample type of N bits. Note that this is asymmetric. Sample ranges
  45. for signed integer, 2's complement values are -(2^(N-1) to +(2^(N-1)-1)
  46. Complications
  47. -------------
  48. If we use +2^(N-1) for the scaling factors, we run into a problem:
  49. if we start with a normalized float value of -1.0, scaling
  50. to 24 bits would give -8388608 (-2^23), which is ideal.
  51. But with +1.0, we get +8388608, which is technically out of range.
  52. We never multiply a full range normalized value by this constant,
  53. but we could multiply it by a positive value that is close enough to +1.0
  54. to produce a value > +(2^(N-1)-1.
  55. There is no way around this paradox without wasting CPU cycles to determine
  56. which scaling factor to use (i.e. determine if its negative or not,
  57. use the right factor).
  58. So, for now (October 2008) we use 2^(N-1)-1 as the scaling factor.
  59. */
  60. #define SAMPLE_32BIT_SCALING 0x7FFFFFFF
  61. #define SAMPLE_24BIT_SCALING 8388607
  62. #define SAMPLE_16BIT_SCALING 32767
  63. /* these are just values to use if the floating point value was out of range
  64. advice from Fons Adriaensen: make the limits symmetrical
  65. */
  66. #define SAMPLE_24BIT_MAX 8388607
  67. #define SAMPLE_24BIT_MIN -8388607
  68. #define SAMPLE_16BIT_MAX 32767
  69. #define SAMPLE_16BIT_MIN -32767
  70. #define SAMPLE_16BIT_MAX_F 32767.0f
  71. #define SAMPLE_16BIT_MIN_F -32767.0f
  72. /* these mark the outer edges of the range considered "within" range
  73. for a floating point sample value. values outside (and on the boundaries)
  74. of this range will be clipped before conversion; values within this
  75. range will be scaled to appropriate values for the target sample
  76. type.
  77. */
  78. #define NORMALIZED_FLOAT_MIN -1.0f
  79. #define NORMALIZED_FLOAT_MAX 1.0f
  80. /* define this in case we end up on a platform that is missing
  81. the real lrintf functions
  82. */
  83. #define f_round(f) lrintf(f)
  84. #define float_16(s, d)\
  85. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  86. (d) = SAMPLE_16BIT_MIN;\
  87. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  88. (d) = SAMPLE_16BIT_MAX;\
  89. } else {\
  90. (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
  91. }
  92. /* call this when "s" has already been scaled (e.g. when dithering)
  93. */
  94. #define float_16_scaled(s, d)\
  95. if ((s) <= SAMPLE_16BIT_MIN_F) {\
  96. (d) = SAMPLE_16BIT_MIN_F;\
  97. } else if ((s) >= SAMPLE_16BIT_MAX_F) { \
  98. (d) = SAMPLE_16BIT_MAX;\
  99. } else {\
  100. (d) = f_round ((s));\
  101. }
  102. #define float_32(s, d, scale) \
  103. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  104. (d) = -scale;\
  105. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  106. (d) = scale;\
  107. } else {\
  108. (d) = f_round ((s) * scale);\
  109. }
  110. #define float_24(s, d) \
  111. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  112. (d) = SAMPLE_24BIT_MIN;\
  113. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  114. (d) = SAMPLE_24BIT_MAX;\
  115. } else {\
  116. (d) = f_round ((s) * SAMPLE_24BIT_SCALING);\
  117. }
  118. #if defined (__SSE2__) && !defined (__sun__)
  119. /* generates same as _mm_set_ps(1.f, 1.f, 1f., 1f) but faster */
  120. static inline __m128 gen_one(void)
  121. {
  122. volatile __m128i x = { 0 }; /* shut up, GCC */
  123. __m128i ones = _mm_cmpeq_epi32(x, x);
  124. return (__m128)_mm_slli_epi32 (_mm_srli_epi32(ones, 25), 23);
  125. }
  126. static inline __m128 clip(__m128 s, __m128 min, __m128 max)
  127. {
  128. return _mm_min_ps(max, _mm_max_ps(s, min));
  129. }
  130. static inline __m128i float_24_sse(__m128 s)
  131. {
  132. const __m128 upper_bound = gen_one(); /* NORMALIZED_FLOAT_MAX */
  133. const __m128 lower_bound = _mm_sub_ps(_mm_setzero_ps(), upper_bound);
  134. __m128 clipped = clip(s, lower_bound, upper_bound);
  135. __m128 scaled = _mm_mul_ps(clipped, _mm_set1_ps(SAMPLE_24BIT_SCALING));
  136. return _mm_cvtps_epi32(scaled);
  137. }
  138. #endif
  139. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  140. static inline float32x4_t clip(float32x4_t s, float32x4_t min, float32x4_t max)
  141. {
  142. return vminq_f32(max, vmaxq_f32(s, min));
  143. }
  144. static inline int32x4_t float_32_neon(float32x4_t s, const int32_t scaling)
  145. {
  146. const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX);
  147. const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN);
  148. float32x4_t clipped = clip(s, lower_bound, upper_bound);
  149. float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(scaling));
  150. return vcvtq_s32_f32(scaled);
  151. }
  152. static inline int16x4_t float_16_neon(float32x4_t s)
  153. {
  154. const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX);
  155. const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN);
  156. float32x4_t clipped = clip(s, lower_bound, upper_bound);
  157. float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(SAMPLE_16BIT_SCALING));
  158. return vmovn_s32(vcvtq_s32_f32(scaled));
  159. }
  160. #endif
  161. /* Linear Congruential noise generator. From the music-dsp list
  162. * less random than rand(), but good enough and 10x faster
  163. */
  164. static unsigned int seed = 22222;
  165. static inline unsigned int fast_rand() {
  166. seed = (seed * 196314165) + 907633515;
  167. return seed;
  168. }
  169. /* functions for native float sample data */
  170. void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) {
  171. while (nsamples--) {
  172. *dst = *((float *) src);
  173. dst++;
  174. src += src_skip;
  175. }
  176. }
  177. void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) {
  178. while (nsamples--) {
  179. *((float *) dst) = *src;
  180. dst += dst_skip;
  181. src++;
  182. }
  183. }
  184. /* NOTES on function naming:
  185. foo_bar_d<TYPE>_s<TYPE>
  186. the "d<TYPE>" component defines the destination type for the operation
  187. the "s<TYPE>" component defines the source type for the operation
  188. TYPE can be one of:
  189. S - sample is a jack_default_audio_sample_t, currently (October 2008) a 32 bit floating point value
  190. Ss - like S but reverse endian from the host CPU
  191. 32 - sample is an signed 32 bit integer value
  192. 32s - like 32 but reverse endian from the host CPU
  193. 32u24 - sample is an signed 32 bit integer value, but data is in lower 24 bits only
  194. 32u24s - like 32u24 but reverse endian from the host CPU
  195. 24 - sample is an signed 24 bit integer value
  196. 24s - like 24 but reverse endian from the host CPU
  197. 16 - sample is an signed 16 bit integer value
  198. 16s - like 16 but reverse endian from the host CPU
  199. For obvious reasons, the reverse endian versions only show as source types.
  200. This covers all known sample formats at 16 bits or larger.
  201. */
  202. /* functions for native integer sample data */
  203. static inline void sample_move_d32scal_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state, const int32_t scaling)
  204. {
  205. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  206. unsigned long unrolled = nsamples / 4;
  207. nsamples = nsamples & 3;
  208. while (unrolled--) {
  209. float32x4_t samples = vld1q_f32(src);
  210. int32x4_t converted = float_32_neon(samples, scaling);
  211. converted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(converted)));
  212. switch(dst_skip) {
  213. case 4:
  214. vst1q_s32((int32_t*)dst, converted);
  215. break;
  216. default:
  217. vst1q_lane_s32((int32_t*)(dst), converted, 0);
  218. vst1q_lane_s32((int32_t*)(dst+dst_skip), converted, 1);
  219. vst1q_lane_s32((int32_t*)(dst+2*dst_skip), converted, 2);
  220. vst1q_lane_s32((int32_t*)(dst+3*dst_skip), converted, 3);
  221. break;
  222. }
  223. dst += 4*dst_skip;
  224. src+= 4;
  225. }
  226. #endif
  227. int32_t z;
  228. while (nsamples--) {
  229. float_32 (*src, z, scaling);
  230. #if __BYTE_ORDER == __LITTLE_ENDIAN
  231. dst[0]=(char)(z>>24);
  232. dst[1]=(char)(z>>16);
  233. dst[2]=(char)(z>>8);
  234. dst[3]=(char)(z);
  235. #elif __BYTE_ORDER == __BIG_ENDIAN
  236. dst[0]=(char)(z);
  237. dst[1]=(char)(z>>8);
  238. dst[2]=(char)(z>>16);
  239. dst[3]=(char)(z>>24);
  240. #endif
  241. dst += dst_skip;
  242. src++;
  243. }
  244. }
  245. void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  246. {
  247. sample_move_d32scal_sSs (dst, src, nsamples, dst_skip, state, SAMPLE_24BIT_SCALING);
  248. }
  249. void sample_move_d32_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  250. {
  251. sample_move_d32scal_sSs (dst, src, nsamples, dst_skip, state, SAMPLE_32BIT_SCALING);
  252. }
  253. static inline void sample_move_d32scal_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state, const int32_t scaling)
  254. {
  255. #if defined (__SSE2__) && !defined (__sun__)
  256. __m128 int_max = _mm_set1_ps(scaling);
  257. __m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
  258. __m128 factor = int_max;
  259. unsigned long unrolled = nsamples / 4;
  260. nsamples = nsamples & 3;
  261. while (unrolled--) {
  262. __m128 in = _mm_load_ps(src);
  263. __m128 scaled = _mm_mul_ps(in, factor);
  264. __m128 clipped = clip(scaled, int_min, int_max);
  265. __m128i y = _mm_cvttps_epi32(clipped);
  266. #ifdef __SSE4_1__
  267. *(int32_t*)dst = _mm_extract_epi32(y, 0);
  268. *(int32_t*)(dst+dst_skip) = _mm_extract_epi32(y, 1);
  269. *(int32_t*)(dst+2*dst_skip) = _mm_extract_epi32(y, 2);
  270. *(int32_t*)(dst+3*dst_skip) = _mm_extract_epi32(y, 3);
  271. #else
  272. __m128i shuffled1 = _mm_shuffle_epi32(y, _MM_SHUFFLE(0, 3, 2, 1));
  273. __m128i shuffled2 = _mm_shuffle_epi32(y, _MM_SHUFFLE(1, 0, 3, 2));
  274. __m128i shuffled3 = _mm_shuffle_epi32(y, _MM_SHUFFLE(2, 1, 0, 3));
  275. _mm_store_ss((float*)dst, (__m128)y);
  276. _mm_store_ss((float*)(dst+dst_skip), (__m128)shuffled1);
  277. _mm_store_ss((float*)(dst+2*dst_skip), (__m128)shuffled2);
  278. _mm_store_ss((float*)(dst+3*dst_skip), (__m128)shuffled3);
  279. #endif
  280. dst += 4*dst_skip;
  281. src+= 4;
  282. }
  283. while (nsamples--) {
  284. __m128 in = _mm_load_ss(src);
  285. __m128 scaled = _mm_mul_ss(in, factor);
  286. __m128 clipped = _mm_min_ss(int_max, _mm_max_ss(scaled, int_min));
  287. int y = _mm_cvttss_si32(clipped);
  288. *((int *) dst) = y;
  289. dst += dst_skip;
  290. src++;
  291. }
  292. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  293. unsigned long unrolled = nsamples / 4;
  294. nsamples = nsamples & 3;
  295. while (unrolled--) {
  296. float32x4_t samples = vld1q_f32(src);
  297. int32x4_t converted = float_32_neon(samples, scaling);
  298. switch(dst_skip) {
  299. case 4:
  300. vst1q_s32((int32_t*)dst, converted);
  301. break;
  302. default:
  303. vst1q_lane_s32((int32_t*)(dst), converted, 0);
  304. vst1q_lane_s32((int32_t*)(dst+dst_skip), converted, 1);
  305. vst1q_lane_s32((int32_t*)(dst+2*dst_skip), converted, 2);
  306. vst1q_lane_s32((int32_t*)(dst+3*dst_skip), converted, 3);
  307. break;
  308. }
  309. dst += 4*dst_skip;
  310. src+= 4;
  311. }
  312. #endif
  313. #if !defined (__SSE2__)
  314. while (nsamples--) {
  315. float_32 (*src, *((int32_t*) dst), scaling);
  316. dst += dst_skip;
  317. src++;
  318. }
  319. #endif
  320. }
  321. void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  322. {
  323. sample_move_d32scal_sS (dst, src, nsamples, dst_skip, state, SAMPLE_24BIT_SCALING);
  324. }
  325. void sample_move_d32_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  326. {
  327. sample_move_d32scal_sS (dst, src, nsamples, dst_skip, state, SAMPLE_32BIT_SCALING);
  328. }
  329. static inline void sample_move_dS_s32s_signext (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip, const bool do_signext)
  330. {
  331. const jack_default_audio_sample_t scaling_divisor = do_signext ? (SAMPLE_24BIT_SCALING << 8) : SAMPLE_32BIT_SCALING;
  332. const jack_default_audio_sample_t scaling = 1.0 / scaling_divisor;
  333. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  334. float32x4_t factor = vdupq_n_f32(scaling);
  335. unsigned long unrolled = nsamples / 4;
  336. while (unrolled--) {
  337. int32x4_t src128;
  338. switch(src_skip)
  339. {
  340. case 4:
  341. src128 = vld1q_s32((int32_t*)src);
  342. break;
  343. case 8:
  344. src128 = vld2q_s32((int32_t*)src).val[0];
  345. break;
  346. default:
  347. src128 = vld1q_lane_s32((int32_t*)src, src128, 0);
  348. src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1);
  349. src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2);
  350. src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3);
  351. break;
  352. }
  353. src128 = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(src128)));
  354. if (do_signext) {
  355. /* sign extension - left shift will be reverted by scaling */
  356. src128 = vshlq_n_s32(src128, 8);
  357. }
  358. float32x4_t as_float = vcvtq_f32_s32(src128);
  359. float32x4_t divided = vmulq_f32(as_float, factor);
  360. vst1q_f32(dst, divided);
  361. src += 4*src_skip;
  362. dst += 4;
  363. }
  364. nsamples = nsamples & 3;
  365. #endif
  366. /* ALERT: signed sign-extension portability !!! */
  367. while (nsamples--) {
  368. int x;
  369. #if __BYTE_ORDER == __LITTLE_ENDIAN
  370. x = (unsigned char)(src[0]);
  371. x <<= 8;
  372. x |= (unsigned char)(src[1]);
  373. x <<= 8;
  374. x |= (unsigned char)(src[2]);
  375. x <<= 8;
  376. x |= (unsigned char)(src[3]);
  377. #elif __BYTE_ORDER == __BIG_ENDIAN
  378. x = (unsigned char)(src[3]);
  379. x <<= 8;
  380. x |= (unsigned char)(src[2]);
  381. x <<= 8;
  382. x |= (unsigned char)(src[1]);
  383. x <<= 8;
  384. x |= (unsigned char)(src[0]);
  385. #endif
  386. if (do_signext) {
  387. /* sign extension - left shift will be reverted by scaling */
  388. x <<= 8;
  389. }
  390. *dst = x * scaling;
  391. dst++;
  392. src += src_skip;
  393. }
  394. }
  395. void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  396. {
  397. sample_move_dS_s32s_signext (dst, src, nsamples, src_skip, true);
  398. }
  399. void sample_move_dS_s32s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  400. {
  401. sample_move_dS_s32s_signext (dst, src, nsamples, src_skip, false);
  402. }
  403. static inline void sample_move_dS_s32_signext (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip, const bool do_signext)
  404. {
  405. const jack_default_audio_sample_t scaling_divisor = do_signext ? (SAMPLE_24BIT_SCALING << 8) : SAMPLE_32BIT_SCALING;
  406. const jack_default_audio_sample_t scaling = 1.0 / scaling_divisor;
  407. #if defined (__SSE2__) && !defined (__sun__)
  408. unsigned long unrolled = nsamples / 4;
  409. __m128 factor = _mm_set1_ps(scaling);
  410. while (unrolled--)
  411. {
  412. int i1 = *((int *) src);
  413. src+= src_skip;
  414. int i2 = *((int *) src);
  415. src+= src_skip;
  416. int i3 = *((int *) src);
  417. src+= src_skip;
  418. int i4 = *((int *) src);
  419. src+= src_skip;
  420. __m128i src128 = _mm_set_epi32(i4, i3, i2, i1);
  421. if (do_signext) {
  422. /* sign extension - left shift will be reverted by scaling */
  423. src128 = _mm_slli_epi32(src128, 8);
  424. }
  425. __m128 as_float = _mm_cvtepi32_ps(src128);
  426. __m128 divided = _mm_mul_ps(as_float, factor);
  427. _mm_storeu_ps(dst, divided);
  428. dst += 4;
  429. }
  430. nsamples = nsamples & 3;
  431. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  432. unsigned long unrolled = nsamples / 4;
  433. float32x4_t factor = vdupq_n_f32(scaling);
  434. while (unrolled--) {
  435. int32x4_t src128;
  436. switch(src_skip) {
  437. case 4:
  438. src128 = vld1q_s32((int32_t*)src);
  439. break;
  440. case 8:
  441. src128 = vld2q_s32((int32_t*)src).val[0];
  442. break;
  443. default:
  444. src128 = vld1q_lane_s32((int32_t*)src, src128, 0);
  445. src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1);
  446. src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2);
  447. src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3);
  448. break;
  449. }
  450. if (do_signext) {
  451. /* sign extension - left shift will be reverted by scaling */
  452. src128 = vshlq_n_s32(src128, 8);
  453. }
  454. float32x4_t as_float = vcvtq_f32_s32(src128);
  455. float32x4_t divided = vmulq_f32(as_float, factor);
  456. vst1q_f32(dst, divided);
  457. src += 4*src_skip;
  458. dst += 4;
  459. }
  460. nsamples = nsamples & 3;
  461. #endif
  462. /* ALERT: signed sign-extension portability !!! */
  463. while (nsamples--) {
  464. int src32 = *((int *) src);
  465. if (do_signext) {
  466. /* sign extension - left shift will be reverted by scaling */
  467. src32 <<= 8;
  468. }
  469. *dst = src32 * scaling;
  470. dst++;
  471. src += src_skip;
  472. }
  473. }
  474. void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  475. {
  476. sample_move_dS_s32_signext (dst, src, nsamples, src_skip, true);
  477. }
  478. void sample_move_dS_s32 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  479. {
  480. sample_move_dS_s32_signext (dst, src, nsamples, src_skip, false);
  481. }
  482. void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  483. {
  484. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  485. unsigned long unrolled = nsamples / 4;
  486. while (unrolled--) {
  487. int i;
  488. int32_t z[4];
  489. float32x4_t samples = vld1q_f32(src);
  490. int32x4_t converted = float_32_neon(samples, SAMPLE_24BIT_SCALING);
  491. converted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(converted)));
  492. vst1q_s32(z, converted);
  493. for (i = 0; i != 4; ++i) {
  494. memcpy (dst, ((char*)(z+i))+1, 3);
  495. dst += dst_skip;
  496. }
  497. src += 4;
  498. }
  499. nsamples = nsamples & 3;
  500. #endif
  501. int32_t z;
  502. while (nsamples--) {
  503. float_24 (*src, z);
  504. #if __BYTE_ORDER == __LITTLE_ENDIAN
  505. dst[0]=(char)(z>>16);
  506. dst[1]=(char)(z>>8);
  507. dst[2]=(char)(z);
  508. #elif __BYTE_ORDER == __BIG_ENDIAN
  509. dst[0]=(char)(z);
  510. dst[1]=(char)(z>>8);
  511. dst[2]=(char)(z>>16);
  512. #endif
  513. dst += dst_skip;
  514. src++;
  515. }
  516. }
  517. void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  518. {
  519. #if defined (__SSE2__) && !defined (__sun__)
  520. _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST);
  521. while (nsamples >= 4) {
  522. int i;
  523. int32_t z[4];
  524. __m128 samples = _mm_loadu_ps(src);
  525. __m128i converted = float_24_sse(samples);
  526. #ifdef __SSE4_1__
  527. z[0] = _mm_extract_epi32(converted, 0);
  528. z[1] = _mm_extract_epi32(converted, 1);
  529. z[2] = _mm_extract_epi32(converted, 2);
  530. z[3] = _mm_extract_epi32(converted, 3);
  531. #else
  532. __m128i shuffled1 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(0, 3, 2, 1));
  533. __m128i shuffled2 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(1, 0, 3, 2));
  534. __m128i shuffled3 = _mm_shuffle_epi32(converted, _MM_SHUFFLE(2, 1, 0, 3));
  535. _mm_store_ss((float*)z, (__m128)converted);
  536. _mm_store_ss((float*)z+1, (__m128)shuffled1);
  537. _mm_store_ss((float*)z+2, (__m128)shuffled2);
  538. _mm_store_ss((float*)z+3, (__m128)shuffled3);
  539. #endif
  540. for (i = 0; i != 4; ++i) {
  541. memcpy (dst, z+i, 3);
  542. dst += dst_skip;
  543. }
  544. nsamples -= 4;
  545. src += 4;
  546. }
  547. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  548. unsigned long unrolled = nsamples / 4;
  549. while (unrolled--) {
  550. int i;
  551. int32_t z[4];
  552. float32x4_t samples = vld1q_f32(src);
  553. int32x4_t converted = float_32_neon(samples, SAMPLE_24BIT_SCALING);
  554. vst1q_s32(z, converted);
  555. for (i = 0; i != 4; ++i) {
  556. memcpy (dst, z+i, 3);
  557. dst += dst_skip;
  558. }
  559. src += 4;
  560. }
  561. nsamples = nsamples & 3;
  562. #endif
  563. int32_t z;
  564. while (nsamples--) {
  565. float_24 (*src, z);
  566. #if __BYTE_ORDER == __LITTLE_ENDIAN
  567. memcpy (dst, &z, 3);
  568. #elif __BYTE_ORDER == __BIG_ENDIAN
  569. memcpy (dst, (char *)&z + 1, 3);
  570. #endif
  571. dst += dst_skip;
  572. src++;
  573. }
  574. }
  575. void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  576. {
  577. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_24BIT_SCALING;
  578. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  579. // we shift 8 to the right by dividing by 256.0 -> no sign extra handling
  580. const float32x4_t vscaling = vdupq_n_f32(scaling/256.0);
  581. int32_t x[4];
  582. memset(x, 0, sizeof(x));
  583. unsigned long unrolled = nsamples / 4;
  584. while (unrolled--) {
  585. #if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */
  586. // right aligned / inverse sequence below -> *256
  587. memcpy(((char*)&x[0])+1, src, 3);
  588. memcpy(((char*)&x[1])+1, src+src_skip, 3);
  589. memcpy(((char*)&x[2])+1, src+2*src_skip, 3);
  590. memcpy(((char*)&x[3])+1, src+3*src_skip, 3);
  591. #else
  592. memcpy(&x[0], src, 3);
  593. memcpy(&x[1], src+src_skip, 3);
  594. memcpy(&x[2], src+2*src_skip, 3);
  595. memcpy(&x[3], src+3*src_skip, 3);
  596. #endif
  597. src += 4 * src_skip;
  598. int32x4_t source = vld1q_s32(x);
  599. source = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(source)));
  600. float32x4_t converted = vcvtq_f32_s32(source);
  601. float32x4_t scaled = vmulq_f32(converted, vscaling);
  602. vst1q_f32(dst, scaled);
  603. dst += 4;
  604. }
  605. nsamples = nsamples & 3;
  606. #endif
  607. /* ALERT: signed sign-extension portability !!! */
  608. while (nsamples--) {
  609. int x;
  610. #if __BYTE_ORDER == __LITTLE_ENDIAN
  611. x = (unsigned char)(src[0]);
  612. x <<= 8;
  613. x |= (unsigned char)(src[1]);
  614. x <<= 8;
  615. x |= (unsigned char)(src[2]);
  616. /* correct sign bit and the rest of the top byte */
  617. if (src[0] & 0x80) {
  618. x |= 0xff << 24;
  619. }
  620. #elif __BYTE_ORDER == __BIG_ENDIAN
  621. x = (unsigned char)(src[2]);
  622. x <<= 8;
  623. x |= (unsigned char)(src[1]);
  624. x <<= 8;
  625. x |= (unsigned char)(src[0]);
  626. /* correct sign bit and the rest of the top byte */
  627. if (src[2] & 0x80) {
  628. x |= 0xff << 24;
  629. }
  630. #endif
  631. *dst = x * scaling;
  632. dst++;
  633. src += src_skip;
  634. }
  635. }
  636. void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  637. {
  638. const jack_default_audio_sample_t scaling = 1.f/SAMPLE_24BIT_SCALING;
  639. #if defined (__SSE2__) && !defined (__sun__)
  640. const __m128 scaling_block = _mm_set_ps1(scaling);
  641. while (nsamples >= 4) {
  642. int x0, x1, x2, x3;
  643. memcpy((char*)&x0 + 1, src, 3);
  644. memcpy((char*)&x1 + 1, src+src_skip, 3);
  645. memcpy((char*)&x2 + 1, src+2*src_skip, 3);
  646. memcpy((char*)&x3 + 1, src+3*src_skip, 3);
  647. src += 4 * src_skip;
  648. const __m128i block_i = _mm_set_epi32(x3, x2, x1, x0);
  649. const __m128i shifted = _mm_srai_epi32(block_i, 8);
  650. const __m128 converted = _mm_cvtepi32_ps (shifted);
  651. const __m128 scaled = _mm_mul_ps(converted, scaling_block);
  652. _mm_storeu_ps(dst, scaled);
  653. dst += 4;
  654. nsamples -= 4;
  655. }
  656. #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
  657. // we shift 8 to the right by dividing by 256.0 -> no sign extra handling
  658. const float32x4_t vscaling = vdupq_n_f32(scaling/256.0);
  659. int32_t x[4];
  660. memset(x, 0, sizeof(x));
  661. unsigned long unrolled = nsamples / 4;
  662. while (unrolled--) {
  663. #if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */
  664. // left aligned -> *256
  665. memcpy(&x[0], src, 3);
  666. memcpy(&x[1], src+src_skip, 3);
  667. memcpy(&x[2], src+2*src_skip, 3);
  668. memcpy(&x[3], src+3*src_skip, 3);
  669. #else
  670. memcpy(((char*)&x[0])+1, src, 3);
  671. memcpy(((char*)&x[1])+1, src+src_skip, 3);
  672. memcpy(((char*)&x[2])+1, src+2*src_skip, 3);
  673. memcpy(((char*)&x[3])+1, src+3*src_skip, 3);
  674. #endif
  675. src += 4 * src_skip;
  676. int32x4_t source = vld1q_s32(x);
  677. float32x4_t converted = vcvtq_f32_s32(source);
  678. float32x4_t scaled = vmulq_f32(converted, vscaling);
  679. vst1q_f32(dst, scaled);
  680. dst += 4;
  681. }
  682. nsamples = nsamples & 3;
  683. #endif
  684. while (nsamples--) {
  685. int x;
  686. #if __BYTE_ORDER == __LITTLE_ENDIAN
  687. memcpy((char*)&x + 1, src, 3);
  688. #elif __BYTE_ORDER == __BIG_ENDIAN
  689. memcpy(&x, src, 3);
  690. #endif
  691. x >>= 8;
  692. *dst = x * scaling;
  693. dst++;
  694. src += src_skip;
  695. }
  696. }
  697. void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  698. {
  699. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  700. unsigned long unrolled = nsamples / 4;
  701. nsamples = nsamples & 3;
  702. while (unrolled--) {
  703. float32x4_t samples = vld1q_f32(src);
  704. int16x4_t converted = float_16_neon(samples);
  705. converted = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(converted)));
  706. switch(dst_skip) {
  707. case 2:
  708. vst1_s16((int16_t*)dst, converted);
  709. break;
  710. default:
  711. vst1_lane_s16((int16_t*)(dst), converted, 0);
  712. vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1);
  713. vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2);
  714. vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3);
  715. break;
  716. }
  717. dst += 4*dst_skip;
  718. src+= 4;
  719. }
  720. #endif
  721. int16_t tmp;
  722. while (nsamples--) {
  723. // float_16 (*src, tmp);
  724. if (*src <= NORMALIZED_FLOAT_MIN) {
  725. tmp = SAMPLE_16BIT_MIN;
  726. } else if (*src >= NORMALIZED_FLOAT_MAX) {
  727. tmp = SAMPLE_16BIT_MAX;
  728. } else {
  729. tmp = (int16_t) f_round (*src * SAMPLE_16BIT_SCALING);
  730. }
  731. #if __BYTE_ORDER == __LITTLE_ENDIAN
  732. dst[0]=(char)(tmp>>8);
  733. dst[1]=(char)(tmp);
  734. #elif __BYTE_ORDER == __BIG_ENDIAN
  735. dst[0]=(char)(tmp);
  736. dst[1]=(char)(tmp>>8);
  737. #endif
  738. dst += dst_skip;
  739. src++;
  740. }
  741. }
  742. void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
  743. {
  744. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  745. unsigned long unrolled = nsamples / 4;
  746. nsamples = nsamples & 3;
  747. while (unrolled--) {
  748. float32x4_t samples = vld1q_f32(src);
  749. int16x4_t converted = float_16_neon(samples);
  750. switch(dst_skip) {
  751. case 2:
  752. vst1_s16((int16_t*)dst, converted);
  753. break;
  754. default:
  755. vst1_lane_s16((int16_t*)(dst), converted, 0);
  756. vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1);
  757. vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2);
  758. vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3);
  759. break;
  760. }
  761. dst += 4*dst_skip;
  762. src+= 4;
  763. }
  764. #endif
  765. while (nsamples--) {
  766. float_16 (*src, *((int16_t*) dst));
  767. dst += dst_skip;
  768. src++;
  769. }
  770. }
  771. 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)
  772. {
  773. jack_default_audio_sample_t val;
  774. int16_t tmp;
  775. while (nsamples--) {
  776. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float) UINT_MAX - 0.5f;
  777. float_16_scaled (val, tmp);
  778. #if __BYTE_ORDER == __LITTLE_ENDIAN
  779. dst[0]=(char)(tmp>>8);
  780. dst[1]=(char)(tmp);
  781. #elif __BYTE_ORDER == __BIG_ENDIAN
  782. dst[0]=(char)(tmp);
  783. dst[1]=(char)(tmp>>8);
  784. #endif
  785. dst += dst_skip;
  786. src++;
  787. }
  788. }
  789. 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)
  790. {
  791. jack_default_audio_sample_t val;
  792. while (nsamples--) {
  793. val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float)UINT_MAX - 0.5f;
  794. float_16_scaled (val, *((int16_t*) dst));
  795. dst += dst_skip;
  796. src++;
  797. }
  798. }
  799. 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)
  800. {
  801. jack_default_audio_sample_t val;
  802. int16_t tmp;
  803. while (nsamples--) {
  804. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  805. float_16_scaled (val, tmp);
  806. #if __BYTE_ORDER == __LITTLE_ENDIAN
  807. dst[0]=(char)(tmp>>8);
  808. dst[1]=(char)(tmp);
  809. #elif __BYTE_ORDER == __BIG_ENDIAN
  810. dst[0]=(char)(tmp);
  811. dst[1]=(char)(tmp>>8);
  812. #endif
  813. dst += dst_skip;
  814. src++;
  815. }
  816. }
  817. 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)
  818. {
  819. jack_default_audio_sample_t val;
  820. while (nsamples--) {
  821. val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  822. float_16_scaled (val, *((int16_t*) dst));
  823. dst += dst_skip;
  824. src++;
  825. }
  826. }
  827. 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)
  828. {
  829. jack_default_audio_sample_t x;
  830. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  831. jack_default_audio_sample_t xp; /* x' */
  832. float r;
  833. float rm1 = state->rm1;
  834. unsigned int idx = state->idx;
  835. int16_t tmp;
  836. while (nsamples--) {
  837. x = *src * SAMPLE_16BIT_SCALING;
  838. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  839. /* Filter the error with Lipshitz's minimally audible FIR:
  840. [2.033 -2.165 1.959 -1.590 0.6149] */
  841. xe = x
  842. - state->e[idx] * 2.033f
  843. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  844. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  845. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  846. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  847. xp = xe + r - rm1;
  848. rm1 = r;
  849. float_16_scaled (xp, tmp);
  850. /* Intrinsic z^-1 delay */
  851. idx = (idx + 1) & DITHER_BUF_MASK;
  852. state->e[idx] = xp - xe;
  853. #if __BYTE_ORDER == __LITTLE_ENDIAN
  854. dst[0]=(char)(tmp>>8);
  855. dst[1]=(char)(tmp);
  856. #elif __BYTE_ORDER == __BIG_ENDIAN
  857. dst[0]=(char)(tmp);
  858. dst[1]=(char)(tmp>>8);
  859. #endif
  860. dst += dst_skip;
  861. src++;
  862. }
  863. state->rm1 = rm1;
  864. state->idx = idx;
  865. }
  866. 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)
  867. {
  868. jack_default_audio_sample_t x;
  869. jack_default_audio_sample_t xe; /* the innput sample - filtered error */
  870. jack_default_audio_sample_t xp; /* x' */
  871. float r;
  872. float rm1 = state->rm1;
  873. unsigned int idx = state->idx;
  874. while (nsamples--) {
  875. x = *src * SAMPLE_16BIT_SCALING;
  876. r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
  877. /* Filter the error with Lipshitz's minimally audible FIR:
  878. [2.033 -2.165 1.959 -1.590 0.6149] */
  879. xe = x
  880. - state->e[idx] * 2.033f
  881. + state->e[(idx - 1) & DITHER_BUF_MASK] * 2.165f
  882. - state->e[(idx - 2) & DITHER_BUF_MASK] * 1.959f
  883. + state->e[(idx - 3) & DITHER_BUF_MASK] * 1.590f
  884. - state->e[(idx - 4) & DITHER_BUF_MASK] * 0.6149f;
  885. xp = xe + r - rm1;
  886. rm1 = r;
  887. float_16_scaled (xp, *((int16_t*) dst));
  888. /* Intrinsic z^-1 delay */
  889. idx = (idx + 1) & DITHER_BUF_MASK;
  890. state->e[idx] = *((int16_t*) dst) - xe;
  891. dst += dst_skip;
  892. src++;
  893. }
  894. state->rm1 = rm1;
  895. state->idx = idx;
  896. }
  897. void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  898. {
  899. short z;
  900. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
  901. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  902. const float32x4_t vscaling = vdupq_n_f32(scaling);
  903. unsigned long unrolled = nsamples / 4;
  904. while (unrolled--) {
  905. int16x4_t source16x4;
  906. switch(src_skip) {
  907. case 2:
  908. source16x4 = vld1_s16((int16_t*)src);
  909. break;
  910. case 4:
  911. source16x4 = vld2_s16((int16_t*)src).val[0];
  912. break;
  913. default:
  914. source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0);
  915. source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1);
  916. source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
  917. source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
  918. break;
  919. }
  920. source16x4 = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(source16x4)));
  921. int32x4_t source32x4 = vmovl_s16(source16x4);
  922. src += 4 * src_skip;
  923. float32x4_t converted = vcvtq_f32_s32(source32x4);
  924. float32x4_t scaled = vmulq_f32(converted, vscaling);
  925. vst1q_f32(dst, scaled);
  926. dst += 4;
  927. }
  928. nsamples = nsamples & 3;
  929. #endif
  930. /* ALERT: signed sign-extension portability !!! */
  931. while (nsamples--) {
  932. #if __BYTE_ORDER == __LITTLE_ENDIAN
  933. z = (unsigned char)(src[0]);
  934. z <<= 8;
  935. z |= (unsigned char)(src[1]);
  936. #elif __BYTE_ORDER == __BIG_ENDIAN
  937. z = (unsigned char)(src[1]);
  938. z <<= 8;
  939. z |= (unsigned char)(src[0]);
  940. #endif
  941. *dst = z * scaling;
  942. dst++;
  943. src += src_skip;
  944. }
  945. }
  946. void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  947. {
  948. /* ALERT: signed sign-extension portability !!! */
  949. const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
  950. #if defined (__ARM_NEON__) || defined (__ARM_NEON)
  951. const float32x4_t vscaling = vdupq_n_f32(scaling);
  952. unsigned long unrolled = nsamples / 4;
  953. while (unrolled--) {
  954. int16x4_t source16x4;
  955. switch(src_skip) {
  956. case 2:
  957. source16x4 = vld1_s16((int16_t*)src);
  958. break;
  959. case 4:
  960. source16x4 = vld2_s16((int16_t*)src).val[0];
  961. break;
  962. default:
  963. source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0);
  964. source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1);
  965. source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
  966. source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
  967. break;
  968. }
  969. int32x4_t source32x4 = vmovl_s16(source16x4);
  970. src += 4 * src_skip;
  971. float32x4_t converted = vcvtq_f32_s32(source32x4);
  972. float32x4_t scaled = vmulq_f32(converted, vscaling);
  973. vst1q_f32(dst, scaled);
  974. dst += 4;
  975. }
  976. nsamples = nsamples & 3;
  977. #endif
  978. while (nsamples--) {
  979. *dst = (*((short *) src)) * scaling;
  980. dst++;
  981. src += src_skip;
  982. }
  983. }
  984. void memset_interleave (char *dst, char val, unsigned long bytes,
  985. unsigned long unit_bytes,
  986. unsigned long skip_bytes)
  987. {
  988. switch (unit_bytes) {
  989. case 1:
  990. while (bytes--) {
  991. *dst = val;
  992. dst += skip_bytes;
  993. }
  994. break;
  995. case 2:
  996. while (bytes) {
  997. *((short *) dst) = (short) val;
  998. dst += skip_bytes;
  999. bytes -= 2;
  1000. }
  1001. break;
  1002. case 4:
  1003. while (bytes) {
  1004. *((int *) dst) = (int) val;
  1005. dst += skip_bytes;
  1006. bytes -= 4;
  1007. }
  1008. break;
  1009. default:
  1010. while (bytes) {
  1011. memset(dst, val, unit_bytes);
  1012. dst += skip_bytes;
  1013. bytes -= unit_bytes;
  1014. }
  1015. break;
  1016. }
  1017. }
  1018. /* COPY FUNCTIONS: used to move data from an input channel to an
  1019. output channel. Note that we assume that the skip distance
  1020. is the same for both channels. This is completely fine
  1021. unless the input and output were on different audio interfaces that
  1022. were interleaved differently. We don't try to handle that.
  1023. */
  1024. void
  1025. memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
  1026. {
  1027. memcpy (dst, src, src_bytes);
  1028. }
  1029. void
  1030. memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  1031. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1032. {
  1033. while (src_bytes) {
  1034. *((short *) dst) = *((short *) src);
  1035. dst += dst_skip_bytes;
  1036. src += src_skip_bytes;
  1037. src_bytes -= 2;
  1038. }
  1039. }
  1040. void
  1041. memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes,
  1042. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1043. {
  1044. while (src_bytes) {
  1045. memcpy(dst, src, 3);
  1046. dst += dst_skip_bytes;
  1047. src += src_skip_bytes;
  1048. src_bytes -= 3;
  1049. }
  1050. }
  1051. void
  1052. memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  1053. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  1054. {
  1055. while (src_bytes) {
  1056. *((int *) dst) = *((int *) src);
  1057. dst += dst_skip_bytes;
  1058. src += src_skip_bytes;
  1059. src_bytes -= 4;
  1060. }
  1061. }