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 "JackGlobals.h"
22 #include "JackEngineControl.h"
23 #include "JackPortType.h"
27 #if defined (__APPLE__)
28 #include <Accelerate/Accelerate.h>
29 #elif defined (__SSE__) && !defined (__sun__)
30 #include <xmmintrin.h>
31 #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
38 static void AudioBufferInit(void* buffer
, size_t buffer_size
, jack_nframes_t
)
40 memset(buffer
, 0, buffer_size
);
43 static inline void MixAudioBuffer(jack_default_audio_sample_t
* mixbuffer
, jack_default_audio_sample_t
* buffer
, jack_nframes_t frames
)
46 vDSP_vadd(buffer
, 1, mixbuffer
, 1, mixbuffer
, 1, frames
);
48 jack_nframes_t frames_group
= frames
/ 4;
51 while (frames_group
> 0) {
52 #if defined (__SSE__) && !defined (__sun__)
53 __m128 vec
= _mm_add_ps(_mm_load_ps(mixbuffer
), _mm_load_ps(buffer
));
54 _mm_store_ps(mixbuffer
, vec
);
59 #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
60 float32x4_t vec
= vaddq_f32(vld1q_f32(mixbuffer
), vld1q_f32(buffer
));
61 vst1q_f32(mixbuffer
, vec
);
67 register jack_default_audio_sample_t mixFloat1
= *mixbuffer
;
68 register jack_default_audio_sample_t sourceFloat1
= *buffer
;
69 register jack_default_audio_sample_t mixFloat2
= *(mixbuffer
+ 1);
70 register jack_default_audio_sample_t sourceFloat2
= *(buffer
+ 1);
71 register jack_default_audio_sample_t mixFloat3
= *(mixbuffer
+ 2);
72 register jack_default_audio_sample_t sourceFloat3
= *(buffer
+ 2);
73 register jack_default_audio_sample_t mixFloat4
= *(mixbuffer
+ 3);
74 register jack_default_audio_sample_t sourceFloat4
= *(buffer
+ 3);
79 mixFloat1
+= sourceFloat1
;
80 mixFloat2
+= sourceFloat2
;
81 mixFloat3
+= sourceFloat3
;
82 mixFloat4
+= sourceFloat4
;
84 *mixbuffer
= mixFloat1
;
85 *(mixbuffer
+ 1) = mixFloat2
;
86 *(mixbuffer
+ 2) = mixFloat3
;
87 *(mixbuffer
+ 3) = mixFloat4
;
94 register jack_default_audio_sample_t mixFloat1
= *mixbuffer
;
95 register jack_default_audio_sample_t sourceFloat1
= *buffer
;
98 mixFloat1
+= sourceFloat1
;
99 *mixbuffer
= mixFloat1
;
105 static void AudioBufferMixdown(void* mixbuffer
, void** src_buffers
, int src_count
, jack_nframes_t nframes
)
110 #if defined (__SSE__) && !defined (__sun__)
111 jack_nframes_t frames_group
= nframes
/ 4;
112 jack_nframes_t remaining_frames
= nframes
% 4;
114 jack_default_audio_sample_t
* source
= static_cast<jack_default_audio_sample_t
*>(src_buffers
[0]);
115 jack_default_audio_sample_t
* target
= static_cast<jack_default_audio_sample_t
*>(mixbuffer
);
117 while (frames_group
> 0) {
118 __m128 vec
= _mm_load_ps(source
);
119 _mm_store_ps(target
, vec
);
125 for (jack_nframes_t i
= 0; i
!= remaining_frames
; ++i
) {
126 target
[i
] = source
[i
];
128 #elif defined (__ARM_NEON__) || defined (__ARM_NEON)
129 jack_nframes_t frames_group
= nframes
/ 4;
130 jack_nframes_t remaining_frames
= nframes
% 4;
132 jack_default_audio_sample_t
* source
= static_cast<jack_default_audio_sample_t
*>(src_buffers
[0]);
133 jack_default_audio_sample_t
* target
= static_cast<jack_default_audio_sample_t
*>(mixbuffer
);
135 while (frames_group
> 0) {
136 float32x4_t vec
= vld1q_f32(source
);
137 vst1q_f32(target
, vec
);
143 for (jack_nframes_t i
= 0; i
!= remaining_frames
; ++i
) {
144 target
[i
] = source
[i
];
147 memcpy(mixbuffer
, src_buffers
[0], nframes
* sizeof(jack_default_audio_sample_t
));
150 // Mix remaining buffers
151 for (int i
= 1; i
< src_count
; ++i
) {
152 buffer
= src_buffers
[i
];
153 MixAudioBuffer(static_cast<jack_default_audio_sample_t
*>(mixbuffer
), static_cast<jack_default_audio_sample_t
*>(buffer
), nframes
);
157 static size_t AudioBufferSize()
159 return GetEngineControl()->fBufferSize
* sizeof(jack_default_audio_sample_t
);
162 const JackPortType gAudioPortType
=
164 JACK_DEFAULT_AUDIO_TYPE
,