Comment remaining unsolved bug.
[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 #include "ardour/runtime_functions.h"
22 #include "pbd/malign.h"
23
24 using namespace ARDOUR;
25
26 WavesAudioPort::WavesAudioPort (const std::string& port_name, PortFlags flags)
27     : WavesDataPort (port_name, flags)
28 {
29         aligned_malloc ((void**)&_buffer, MAX_BUFFER_SIZE_BYTES, 32 /*32 byte alignment*/);
30     memset (_buffer, 0, MAX_BUFFER_SIZE_BYTES);
31 }
32
33 WavesAudioPort::~WavesAudioPort ()
34 {
35         aligned_free (_buffer);
36 }
37
38
39 void* WavesAudioPort::get_buffer (pframes_t nframes)
40 {
41     if (is_input ()) {
42
43         std::vector<WavesDataPort*>::const_iterator it = get_connections ().begin ();
44
45         if (it != get_connections ().end ()) {
46             /* In fact, the static casting to (const WavesAudioPort*) is not that safe.
47              * However, mixing the buffers is assumed in the time critical conditions.
48              * Base class WavesDataPort takes is supposed to provide enough consistentcy
49              * of the connections.
50              */
51
52              // get first buffer data
53              // use optimized function to fill the buffer intialy
54              ARDOUR::copy_vector (_buffer, ((const WavesAudioPort*)*it)->const_buffer (), nframes);
55              ++it;
56
57              // mix the rest
58              for (; it != get_connections ().end (); ++it) {
59                  Sample* tgt = buffer ();
60                  const Sample* src = ((const WavesAudioPort*)*it)->const_buffer ();
61
62                  // use otimized function to mix the buffers
63                  ARDOUR::mix_buffers_no_gain (tgt, src, nframes);
64             }
65         }
66     }
67     return _buffer;
68 }
69
70
71 void
72 WavesAudioPort::_wipe_buffer()
73 {
74         memset (_buffer, 0, sizeof (_buffer));
75 }