4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
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.
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.
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
28 #include "transportque.h"
35 #define WINDOW_SIZE 65536
37 REGISTER_PLUGIN(DCOffset)
47 DCOffset::DCOffset(PluginServer *server)
48 : PluginAClient(server)
59 const char* DCOffset::plugin_title() { return _("DC Offset"); }
60 int DCOffset::is_realtime() { return 1; }
64 int DCOffset::process_buffer(int64_t size,
66 int64_t start_position,
70 double *buffer_samples = buffer->get_data();
71 double *reference_samples = !reference ? 0 : reference->get_data();
76 reference = new Samples(WINDOW_SIZE);
77 reference_samples = reference->get_data();
79 int64_t collection_start = 0;
80 if(get_direction() == PLAY_REVERSE)
81 collection_start += WINDOW_SIZE;
82 read_samples(reference,
88 for(int i = 0; i < WINDOW_SIZE; i++)
90 offset += reference_samples[i];
92 offset /= WINDOW_SIZE;
102 for(int i = 0; i < size; i++)
104 buffer_samples[i] -= offset;