Added optimized AVX function for sample processing
[ardour.git] / libs / backends / wavesaudio / waves_audioport.cc
1 /*
2     Copyright (C) 2014 Waves Audio Ltd.
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 "waves_audioport.h"
21
22 using namespace ARDOUR;
23
24 WavesAudioPort::WavesAudioPort (const std::string& port_name, PortFlags flags)
25     : WavesDataPort (port_name, flags)    
26 {
27     memset (_buffer, 0, sizeof (_buffer));
28 }
29
30
31 void* WavesAudioPort::get_buffer (pframes_t nframes)
32 {
33     if (is_input ()) {
34         
35         std::vector<WavesDataPort*>::const_iterator it = get_connections ().begin ();
36         
37         if (it != get_connections ().end ()) {
38                 /* In fact, the static casting to (const WavesAudioPort*) is not that safe.
39                  * However, mixing the buffers is assumed in the time critical conditions.
40                  * Base class WavesDataPort takes is supposed to provide enough consistentcy
41                  * of the connections.
42                  */
43                 // get first buffer data
44                 // use optimized function to fill the buffer intialy
45                 ARDOUR::copy_vector (_buffer, ((const WavesAudioPort*)*it)->const_buffer (), nframes);
46                 ++it;
47                 
48                 // mix the rest
49                 for (; it != get_connections ().end (); ++it) {
50                         Sample* tgt = buffer ();
51                         const Sample* src = ((const WavesAudioPort*)*it)->const_buffer ();
52                         for (uint32_t frame = 0; frame < nframes; ++frame, ++tgt, ++src)    {
53                                 *tgt += *src;
54                         }
55                 }
56         }
57     }
58     return _buffer;
59 }
60
61
62 void
63 WavesAudioPort::_wipe_buffer()
64 {
65         memset (_buffer, 0, sizeof (_buffer));
66 }