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.

258 lines
5.9KB

  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. $Id$
  15. */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <memory.h>
  20. #include <stdlib.h>
  21. #include <jack/memops.h>
  22. #define SAMPLE_MAX_24BIT 8388608.0f
  23. #define SAMPLE_MAX_16BIT 32767.0f
  24. /* XXX we could use rint(), but for now we'll accept whatever default
  25. floating-point => int conversion the compiler provides.
  26. */
  27. void sample_move_d32u24_sS (char *dst, sample_t *src, unsigned long nsamples, unsigned long dst_skip, gain_t gain)
  28. {
  29. /* ALERT: signed sign-extension portability !!! */
  30. if (gain == 1.0) {
  31. while (nsamples--) {
  32. *((int *) dst) = ((int) (*src * SAMPLE_MAX_24BIT)) << 8;
  33. dst += dst_skip;
  34. src++;
  35. }
  36. } else {
  37. while (nsamples--) {
  38. *((int *) dst) = ((int) ((*src * gain) * SAMPLE_MAX_24BIT)) << 8;
  39. dst += dst_skip;
  40. src++;
  41. }
  42. }
  43. }
  44. void sample_move_dS_s32u24 (sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  45. {
  46. /* ALERT: signed sign-extension portability !!! */
  47. while (nsamples--) {
  48. *dst = (*((int *) src) >> 8) / SAMPLE_MAX_24BIT;
  49. dst++;
  50. src += src_skip;
  51. }
  52. }
  53. void sample_move_d16_sS (char *dst, sample_t *src, unsigned long nsamples, unsigned long dst_skip, gain_t gain)
  54. {
  55. /* ALERT: signed sign-extension portability !!! */
  56. /* XXX good to use x86 assembler here, since float->short
  57. sucks that h/w.
  58. */
  59. if (gain == 1.0) {
  60. while (nsamples--) {
  61. *((short *) dst) = (short) (*src * SAMPLE_MAX_16BIT);
  62. dst += dst_skip;
  63. src++;
  64. }
  65. } else {
  66. while (nsamples--) {
  67. *((short *) dst) = (short) ((*src * gain) * SAMPLE_MAX_16BIT);
  68. dst += dst_skip;
  69. src++;
  70. }
  71. }
  72. }
  73. void sample_move_dS_s16 (sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
  74. {
  75. /* ALERT: signed sign-extension portability !!! */
  76. while (nsamples--) {
  77. *dst = (*((short *) src)) / SAMPLE_MAX_16BIT;
  78. dst++;
  79. src += src_skip;
  80. }
  81. }
  82. void sample_merge_d16_sS (char *dst, sample_t *src, unsigned long nsamples, unsigned long dst_skip, gain_t gain)
  83. {
  84. /* ALERT: signed sign-extension portability !!! */
  85. if (gain == 1.0) {
  86. while (nsamples--) {
  87. *((short *) dst) += (short) (*src * SAMPLE_MAX_16BIT);
  88. dst += dst_skip;
  89. src++;
  90. }
  91. } else {
  92. while (nsamples--) {
  93. *((short *) dst) += (short) ((*src * gain) * SAMPLE_MAX_16BIT);
  94. dst += dst_skip;
  95. src++;
  96. }
  97. }
  98. }
  99. void sample_merge_d32u24_sS (char *dst, sample_t *src, unsigned long nsamples, unsigned long dst_skip, gain_t gain)
  100. {
  101. /* ALERT: signed sign-extension portability !!! */
  102. if (gain == 1.0) {
  103. while (nsamples--) {
  104. *((int *) dst) += (((int) (*src * SAMPLE_MAX_24BIT)) << 8);
  105. dst += dst_skip;
  106. src++;
  107. }
  108. } else {
  109. while (nsamples--) {
  110. *((int *) dst) += (((int) ((*src * gain) * SAMPLE_MAX_24BIT)) << 8);
  111. dst += dst_skip;
  112. src++;
  113. }
  114. }
  115. }
  116. void memset_interleave (char *dst, char val, unsigned long bytes,
  117. unsigned long unit_bytes,
  118. unsigned long skip_bytes)
  119. {
  120. switch (unit_bytes) {
  121. case 1:
  122. while (bytes--) {
  123. *dst = val;
  124. dst += skip_bytes;
  125. }
  126. break;
  127. case 2:
  128. while (bytes) {
  129. *((short *) dst) = (short) val;
  130. dst += skip_bytes;
  131. bytes -= 2;
  132. }
  133. break;
  134. case 4:
  135. while (bytes) {
  136. *((int *) dst) = (int) val;
  137. dst += skip_bytes;
  138. bytes -= 4;
  139. }
  140. break;
  141. }
  142. }
  143. /* COPY FUNCTIONS: used to move data from an input channel to an
  144. output channel. Note that we assume that the skip distance
  145. is the same for both channels. This is completely fine
  146. unless the input and output were on different audio interfaces that
  147. were interleaved differently. We don't try to handle that.
  148. */
  149. void
  150. memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
  151. {
  152. memcpy (dst, src, src_bytes);
  153. }
  154. void
  155. merge_memcpy_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  156. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  157. {
  158. while (src_bytes) {
  159. *((short *) dst) += *((short *) src);
  160. dst += 2;
  161. src += 2;
  162. src_bytes -= 2;
  163. }
  164. }
  165. void
  166. merge_memcpy_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  167. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  168. {
  169. while (src_bytes) {
  170. *((int *) dst) += *((int *) src);
  171. dst += 4;
  172. src += 4;
  173. src_bytes -= 4;
  174. }
  175. }
  176. void
  177. merge_memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  178. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  179. {
  180. while (src_bytes) {
  181. *((short *) dst) += *((short *) src);
  182. dst += dst_skip_bytes;
  183. src += src_skip_bytes;
  184. src_bytes -= 2;
  185. }
  186. }
  187. void
  188. merge_memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  189. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  190. {
  191. while (src_bytes) {
  192. *((int *) dst) += *((int *) src);
  193. dst += dst_skip_bytes;
  194. src += src_skip_bytes;
  195. src_bytes -= 4;
  196. }
  197. }
  198. void
  199. memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
  200. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  201. {
  202. while (src_bytes) {
  203. *((short *) dst) = *((short *) src);
  204. dst += dst_skip_bytes;
  205. src += src_skip_bytes;
  206. src_bytes -= 2;
  207. }
  208. }
  209. void
  210. memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
  211. unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
  212. {
  213. while (src_bytes) {
  214. *((int *) dst) = *((int *) src);
  215. dst += dst_skip_bytes;
  216. src += src_skip_bytes;
  217. src_bytes -= 4;
  218. }
  219. }