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.

122 lines
3.2KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #if defined(HAVE_CONFIG_H)
  17. #include "config.h"
  18. #endif
  19. #include "JackPortType.h"
  20. #include <string.h>
  21. #if defined (__APPLE__)
  22. #include <Accelerate/Accelerate.h>
  23. #elif defined (__SSE__)
  24. #include <xmmintrin.h>
  25. #endif
  26. namespace Jack
  27. {
  28. static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
  29. {
  30. memset(buffer, 0, buffer_size);
  31. }
  32. static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
  33. {
  34. #ifdef __APPLE__
  35. // It seems that a vector mult only operation does not exist...
  36. float gain = 1.0f;
  37. vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
  38. #else
  39. jack_nframes_t frames_group = frames / 4;
  40. frames = frames % 4;
  41. while (frames_group > 0) {
  42. #ifdef __SSE__
  43. __m128 vec = _mm_add_ps(_mm_load_ps(mixbuffer), _mm_load_ps(buffer));
  44. _mm_store_ps(mixbuffer, vec);
  45. mixbuffer += 4;
  46. buffer += 4;
  47. frames_group--;
  48. #else
  49. register float mixFloat1 = *mixbuffer;
  50. register float sourceFloat1 = *buffer;
  51. register float mixFloat2 = *(mixbuffer + 1);
  52. register float sourceFloat2 = *(buffer + 1);
  53. register float mixFloat3 = *(mixbuffer + 2);
  54. register float sourceFloat3 = *(buffer + 2);
  55. register float mixFloat4 = *(mixbuffer + 3);
  56. register float sourceFloat4 = *(buffer + 3);
  57. buffer += 4;
  58. frames_group--;
  59. mixFloat1 += sourceFloat1;
  60. mixFloat2 += sourceFloat2;
  61. mixFloat3 += sourceFloat3;
  62. mixFloat4 += sourceFloat4;
  63. *mixbuffer = mixFloat1;
  64. *(mixbuffer + 1) = mixFloat2;
  65. *(mixbuffer + 2) = mixFloat3;
  66. *(mixbuffer + 3) = mixFloat4;
  67. mixbuffer += 4;
  68. #endif
  69. }
  70. while (frames > 0) {
  71. register float mixFloat1 = *mixbuffer;
  72. register float sourceFloat1 = *buffer;
  73. buffer++;
  74. frames--;
  75. mixFloat1 += sourceFloat1;
  76. *mixbuffer = mixFloat1;
  77. mixbuffer++;
  78. }
  79. #endif
  80. }
  81. static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes)
  82. {
  83. void* buffer;
  84. // Copy first buffer
  85. memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float));
  86. // Mix remaining buffers
  87. for (int i = 1; i < src_count; ++i) {
  88. buffer = src_buffers[i];
  89. MixAudioBuffer(static_cast<float*>(mixbuffer), static_cast<float*>(buffer), nframes);
  90. }
  91. }
  92. const JackPortType gAudioPortType =
  93. {
  94. JACK_DEFAULT_AUDIO_TYPE,
  95. AudioBufferInit,
  96. AudioBufferMixdown
  97. };
  98. } // namespace Jack