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.

118 lines
3.1KB

  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 General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackPortType.h"
  17. #include <string.h>
  18. #if defined (__APPLE__)
  19. #include <Accelerate/Accelerate.h>
  20. #elif defined (__SSE__)
  21. #include <xmmintrin.h>
  22. #endif
  23. namespace Jack
  24. {
  25. static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
  26. {
  27. memset(buffer, 0, buffer_size);
  28. }
  29. static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
  30. {
  31. #ifdef __APPLE__
  32. // It seems that a vector mult only operation does not exist...
  33. float gain = 1.0f;
  34. vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
  35. #else
  36. jack_nframes_t frames_group = frames / 4;
  37. frames = frames % 4;
  38. while (frames_group > 0) {
  39. #ifdef __SSE__
  40. __m128 vec = _mm_add_ps(_mm_load_ps(mixbuffer), _mm_load_ps(buffer));
  41. _mm_store_ps(mixbuffer, vec);
  42. mixbuffer += 4;
  43. buffer += 4;
  44. frames_group--;
  45. #else
  46. register float mixFloat1 = *mixbuffer;
  47. register float sourceFloat1 = *buffer;
  48. register float mixFloat2 = *(mixbuffer + 1);
  49. register float sourceFloat2 = *(buffer + 1);
  50. register float mixFloat3 = *(mixbuffer + 2);
  51. register float sourceFloat3 = *(buffer + 2);
  52. register float mixFloat4 = *(mixbuffer + 3);
  53. register float sourceFloat4 = *(buffer + 3);
  54. buffer += 4;
  55. frames_group--;
  56. mixFloat1 += sourceFloat1;
  57. mixFloat2 += sourceFloat2;
  58. mixFloat3 += sourceFloat3;
  59. mixFloat4 += sourceFloat4;
  60. *mixbuffer = mixFloat1;
  61. *(mixbuffer + 1) = mixFloat2;
  62. *(mixbuffer + 2) = mixFloat3;
  63. *(mixbuffer + 3) = mixFloat4;
  64. mixbuffer += 4;
  65. #endif
  66. }
  67. while (frames > 0) {
  68. register float mixFloat1 = *mixbuffer;
  69. register float sourceFloat1 = *buffer;
  70. buffer++;
  71. frames--;
  72. mixFloat1 += sourceFloat1;
  73. *mixbuffer = mixFloat1;
  74. mixbuffer++;
  75. }
  76. #endif
  77. }
  78. static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes)
  79. {
  80. void* buffer;
  81. // Copy first buffer
  82. memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float));
  83. // Mix remaining buffers
  84. for (int i = 1; i < src_count; ++i) {
  85. buffer = src_buffers[i];
  86. MixAudioBuffer(static_cast<float*>(mixbuffer), static_cast<float*>(buffer), nframes);
  87. }
  88. }
  89. const JackPortType gAudioPortType =
  90. {
  91. JACK_DEFAULT_AUDIO_TYPE,
  92. AudioBufferInit,
  93. AudioBufferMixdown
  94. };
  95. } // namespace Jack