1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/**
* Smarc
*
* Copyright (c) 2009-2011 Institut Télécom - Télécom Paristech
* Télécom ParisTech / dept. TSI
*
* Authors : Benoit Mathieu, Jacques Prado
*
* This file is part of Smarc.
*
* Smarc is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Smarc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "polyfilt.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void polyfiltLM(struct PSFilter* pfilt, struct PSState* pstate,
const double* signal, int signalLen, int* nbRead, double* output,
int outputLen, int* nbWritten) {
const int M = pfilt->M;
const int L = pfilt->L;
const int K = pfilt->K;
int signalPos = 0;
int outPos = 0;
int phase = pstate->phase;
// skip first sample for delays
if (pstate->skip>0)
{
const int maxAdvance = (M + L - 1) / L;
while (pstate->skip>0 && ((signalPos+maxAdvance)<signalLen)) {
pstate->skip--;
phase += M;
signalPos += phase / L;
phase = phase % L;
}
}
// process filtering
while ((signalPos+K<=signalLen) && (outPos<outputLen))
{
// compute value
output[outPos++] = filter(pfilt->filters + phase*K,signal + signalPos, K);
// consume samples
phase += M;
signalPos += phase / L;
phase = phase % L;
}
// report state values
pstate->phase = phase;
*nbRead = signalPos;
*nbWritten = outPos;
}
void polyfiltM(struct PSFilter* pfilt, struct PSState* pstate,
const double* SMARC_RESTRICT signal, const int signalLen, int* SMARC_RESTRICT nbConsume,
double* SMARC_RESTRICT output, const int outputLen, int* SMARC_RESTRICT nbWritten) {
const int M = pfilt->M;
const int K = pfilt->K;
const double* filt = pfilt->filters;
int signalPos = 0;
int outPos = 0;
// skip first sample for delays
while (pstate->skip>0 && ((signalPos+M)<signalLen)) {
pstate->skip--;
signalPos += M;
}
// process filtering
while (((signalPos+K)<=signalLen) && (outPos<outputLen))
{
// compute value
// double v = 0.0;
// const double* inPtr = signal + signalPos;
// for (int k=0;k<K;k++)
// v += inPtr[k] * filt[k];
// output[outPos++] = v;
output[outPos++] = filter(filt,signal+signalPos,K);
// consume samples
signalPos += M;
}
// report state values
*nbWritten = outPos;
*nbConsume = signalPos;
}
void polyfiltL(struct PSFilter* pfilt, struct PSState* pstate,
const double* signal, int signalLen, int* nbRead, double* output,
int outputLen, int* nbWritten) {
const int L = pfilt->L;
const int K = pfilt->K;
int signalPos = 0;
int outPos = 0;
int phase = pstate->phase;
// skip first sample for delays
while (pstate->skip>0 && signalPos<signalLen) {
pstate->skip--;
phase++;
if (phase==L) {
signalPos++;
phase = 0;
}
}
// compute first output to reach phase 0
while (signalPos+K<=signalLen && outPos<outputLen)
{
// double v=0;
// const double* inPtr = signal + signalPos;
// const double* filtPtr = pfilt->filters + phase*K;
// for (int k=0;k<K;++k)
// v += inPtr[k] * filtPtr[k];
// output[outPos++] = v;
output[outPos++] = filter(pfilt->filters + phase*K, signal+signalPos, K);
phase++;
if (phase==L) {
signalPos++;
phase=0;
}
}
// report state values
pstate->phase = phase;
*nbRead = signalPos;
*nbWritten = outPos;
}
|