bsd compatibility mods
[goodguy/history.git] / cinelerra-5.1 / plugins / dcoffset / dcoffset.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "clip.h"
23 #include "bchash.h"
24 #include "dcoffset.h"
25 #include "filexml.h"
26 #include "language.h"
27 #include "samples.h"
28 #include "transportque.h"
29
30 #include "vframe.h"
31
32 #include <string.h>
33
34
35 #define WINDOW_SIZE 65536
36
37 REGISTER_PLUGIN(DCOffset)
38
39
40
41
42
43
44
45
46
47 DCOffset::DCOffset(PluginServer *server)
48  : PluginAClient(server)
49 {
50         need_collection = 1;
51         reference = 0;
52 }
53
54 DCOffset::~DCOffset()
55 {
56         delete reference;
57 }
58
59 const char* DCOffset::plugin_title() { return N_("DC Offset"); }
60 int DCOffset::is_realtime() { return 1; }
61
62
63
64 int DCOffset::process_buffer(int64_t size,
65         Samples *buffer,
66         int64_t start_position,
67         int sample_rate)
68 {
69         load_configuration();
70         double *buffer_samples = buffer->get_data();
71         double *reference_samples = !reference ? 0 : reference->get_data();
72
73         if(need_collection)
74         {
75                 if(!reference) {
76                         reference = new Samples(WINDOW_SIZE);
77                         reference_samples = reference->get_data();
78                 }
79                 int64_t collection_start = 0;
80                 if(get_direction() == PLAY_REVERSE)
81                         collection_start += WINDOW_SIZE;
82                 read_samples(reference,
83                         0,
84                         sample_rate,
85                         collection_start,
86                         WINDOW_SIZE);
87                 offset = 0;
88                 for(int i = 0; i < WINDOW_SIZE; i++)
89                 {
90                         offset += reference_samples[i];
91                 }
92                 offset /= WINDOW_SIZE;
93                 need_collection = 0;
94         }
95
96         read_samples(buffer,
97                 0,
98                 sample_rate,
99                 start_position,
100                 size);
101
102         for(int i = 0; i < size; i++)
103         {
104                 buffer_samples[i] -= offset;
105         }
106
107         return 0;
108 }
109
110
111