#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
Classes | |
struct | complex |
struct | filter |
Macros | |
#define | MYMATH_H |
#define | RTOLS_H |
#define | RTOLS_ERROR_GENERAL -1 |
#define | RTOLS_ERROR_RESTART_FAILED -2 |
#define | RTOLS_ERROR_SHARED_INPUT -4 |
#define | RTOLS_ERROR_UNSHARED_INPUT -8 |
#define | RTOLS_SHARED_NONE 0 |
#define | RTOLS_SHARED_FFT 1 |
#define | RTOLS_SHARED_INPUT 2 |
#define | RTOLS_SHARED_FILTER 4 |
#define | RTOLS_SHARED_OUTPUT_ADD 8 |
#define | TOLS_H |
#define | TWOPI 6.28318530717959 |
#define | SWAP(a, b) temp = (a); (a) = (b); (b) = temp |
#define | SWAP(a, b) temp = (a); (a) = (b); (b) = temp |
Typedefs | |
typedef double | real |
#define MYMATH_H |
#define RTOLS_ERROR_GENERAL -1 |
#define RTOLS_ERROR_RESTART_FAILED -2 |
#define RTOLS_ERROR_SHARED_INPUT -4 |
#define RTOLS_ERROR_UNSHARED_INPUT -8 |
#define RTOLS_H |
#define RTOLS_SHARED_FFT 1 |
#define RTOLS_SHARED_FILTER 4 |
#define RTOLS_SHARED_INPUT 2 |
#define RTOLS_SHARED_NONE 0 |
#define RTOLS_SHARED_OUTPUT_ADD 8 |
#define SWAP | ( | a, | |
b | |||
) | temp = (a); (a) = (b); (b) = temp |
#define SWAP | ( | a, | |
b | |||
) | temp = (a); (a) = (b); (b) = temp |
#define TOLS_H |
#define TWOPI 6.28318530717959 |
bit reversal
i | number with bits |
m | number of total bits (=ld of size of fft n=2^m). |
conversion from complex to real
in | complex input |
out | real output |
len | buffer lengths |
mode | uses Re(z) if 0, Im(z) if 1, |z| if 2, arg(z) if 3 |
frequency-domain convolution
x | [in] time-domain signal x, length 2^(m-1) |
h | [in] impulse response h, length 2^(m-1) |
y | [out] convolved time-domain signal y = x ** h, length 2^m |
wf | phase factors for fft |
wf | phase factors for inverse fft |
m | ld of fft size |
complete in-place fft
x | [in/out] time/freq |
w | phase factors for transformation |
fft core routine. (must be prepended by a permutation)
[in/out] | time/freq domain vector |
direction | (forward = 1, backward = -1) |
size | of fft (should be 2^N) |
complete fft preserving input
x | [in] time |
y | [out] freq |
w | phase factors for transformation |
complete in-place fft with reversed half-frame order
x | [in/out] time (with reversed half-frame order)/freq |
w | phase factors for transformation |
calculate phase factors
w | [out] array of phase factors (fft size / 2) |
idir | direction (forward = 1, backward = -1) |
size | of fft |
frequency-domain convolution with internal weights calculation
x | [in] time-domain signal x, length 2^(m-1) plus zero padding to length 2^m |
h | [in] impulse response h, length 2^(m-1) plus zero padding to length 2^m |
y | [out] convolved time-domain signal y = x ** h, length 2^m |
m | ld of fft size |
complete in-place ifft
x | [in/out] freq/time |
w | phase factors for inverse transformation |
complete ifft preserving input
x | [in] freq |
y | [out] time |
w | phase factors for transformation |
complex number from magnitude and phase
mag | magnitude |
permutation from data order to butterfly order,
x | [in/out] data |
m | ld of fft size |
permutation from data order to butterfly order into provided array.
x | [in] data |
y | [out] data |
m | ld of fft size |
permutation from data order to butterfly order using reversed half- frames
x | [in/out] data whose actual order is x[2^(m-1):2^m-1]x[0:2^(m-1)] |
m | ld of fft size |
permutation from data order to butterfly order using reversed half- frames, copies into the provided array.
x | [in/out] data whose actual order is x[2^(m-1):2^m-1]x[0:2^(m-1)] |
m | ld of fft size |
void printbits | ( | int | n | ) |
print 8 lowest significant bits
conversion from real to complex
in | real input |
out | complex output |
len | buffer lengths |
deallocates the internal filter memory (inbuf and outbuf must be freed).
filter | to be destoyed |
time-partitioned OLS convolution, streaming mode.
Triggers the algorithm that a new frame has been written into inbuf and last result will be read from outbuf. Important: Do not use for sharing inputs between filters, otherwise this is ignored and -4 returned.
filters | the filters to be triggered. |
inbuf | real input buffer where the frame is read from (size 2^(m-1) = fftsize/2 expected). After calling rtols_finish and the returned number of frames, inbuf is ignored (as there is no signal left). |
outbuf | real output buffer where the result is written to (size 2^(m-1) expected). If not the full buffer is filled with signal, it is zero-padded. |
int rtols_filter_sigshare | ( | filter * | filters, |
int | nfilt, | ||
real * | inbuf, | ||
real ** | outbuf, | ||
int | outoffset | ||
) |
time-partitioned OLS convolution, streaming mode.
Triggers the algorithm that a new frame has been written into inbuf and last result will be read from outbuf.
filters | the filters to be triggered. |
nfilt | number of filters (and output buffers) |
inbuf | real input buffer where the frame is read from (size 2^(m-1) = fftsize/2 expected). After calling rtols_finish and the returned number of frames, inbuf is ignored (as there is no signal left). |
outbuf | real output buffers where the result is written to (size 2^(m-1) expected). |
outoffset | offset to each output buffer (internal: pointer addition on each single buffer) |
time-partitioned OLS convolution, streaming mode.
Updates the filter coefficients now
h | new impulse response |
hlen | length of new IR |
transition | number of frames that the IR will be crossfaded from the old one (frequency-domain interpolation) |
time-partitioned OLS convolution, streaming mode.
finishes the filter operation. Afterwards, the filter can be reused by calling rtols_restart. If the filter is shared by its input, finishes all filters that belong to the signal.
filter | filter to be finished |
len | the length of the input signal that remains to be filtered |
time-partitioned OLS convolution, streaming mode.
Prepares the filtering by allocating internal memory of a filter and setting up the transformations. The input and output buffers are complex arrays inbuf and outbuf. Therefore, the streaming framework that calls trigger must call the appropriate conversion methods rtols_*2*(in, out, len). TODO: fix this to avoid this inner-loop conversion.
In the system, two internal i/o buffers of type complex are generated, one of size 2^m for the input data, and one of size 2^(m-1) for the output data.
filter | the structure that contains all information for filtering |
h | impulse response |
hlen | length of h |
m | ld of fft size used to partition the signals, note that input and output buffers are fftsize/2 |
int rtols_prepare_filtshare | ( | filter * | filt, |
complex * | wf, | ||
complex * | wi, | ||
complex ** | HH, | ||
int | R, | ||
int | hlen, | ||
int | m | ||
) |
time-partitioned OLS convolution, streaming mode with shared resources for fft and filter transfer function.
Prepares the filtering by allocating internal memory of a filter and setting up the transformations. The input and output buffers are complex arrays inbuf and outbuf. Therefore, the streaming framework that calls trigger must call the appropriate conversion methods rtols_*2*(in, out, len). TODO: fix this to avoid this inner-loop conversion.
In the system, two internal i/o buffers of type complex are generated, one of size 2^m for the input data, and one of size 2^(m-1) for the output data.
filter | the structure that contains all information for filtering |
wf | forward fft structure |
wi | inverse fft structure |
HH | filter transfer functions (frame spectra), size R x 2^m |
R | number of filter frames |
hlen | original length of filter impulse response |
m | ld of fft size used to partition the signals, note that input and output buffers are fftsize/2 |
int rtols_prepare_sigshare | ( | filter * | filt, |
complex * | h, | ||
int | hlen, | ||
complex * | wf, | ||
complex * | wi, | ||
complex ** | XX, | ||
int | R, | ||
int | m, | ||
int | addout | ||
) |
time-partitioned OLS convolution, streaming mode with shared resources for fft and input buffer. Sharing the input buffer requires that the rtols_filter_sigshare method be used instead of rtols_filter, which will return -1 and ignore the call.
Prepares the filtering by allocating internal memory of a filter and setting up the transformations. The input and output buffers are complex arrays inbuf and outbuf. Therefore, the streaming framework that calls trigger must call the appropriate conversion methods rtols_*2*(in, out, len). TODO: fix this to avoid this inner-loop conversion.
In the system, two internal i/o buffers of type complex are generated, one of size 2^m for the input data, and one of size 2^(m-1) for the output data.
filter | the structure that contains all information for filtering |
h | impulse response |
hlen | length of h |
wf | forward fft structure |
wi | inverse fft structure |
XX | circular frame spectrum buffer of size R x 2^m, R is checked if it is compatible with hlen: R = ceil(hlen * 2^(-m+1)), if not, -2 as the error code is returned. |
m | ld of fft size used to partition the signals, note that input and output buffers are fftsize/2 |
addout | 0 if outgoing signals overwrite the output buffer, 1 if they are added. |
after a call to rtols_finish, the filter is restarted by a new signal at its input buffer.
filter | the filter to be reinitialised |
time-domain convolution
x | [in] time-domain signal x |
xlen | length of x |
h | [in] impulse response h |
hlen | length of h |
y | [out] convolved time-domain signal y = x ** h, length ylen = xlen + hlen - 1 |
time-partitioned OLS convolution
x | input signal (time domain) |
xlen | length of x |
h | impulse response |
hlen | length of h |
y | output (length >= xlen + hlen) |
m | ld of fft size used to partition the signals. |