remove all lines to avoid recompiles after commits
[ardour.git] / libs / ardour / mix.cc
1 /*
2     Copyright (C) 2000-2005 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cmath>
21 #include <ardour/types.h>
22 #include <ardour/utils.h>
23 #include <ardour/mix.h>
24 #include <stdint.h>
25
26 #if defined (ARCH_X86) && defined (BUILD_SSE_OPTIMIZATIONS)
27
28 // Debug wrappers
29
30 float
31 debug_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current) 
32 {
33         if ( ((intptr_t)buf % 16) != 0) {
34                 cerr << "compute_peak(): buffer unaligned!" << endl;
35         }
36
37         return x86_sse_compute_peak(buf, nsamples, current);
38 }
39
40 void
41 debug_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
42 {
43         if ( ((intptr_t)buf % 16) != 0) {
44                 cerr << "apply_gain_to_buffer(): buffer unaligned!" << endl;
45         }
46
47         x86_sse_apply_gain_to_buffer(buf, nframes, gain);
48 }
49
50 void
51 debug_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
52 {
53         if ( ((intptr_t)dst & 15) != 0) {
54                 cerr << "mix_buffers_with_gain(): dst unaligned!" << endl;
55         }
56
57         if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
58                 cerr << "mix_buffers_with_gain(): dst & src don't have the same alignment!" << endl;
59                 mix_buffers_with_gain(dst, src, nframes, gain);
60         } else {
61                 x86_sse_mix_buffers_with_gain(dst, src, nframes, gain);
62         }
63 }
64
65 void
66 debug_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
67 {
68         if ( ((intptr_t)dst & 15) != 0) {
69                 cerr << "mix_buffers_no_gain(): dst unaligned!" << endl;
70         }
71
72         if ( ((intptr_t)dst & 15) != ((intptr_t)src & 15) ) {
73                 cerr << "mix_buffers_no_gain(): dst & src don't have the same alignment!" << endl;
74                 mix_buffers_no_gain(dst, src, nframes);
75         } else {
76                 x86_sse_mix_buffers_no_gain(dst, src, nframes);
77         }
78 }
79
80 #endif
81
82
83 float
84 compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current) 
85 {
86         for (nframes_t i = 0; i < nsamples; ++i) {
87                 current = f_max (current, fabsf (buf[i]));
88         }
89
90         return current;
91 }       
92
93 void
94 apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
95 {               
96         for (nframes_t i=0; i<nframes; i++)
97                 buf[i] *= gain;
98 }
99
100 void
101 mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
102 {
103         for (nframes_t i = 0; i < nframes; i++) {
104                 dst[i] += src[i] * gain;
105         }
106 }
107
108 void
109 mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
110 {
111         for (nframes_t i=0; i < nframes; i++) {
112                 dst[i] += src[i];
113         }
114 }
115
116 #if defined (__APPLE__) && defined (BUILD_VECLIB_OPTIMIZATIONS)
117 #include <Accelerate/Accelerate.h>
118
119 float
120 veclib_compute_peak (ARDOUR::Sample *buf, nframes_t nsamples, float current)
121 {
122         float tmpmax = 0.0f;
123         vDSP_maxmgv(buf, 1, &tmpmax, nsamples);
124         return f_max(current, tmpmax);
125 }
126
127 void
128 veclib_apply_gain_to_buffer (ARDOUR::Sample *buf, nframes_t nframes, float gain)
129 {
130         vDSP_vsmul(buf, 1, &gain, buf, 1, nframes);
131 }
132
133 void
134 veclib_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes, float gain)
135 {
136         vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
137 }
138
139 void
140 veclib_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, nframes_t nframes)
141 {
142         // It seems that a vector mult only operation does not exist...
143         float gain = 1.0f;
144         vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
145 }
146
147 #endif
148                 
149