SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
MedianFilter.hxx
Go to the documentation of this file.
1
/*
2
Copyright (c) 2014, 2025 Matthew H. Reilly (kb1vc)
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
7
met:
8
9
Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in
13
the documentation and/or other materials provided with the
14
distribution.
15
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*/
28
#pragma once
29
37
38
#include <fstream>
39
#include <complex>
40
#include <stdio.h>
41
#include <fcntl.h>
42
#include <sys/types.h>
43
#include <sys/stat.h>
44
#include <fftw3.h>
45
namespace
SoDa
{
47
template
<
typename
T>
class
MedianFilter3
{
48
public
:
49
50
53
MedianFilter3
() {
54
a
=
b
= (T) (0.0);
55
}
56
66
unsigned
int
apply
(T * inbuf, T * outbuf,
unsigned
int
len,
float
outgain = 1.0)
67
{
68
unsigned
int
i;
69
for
(i = 0; i < len; i++) {
70
outbuf[i] = outgain *
findMedian
(inbuf[i]);
71
}
72
return
0;
73
}
74
75
private
:
82
T
findMedian
(T v) {
83
T ret;
84
if
(v >
a
) {
85
if
(v <
b
) ret = v;
86
else
ret = (
a
>
b
) ?
a
:
b
;
87
}
88
else
{
89
if
(v <
b
) ret = (
a
>
b
) ?
b
:
a
;
90
else
ret = v;
91
}
92
a
=
b
;
93
b
= v;
94
95
return
ret;
96
}
97
98
T
a
;
99
T
b
;
100
};
101
}
102
SoDa::MedianFilter3::findMedian
T findMedian(T v)
find the median of the supplied value vs.
Definition
MedianFilter.hxx:82
SoDa::MedianFilter3::a
T a
storage for the value-before-last
Definition
MedianFilter.hxx:98
SoDa::MedianFilter3::b
T b
storage for the previous value
Definition
MedianFilter.hxx:99
SoDa::MedianFilter3::MedianFilter3
MedianFilter3()
constructor no parameters
Definition
MedianFilter.hxx:53
SoDa::MedianFilter3::apply
unsigned int apply(T *inbuf, T *outbuf, unsigned int len, float outgain=1.0)
Apply the 3 sample median filter to an input vector.
Definition
MedianFilter.hxx:66
SoDa
Definition
AudioIfc.hxx:34
src
MedianFilter.hxx
Generated on
for SoDaRadio-12.2.0-cut_dependencies:6c82803 by
1.14.0