kopia lustrzana https://github.com/xdsopl/robot36
moved window functions into own files
rodzic
7ce9d44b36
commit
04e68c262f
2
Makefile
2
Makefile
|
@ -22,5 +22,5 @@ clean:
|
||||||
|
|
||||||
encode: encode.o mmap_file.o
|
encode: encode.o mmap_file.o
|
||||||
|
|
||||||
decode: decode.o mmap_file.o pcm.o wav.o alsa.o
|
decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o
|
||||||
|
|
||||||
|
|
43
decode.c
43
decode.c
|
@ -8,6 +8,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "mmap_file.h"
|
#include "mmap_file.h"
|
||||||
#include "pcm.h"
|
#include "pcm.h"
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
float lerp(float a, float b, float x)
|
float lerp(float a, float b, float x)
|
||||||
{
|
{
|
||||||
|
@ -30,48 +31,6 @@ float limit(float min, float max, float x)
|
||||||
return tmp > max ? max : tmp;
|
return tmp > max ? max : tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sinc(float x)
|
|
||||||
{
|
|
||||||
return 0 == x ? 1.0 : sinf(M_PI * x) / (M_PI * x);
|
|
||||||
}
|
|
||||||
float hann(float n, float N)
|
|
||||||
{
|
|
||||||
return 0.5 * (1.0 - cosf(2.0 * M_PI * n / (N - 1.0)));
|
|
||||||
}
|
|
||||||
float hamming(float n, float N)
|
|
||||||
{
|
|
||||||
return 0.54 - 0.46 * cosf(2.0 * M_PI * n / (N - 1.0));
|
|
||||||
}
|
|
||||||
float lanczos(float n, float N)
|
|
||||||
{
|
|
||||||
return sinc(2.0 * n / (N - 1.0) - 1.0);
|
|
||||||
}
|
|
||||||
float gauss(float n, float N)
|
|
||||||
{
|
|
||||||
float o = 0.35;
|
|
||||||
return expf(- 1.0/2.0 * powf((n - (N - 1.0) / 2.0) / (o * (N - 1.0) / 2.0), 2.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
float i0f(float x)
|
|
||||||
{
|
|
||||||
// converges for -3*M_PI:3*M_PI in less than 20 iterations
|
|
||||||
float sum = 1.0, val = 1.0, c = 0.0;
|
|
||||||
for (int n = 1; n < 20; n++) {
|
|
||||||
float tmp = x / (2 * n);
|
|
||||||
val *= tmp * tmp;
|
|
||||||
float y = val - c;
|
|
||||||
float t = sum + y;
|
|
||||||
c = (t - sum) - y;
|
|
||||||
sum = t;
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
float kaiser(float n, float N)
|
|
||||||
{
|
|
||||||
float a = 2.0;
|
|
||||||
return i0f(M_PI * a * sqrtf(1.0 - powf((2.0 * n) / (N - 1.0) - 1.0, 2.0))) / i0f(M_PI * a);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float complex *b;
|
float complex *b;
|
||||||
float *s;
|
float *s;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
|
float sinc(float x)
|
||||||
|
{
|
||||||
|
return 0 == x ? 1.0 : sinf(M_PI * x) / (M_PI * x);
|
||||||
|
}
|
||||||
|
float hann(float n, float N)
|
||||||
|
{
|
||||||
|
return 0.5 * (1.0 - cosf(2.0 * M_PI * n / (N - 1.0)));
|
||||||
|
}
|
||||||
|
float hamming(float n, float N)
|
||||||
|
{
|
||||||
|
return 0.54 - 0.46 * cosf(2.0 * M_PI * n / (N - 1.0));
|
||||||
|
}
|
||||||
|
float lanczos(float n, float N)
|
||||||
|
{
|
||||||
|
return sinc(2.0 * n / (N - 1.0) - 1.0);
|
||||||
|
}
|
||||||
|
float gauss(float n, float N)
|
||||||
|
{
|
||||||
|
float o = 0.35;
|
||||||
|
return expf(- 1.0/2.0 * powf((n - (N - 1.0) / 2.0) / (o * (N - 1.0) / 2.0), 2.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
float i0f(float x)
|
||||||
|
{
|
||||||
|
// converges for -3*M_PI:3*M_PI in less than 20 iterations
|
||||||
|
float sum = 1.0, val = 1.0, c = 0.0;
|
||||||
|
for (int n = 1; n < 20; n++) {
|
||||||
|
float tmp = x / (2 * n);
|
||||||
|
val *= tmp * tmp;
|
||||||
|
float y = val - c;
|
||||||
|
float t = sum + y;
|
||||||
|
c = (t - sum) - y;
|
||||||
|
sum = t;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
float kaiser(float n, float N)
|
||||||
|
{
|
||||||
|
float a = 2.0;
|
||||||
|
return i0f(M_PI * a * sqrtf(1.0 - powf((2.0 * n) / (N - 1.0) - 1.0, 2.0))) / i0f(M_PI * a);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
#ifndef WINDOW_H
|
||||||
|
#define WINDOW_H
|
||||||
|
float sinc(float);
|
||||||
|
float hann(float, float);
|
||||||
|
float hamming(float, float);
|
||||||
|
float lanczos(float, float);
|
||||||
|
float gauss(float, float);
|
||||||
|
float kaiser(float, float);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Ładowanie…
Reference in New Issue