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>
36 static void AudioBufferInit(void* buffer
, size_t buffer_size
, jack_nframes_t
)
38 memset(buffer
, 0, buffer_size
);
41 static inline void MixAudioBuffer(jack_default_audio_sample_t
* mixbuffer
, jack_default_audio_sample_t
* buffer
, jack_nframes_t frames
)
44 // It seems that a vector mult only operation does not exist...
45 jack_default_audio_sample_t gain
= jack_default_audio_sample_t(1.0);
46 vDSP_vsma(buffer
, 1, &gain
, 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
);
60 register jack_default_audio_sample_t mixFloat1
= *mixbuffer
;
61 register jack_default_audio_sample_t sourceFloat1
= *buffer
;
62 register jack_default_audio_sample_t mixFloat2
= *(mixbuffer
+ 1);
63 register jack_default_audio_sample_t sourceFloat2
= *(buffer
+ 1);
64 register jack_default_audio_sample_t mixFloat3
= *(mixbuffer
+ 2);
65 register jack_default_audio_sample_t sourceFloat3
= *(buffer
+ 2);
66 register jack_default_audio_sample_t mixFloat4
= *(mixbuffer
+ 3);
67 register jack_default_audio_sample_t sourceFloat4
= *(buffer
+ 3);
72 mixFloat1
+= sourceFloat1
;
73 mixFloat2
+= sourceFloat2
;
74 mixFloat3
+= sourceFloat3
;
75 mixFloat4
+= sourceFloat4
;
77 *mixbuffer
= mixFloat1
;
78 *(mixbuffer
+ 1) = mixFloat2
;
79 *(mixbuffer
+ 2) = mixFloat3
;
80 *(mixbuffer
+ 3) = mixFloat4
;
87 register jack_default_audio_sample_t mixFloat1
= *mixbuffer
;
88 register jack_default_audio_sample_t sourceFloat1
= *buffer
;
91 mixFloat1
+= sourceFloat1
;
92 *mixbuffer
= mixFloat1
;
98 static void AudioBufferMixdown(void* mixbuffer
, void** src_buffers
, int src_count
, jack_nframes_t nframes
)
103 #if defined (__SSE__) && !defined (__sun__)
104 jack_nframes_t frames_group
= nframes
/ 4;
105 jack_nframes_t remaining_frames
= nframes
% 4;
107 jack_default_audio_sample_t
* source
= static_cast<jack_default_audio_sample_t
*>(src_buffers
[0]);
108 jack_default_audio_sample_t
* target
= static_cast<jack_default_audio_sample_t
*>(mixbuffer
);
110 while (frames_group
> 0)
112 __m128 vec
= _mm_load_ps(source
);
113 _mm_store_ps(target
, vec
);
119 for (jack_nframes_t i
= 0; i
!= remaining_frames
; ++i
)
120 target
[i
] = source
[i
];
123 memcpy(mixbuffer
, src_buffers
[0], nframes
* sizeof(jack_default_audio_sample_t
));
126 // Mix remaining buffers
127 for (int i
= 1; i
< src_count
; ++i
) {
128 buffer
= src_buffers
[i
];
129 MixAudioBuffer(static_cast<jack_default_audio_sample_t
*>(mixbuffer
), static_cast<jack_default_audio_sample_t
*>(buffer
), nframes
);
133 static size_t AudioBufferSize()
135 return GetEngineControl()->fBufferSize
* sizeof(jack_default_audio_sample_t
);
138 const JackPortType gAudioPortType
=
140 JACK_DEFAULT_AUDIO_TYPE
,