2 Copyright (C) 2000-2005 Paul Davis
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.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <ardour/types.h>
22 #include <ardour/utils.h>
23 #include <ardour/mix.h>
26 #if defined (ARCH_X86) && defined (BUILD_SSE_OPTIMIZATIONS)
30 debug_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
32 if ( ((intptr_t)buf % 16) != 0) {
33 cerr << "compute_peak(): buffer unaligned!" << endl;
36 return x86_sse_compute_peak(buf, nsamples, current);
40 debug_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
42 if ( ((intptr_t)buf % 16) != 0) {
43 cerr << "apply_gain_to_buffer(): buffer unaligned!" << endl;
46 x86_sse_apply_gain_to_buffer(buf, nframes, gain);
50 debug_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
52 if ( ((intptr_t)dst & 15) != 0) {
53 cerr << "mix_buffers_with_gain(): dst unaligned!" << endl;
56 if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
57 cerr << "mix_buffers_with_gain(): dst & src don't have the same alignment!" << endl;
58 mix_buffers_with_gain(dst, src, nframes, gain);
60 x86_sse_mix_buffers_with_gain(dst, src, nframes, gain);
65 debug_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
67 if ( ((intptr_t)dst & 15) != 0) {
68 cerr << "mix_buffers_no_gain(): dst unaligned!" << endl;
71 if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
72 cerr << "mix_buffers_no_gain(): dst & src don't have the same alignment!" << endl;
73 mix_buffers_no_gain(dst, src, nframes);
75 x86_sse_mix_buffers_no_gain(dst, src, nframes);
83 compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
85 for (nframes_t i = 0; i < nsamples; ++i) {
86 current = f_max (current, fabsf (buf[i]));
93 find_peaks (ARDOUR::Sample *buf, nframes_t nframes, float *min, float *max)
101 for (i = 0; i < nframes; i++)
103 a = fmax (buf[i], a);
104 b = fmin (buf[i], b);
112 apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
114 for (nframes_t i=0; i<nframes; i++)
119 mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
121 for (nframes_t i = 0; i < nframes; i++) {
122 dst[i] += src[i] * gain;
127 mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
129 for (nframes_t i=0; i < nframes; i++) {
134 #if defined (__APPLE__) && defined (BUILD_VECLIB_OPTIMIZATIONS)
135 #include <Accelerate/Accelerate.h>
138 veclib_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
141 vDSP_maxmgv(buf, 1, &tmpmax, nsamples);
142 return f_max(current, tmpmax);
146 veclib_find_peaks (ARDOUR::Sample *buf, nframes_t nframes, float *min, float *max)
148 vDSP_maxv (buf, 1, max, nframes);
149 vDSP_minv (buf, 1, min, nframes);
153 veclib_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
155 vDSP_vsmul(buf, 1, &gain, buf, 1, nframes);
159 veclib_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
161 vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
165 veclib_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
167 // It seems that a vector mult only operation does not exist...
169 vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);