2
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
2
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
5
* This program is free software; you can redistribute it and/or modify
31
31
#include "dcblocker.h"
33
DcBlocker::DcBlocker() : y_(0), x_(0), xm1_(0), ym1_(0)
33
DcBlocker::DcBlocker(unsigned channels /* = 1 */)
34
: states(channels, (struct StreamState){0, 0, 0, 0})
36
37
void DcBlocker::reset()
44
void DcBlocker::process(SFLDataFormat *out, SFLDataFormat *in, int samples)
46
for (int i = 0; i < samples; ++i) {
49
y_ = (SFLDataFormat) ((float) x_ - (float) xm1_ + 0.9999 * (float) y_);
39
states.assign(states.size(), (struct StreamState){0, 0, 0, 0});
42
void DcBlocker::doProcess(SFLAudioSample *out, SFLAudioSample *in, unsigned samples, struct StreamState * state)
44
for (unsigned i = 0; i < samples; ++i) {
48
state->y_ = (SFLAudioSample) ((float) state->x_ - (float) state->xm1_ + 0.9999 * (float) state->y_);
49
state->xm1_ = state->x_;
50
state->ym1_ = state->y_;
56
void DcBlocker::process(SFLAudioSample *out, SFLAudioSample *in, int samples)
58
if(out == NULL or in == NULL or samples == 0) return;
59
doProcess(out, in, samples, &states[0]);
62
void DcBlocker::process(AudioBuffer& buf)
64
const size_t chans = buf.channels();
65
const size_t samples = buf.frames();
66
if(chans > states.size())
67
states.resize(buf.channels(), (struct StreamState){0, 0, 0, 0});
70
for(i=0; i<chans; i++) {
71
SFLAudioSample *chan = buf.getChannel(i)->data();
72
doProcess(chan, chan, samples, &states[i]);