~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/src/audio/dcblocker.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
30
30
 
31
31
#include "dcblocker.h"
32
32
 
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})
34
35
{}
35
36
 
36
37
void DcBlocker::reset()
37
38
{
38
 
    y_ = 0;
39
 
    x_ = 0;
40
 
    xm1_ = 0;
41
 
    ym1_ = 0;
42
 
}
43
 
 
44
 
void DcBlocker::process(SFLDataFormat *out, SFLDataFormat *in, int samples)
45
 
{
46
 
    for (int i = 0; i < samples; ++i) {
47
 
        x_ = in[i];
48
 
 
49
 
        y_ = (SFLDataFormat) ((float) x_ - (float) xm1_ + 0.9999 * (float) y_);
50
 
        xm1_ = x_;
51
 
        ym1_ = y_;
52
 
 
53
 
        out[i] = y_;
 
39
    states.assign(states.size(), (struct StreamState){0, 0, 0, 0});
 
40
}
 
41
 
 
42
void DcBlocker::doProcess(SFLAudioSample *out, SFLAudioSample *in, unsigned samples, struct StreamState * state)
 
43
{
 
44
    for (unsigned i = 0; i < samples; ++i) {
 
45
        state->x_ = in[i];
 
46
 
 
47
 
 
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_;
 
51
 
 
52
        out[i] = state->y_;
 
53
    }
 
54
}
 
55
 
 
56
void DcBlocker::process(SFLAudioSample *out, SFLAudioSample *in, int samples)
 
57
{
 
58
    if(out == NULL or in == NULL or samples == 0) return;
 
59
    doProcess(out, in, samples, &states[0]);
 
60
}
 
61
 
 
62
void DcBlocker::process(AudioBuffer& buf)
 
63
{
 
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});
 
68
 
 
69
    unsigned i;
 
70
    for(i=0; i<chans; i++) {
 
71
        SFLAudioSample *chan = buf.getChannel(i)->data();
 
72
        doProcess(chan, chan, samples, &states[i]);
54
73
    }
55
74
}
56
75