2nd attempt at updated Waves audio backend, with added -fms-extensions as previously...
[ardour.git] / libs / backends / wavesaudio / waves_audioport.cc
1 /*
2     Copyright (C) 2013 Valeriy Kamyshniy
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             for (memcpy (_buffer, ((const WavesAudioPort*)*it)->const_buffer (), nframes * sizeof (Sample)), ++it;
44                                  it != get_connections ().end ();
45                                  ++it) {
46                 Sample* tgt = buffer ();
47                 const Sample* src = ((const WavesAudioPort*)*it)->const_buffer ();
48                 for (uint32_t frame = 0; frame < nframes; ++frame, ++tgt, ++src)    {
49                     *tgt += *src;
50                 }
51             }
52         }
53     }
54     return _buffer;
55 }
56
57
58 void
59 WavesAudioPort::_wipe_buffer()
60 {
61         memset (_buffer, 0, sizeof (_buffer));
62 }