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"
24 #include "ardour/runtime_functions.h"
29 using namespace ARDOUR;
31 #if defined (ARCH_X86) && defined (BUILD_SSE_OPTIMIZATIONS)
35 debug_compute_peak (const ARDOUR::Sample *buf, pframes_t nsamples, float current)
37 if ( ((intptr_t)buf % 16) != 0) {
38 std::cerr << "compute_peak(): buffer unaligned!" << std::endl;
41 return x86_sse_compute_peak(buf, nsamples, current);
45 debug_apply_gain_to_buffer (ARDOUR::Sample *buf, pframes_t nframes, float gain)
47 if ( ((intptr_t)buf % 16) != 0) {
48 std::cerr << "apply_gain_to_buffer(): buffer unaligned!" << std::endl;
51 x86_sse_apply_gain_to_buffer(buf, nframes, gain);
55 debug_mix_buffers_with_gain (ARDOUR::Sample *dst, const ARDOUR::Sample *src, pframes_t nframes, float gain)
57 if ( ((intptr_t)dst & 15) != 0) {
58 std::cerr << "mix_buffers_with_gain(): dst unaligned!" << std::endl;
61 if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
62 std::cerr << "mix_buffers_with_gain(): dst & src don't have the same alignment!" << std::endl;
63 mix_buffers_with_gain(dst, src, nframes, gain);
65 x86_sse_mix_buffers_with_gain(dst, src, nframes, gain);
70 debug_mix_buffers_no_gain (ARDOUR::Sample *dst, const ARDOUR::Sample *src, pframes_t nframes)
72 if ( ((intptr_t)dst & 15) != 0) {
73 std::cerr << "mix_buffers_no_gain(): dst unaligned!" << std::endl;
76 if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
77 std::cerr << "mix_buffers_no_gain(): dst & src don't have the same alignment!" << std::endl;
78 mix_buffers_no_gain(dst, src, nframes);
80 x86_sse_mix_buffers_no_gain(dst, src, nframes);
88 default_compute_peak (const ARDOUR::Sample * buf, pframes_t nsamples, float current)
90 for (pframes_t i = 0; i < nsamples; ++i) {
91 current = f_max (current, fabsf (buf[i]));
98 default_find_peaks (const ARDOUR::Sample * buf, pframes_t nframes, float *minf, float *maxf)
106 for (i = 0; i < nframes; i++)
117 default_apply_gain_to_buffer (ARDOUR::Sample * buf, pframes_t nframes, float gain)
119 for (pframes_t i=0; i<nframes; i++)
124 default_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, pframes_t nframes, float gain)
126 for (pframes_t i = 0; i < nframes; i++) {
127 dst[i] += src[i] * gain;
132 default_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, pframes_t nframes)
134 for (pframes_t i=0; i < nframes; i++) {
140 default_copy_vector (ARDOUR::Sample * dst, const ARDOUR::Sample * src, pframes_t nframes)
142 memcpy(dst, src, nframes*sizeof(ARDOUR::Sample));
145 #if defined (__APPLE__) && defined (BUILD_VECLIB_OPTIMIZATIONS)
146 #include <Accelerate/Accelerate.h>
149 veclib_compute_peak (const ARDOUR::Sample * buf, pframes_t nsamples, float current)
152 vDSP_maxmgv(buf, 1, &tmpmax, nsamples);
153 return f_max(current, tmpmax);
157 veclib_find_peaks (const ARDOUR::Sample * buf, pframes_t nframes, float *min, float *max)
159 vDSP_maxv (const_cast<ARDOUR::Sample*>(buf), 1, max, nframes);
160 vDSP_minv (const_cast<ARDOUR::Sample*>(buf), 1, min, nframes);
164 veclib_apply_gain_to_buffer (ARDOUR::Sample * buf, pframes_t nframes, float gain)
166 vDSP_vsmul(buf, 1, &gain, buf, 1, nframes);
170 veclib_mix_buffers_with_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, pframes_t nframes, float gain)
172 vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
176 veclib_mix_buffers_no_gain (ARDOUR::Sample * dst, const ARDOUR::Sample * src, pframes_t nframes)
178 // It seems that a vector mult only operation does not exist...
180 vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);