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.

96 lines
2.6KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 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. namespace Jack
  19. {
  20. static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
  21. {
  22. memset(buffer, 0, buffer_size);
  23. }
  24. static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
  25. {
  26. jack_nframes_t frames_group = frames / 4;
  27. frames = frames % 4;
  28. while (frames_group > 0) {
  29. register float mixFloat1 = *mixbuffer;
  30. register float sourceFloat1 = *buffer;
  31. register float mixFloat2 = *(mixbuffer + 1);
  32. register float sourceFloat2 = *(buffer + 1);
  33. register float mixFloat3 = *(mixbuffer + 2);
  34. register float sourceFloat3 = *(buffer + 2);
  35. register float mixFloat4 = *(mixbuffer + 3);
  36. register float sourceFloat4 = *(buffer + 3);
  37. buffer += 4;
  38. frames_group--;
  39. mixFloat1 += sourceFloat1;
  40. mixFloat2 += sourceFloat2;
  41. mixFloat3 += sourceFloat3;
  42. mixFloat4 += sourceFloat4;
  43. *mixbuffer = mixFloat1;
  44. *(mixbuffer + 1) = mixFloat2;
  45. *(mixbuffer + 2) = mixFloat3;
  46. *(mixbuffer + 3) = mixFloat4;
  47. mixbuffer += 4;
  48. }
  49. while (frames > 0) {
  50. register float mixFloat1 = *mixbuffer;
  51. register float sourceFloat1 = *buffer;
  52. buffer++;
  53. frames--;
  54. mixFloat1 += sourceFloat1;
  55. *mixbuffer = mixFloat1;
  56. mixbuffer++;
  57. }
  58. }
  59. static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes)
  60. {
  61. void* buffer;
  62. // Copy first buffer
  63. memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float));
  64. // Mix remaining buffers
  65. for (int i = 1; i < src_count; ++i) {
  66. buffer = src_buffers[i];
  67. MixAudioBuffer((float*)mixbuffer, (float*)buffer, nframes);
  68. }
  69. }
  70. const JackPortType gAudioPortType = {
  71. JACK_DEFAULT_AUDIO_TYPE,
  72. AudioBufferInit,
  73. AudioBufferMixdown
  74. };
  75. } // namespace Jack