2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "JackPortType.h"
24 #if defined (__APPLE__)
25 #include <Accelerate/Accelerate.h>
26 #elif defined (__SSE__)
27 #include <xmmintrin.h>
33 static void AudioBufferInit(void* buffer
, size_t buffer_size
, jack_nframes_t
)
35 memset(buffer
, 0, buffer_size
);
38 static inline void MixAudioBuffer(float* mixbuffer
, float* buffer
, jack_nframes_t frames
)
41 // It seems that a vector mult only operation does not exist...
43 vDSP_vsma(buffer
, 1, &gain
, mixbuffer
, 1, mixbuffer
, 1, frames
);
45 jack_nframes_t frames_group
= frames
/ 4;
48 while (frames_group
> 0) {
50 __m128 vec
= _mm_add_ps(_mm_load_ps(mixbuffer
), _mm_load_ps(buffer
));
51 _mm_store_ps(mixbuffer
, vec
);
57 register float mixFloat1
= *mixbuffer
;
58 register float sourceFloat1
= *buffer
;
59 register float mixFloat2
= *(mixbuffer
+ 1);
60 register float sourceFloat2
= *(buffer
+ 1);
61 register float mixFloat3
= *(mixbuffer
+ 2);
62 register float sourceFloat3
= *(buffer
+ 2);
63 register float mixFloat4
= *(mixbuffer
+ 3);
64 register float sourceFloat4
= *(buffer
+ 3);
69 mixFloat1
+= sourceFloat1
;
70 mixFloat2
+= sourceFloat2
;
71 mixFloat3
+= sourceFloat3
;
72 mixFloat4
+= sourceFloat4
;
74 *mixbuffer
= mixFloat1
;
75 *(mixbuffer
+ 1) = mixFloat2
;
76 *(mixbuffer
+ 2) = mixFloat3
;
77 *(mixbuffer
+ 3) = mixFloat4
;
84 register float mixFloat1
= *mixbuffer
;
85 register float sourceFloat1
= *buffer
;
88 mixFloat1
+= sourceFloat1
;
89 *mixbuffer
= mixFloat1
;
95 static void AudioBufferMixdown(void* mixbuffer
, void** src_buffers
, int src_count
, jack_nframes_t nframes
)
101 jack_nframes_t frames_group
= nframes
/ 4;
102 jack_nframes_t remaining_frames
= nframes
% 4;
104 float * source
= static_cast<float*>(src_buffers
[0]);
105 float * target
= static_cast<float*>(mixbuffer
);
107 while (frames_group
> 0)
109 __m128 vec
= _mm_load_ps(source
);
110 _mm_store_ps(target
, vec
);
116 for (jack_nframes_t i
= 0; i
!= remaining_frames
; ++i
)
117 target
[i
] = source
[i
];
120 memcpy(mixbuffer
, src_buffers
[0], nframes
* sizeof(float));
123 // Mix remaining buffers
124 for (int i
= 1; i
< src_count
; ++i
) {
125 buffer
= src_buffers
[i
];
126 MixAudioBuffer(static_cast<float*>(mixbuffer
), static_cast<float*>(buffer
), nframes
);
130 const JackPortType gAudioPortType
=
132 JACK_DEFAULT_AUDIO_TYPE
,