Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation of AudioWindowKaiserBessel #485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analyze_fft1024.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern const int16_t AudioWindowWelch1024[];
extern const int16_t AudioWindowHamming1024[];
extern const int16_t AudioWindowCosine1024[];
extern const int16_t AudioWindowTukey1024[];
extern const int16_t AudioWindowKaiserBessel1024[];
}

class AudioAnalyzeFFT1024 : public AudioStream
Expand Down
1 change: 1 addition & 0 deletions analyze_fft256.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern const int16_t AudioWindowWelch256[];
extern const int16_t AudioWindowHamming256[];
extern const int16_t AudioWindowCosine256[];
extern const int16_t AudioWindowTukey256[];
extern const int16_t AudioWindowKaiserBessel256[];
}

class AudioAnalyzeFFT256 : public AudioStream
Expand Down
178 changes: 178 additions & 0 deletions data_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,141 @@ const int16_t AudioWindowTukey1024[] __attribute__ ((aligned (4))) = {
11, 5, 1, 0,
};

const int16_t AudioWindowKaiserBessel256[] __attribute__ ((aligned (4))) = {
20, 28, 37, 47, 59, 72, 87, 105, 124, 145,
169, 196, 225, 257, 293, 331, 373, 419, 469, 523,
581, 643, 710, 782, 860, 942, 1030, 1124, 1224, 1330,
1442, 1561, 1687, 1819, 1959, 2106, 2261, 2423, 2594, 2772,
2958, 3153, 3357, 3568, 3789, 4018, 4257, 4504, 4760, 5026,
5300, 5584, 5877, 6179, 6490, 6810, 7139, 7477, 7824, 8180,
8544, 8917, 9298, 9687, 10085, 10489, 10902, 11321, 11748, 12181,
12620, 13065, 13516, 13972, 14433, 14899, 15369, 15842, 16319, 16798,
17279, 17763, 18247, 18733, 19218, 19704, 20188, 20671, 21153, 21631,
22107, 22579, 23047, 23511, 23969, 24421, 24866, 25305, 25736, 26159,
26573, 26978, 27373, 27757, 28131, 28494, 28844, 29183, 29508, 29820,
30119, 30403, 30673, 30928, 31167, 31391, 31599, 31791, 31966, 32125,
32266, 32391, 32497, 32587, 32658, 32712, 32748, 32766, 32766, 32748,
32712, 32658, 32587, 32497, 32391, 32266, 32125, 31966, 31791, 31599,
31391, 31167, 30928, 30673, 30403, 30119, 29820, 29508, 29183, 28844,
28494, 28131, 27757, 27373, 26978, 26573, 26159, 25736, 25305, 24866,
24421, 23969, 23511, 23047, 22579, 22107, 21631, 21153, 20671, 20188,
19704, 19218, 18733, 18247, 17763, 17279, 16798, 16319, 15842, 15369,
14899, 14433, 13972, 13516, 13065, 12620, 12181, 11748, 11321, 10902,
10489, 10085, 9687, 9298, 8917, 8544, 8180, 7824, 7477, 7139,
6810, 6490, 6179, 5877, 5584, 5300, 5026, 4760, 4504, 4257,
4018, 3789, 3568, 3357, 3153, 2958, 2772, 2594, 2423, 2261,
2106, 1959, 1819, 1687, 1561, 1442, 1330, 1224, 1124, 1030,
942, 860, 782, 710, 643, 581, 523, 469, 419, 373,
331, 293, 257, 225, 196, 169, 145, 124, 105, 87,
72, 59, 47, 37, 28, 20
};

const int16_t AudioWindowKaiserBessel1024[] __attribute__ ((aligned (4))) = {
20, 22, 24, 26, 28, 30, 32, 34, 36, 39,
41, 44, 47, 49, 52, 55, 58, 62, 65, 68,
72, 75, 79, 83, 87, 91, 95, 100, 104, 109,
113, 118, 123, 128, 134, 139, 145, 150, 156, 162,
169, 175, 181, 188, 195, 202, 209, 217, 224, 232,
240, 248, 256, 265, 273, 282, 291, 300, 310, 320,
330, 340, 350, 361, 371, 382, 394, 405, 417, 429,
441, 453, 466, 479, 492, 506, 520, 534, 548, 562,
577, 592, 608, 623, 639, 655, 672, 689, 706, 723,
741, 759, 777, 796, 815, 834, 854, 874, 894, 915,
936, 957, 979, 1001, 1023, 1046, 1069, 1093, 1117, 1141,
1165, 1190, 1216, 1241, 1267, 1294, 1321, 1348, 1376, 1404,
1432, 1461, 1490, 1520, 1550, 1581, 1611, 1643, 1675, 1707,
1740, 1773, 1806, 1840, 1875, 1910, 1945, 1981, 2017, 2054,
2091, 2129, 2167, 2205, 2244, 2284, 2324, 2364, 2405, 2447,
2489, 2531, 2574, 2618, 2662, 2706, 2751, 2797, 2843, 2889,
2936, 2984, 3032, 3080, 3129, 3179, 3229, 3280, 3331, 3383,
3435, 3488, 3541, 3595, 3650, 3705, 3760, 3816, 3873, 3930,
3988, 4046, 4105, 4164, 4224, 4285, 4346, 4407, 4469, 4532,
4595, 4659, 4724, 4789, 4854, 4920, 4987, 5054, 5122, 5190,
5259, 5329, 5399, 5470, 5541, 5613, 5685, 5758, 5831, 5906,
5980, 6055, 6131, 6207, 6284, 6362, 6440, 6518, 6598, 6677,
6758, 6839, 6920, 7002, 7084, 7168, 7251, 7335, 7420, 7505,
7591, 7678, 7765, 7852, 7940, 8029, 8118, 8207, 8298, 8388,
8480, 8571, 8664, 8756, 8850, 8944, 9038, 9133, 9228, 9324,
9421, 9517, 9615, 9713, 9811, 9910, 10009, 10109, 10210, 10310,
10412, 10513, 10616, 10718, 10821, 10925, 11029, 11133, 11238, 11343,
11449, 11555, 11662, 11769, 11876, 11984, 12092, 12201, 12310, 12419,
12529, 12639, 12750, 12861, 12972, 13084, 13196, 13308, 13420, 13533,
13647, 13760, 13874, 13988, 14103, 14218, 14333, 14448, 14564, 14680,
14796, 14913, 15030, 15146, 15264, 15381, 15499, 15617, 15735, 15853,
15972, 16090, 16209, 16328, 16448, 16567, 16687, 16806, 16926, 17046,
17166, 17286, 17407, 17527, 17648, 17768, 17889, 18010, 18131, 18251,
18372, 18493, 18614, 18735, 18856, 18978, 19099, 19220, 19341, 19462,
19583, 19704, 19824, 19945, 20066, 20187, 20307, 20428, 20548, 20668,
20789, 20909, 21029, 21148, 21268, 21387, 21507, 21626, 21745, 21863,
21982, 22100, 22218, 22336, 22454, 22571, 22688, 22805, 22922, 23038,
23154, 23269, 23385, 23500, 23615, 23729, 23843, 23957, 24070, 24183,
24295, 24408, 24519, 24631, 24742, 24852, 24962, 25072, 25181, 25290,
25398, 25506, 25613, 25720, 25826, 25932, 26037, 26142, 26246, 26349,
26452, 26555, 26657, 26758, 26859, 26959, 27058, 27157, 27256, 27353,
27450, 27547, 27642, 27737, 27832, 27925, 28018, 28111, 28202, 28293,
28383, 28473, 28562, 28650, 28737, 28823, 28909, 28994, 29078, 29161,
29244, 29326, 29407, 29487, 29566, 29644, 29722, 29799, 29875, 29950,
30024, 30097, 30170, 30242, 30312, 30382, 30451, 30519, 30586, 30652,
30717, 30782, 30845, 30908, 30969, 31030, 31089, 31148, 31205, 31262,
31318, 31372, 31426, 31479, 31531, 31581, 31631, 31680, 31727, 31774,
31820, 31864, 31908, 31950, 31992, 32032, 32072, 32110, 32147, 32183,
32219, 32253, 32286, 32318, 32348, 32378, 32407, 32435, 32461, 32487,
32511, 32534, 32556, 32578, 32598, 32616, 32634, 32651, 32666, 32681,
32694, 32707, 32718, 32728, 32737, 32744, 32751, 32757, 32761, 32765,
32767, 32767, 32767, 32767, 32765, 32761, 32757, 32751, 32744, 32737,
32728, 32718, 32707, 32694, 32681, 32666, 32651, 32634, 32616, 32598,
32578, 32556, 32534, 32511, 32487, 32461, 32435, 32407, 32378, 32348,
32318, 32286, 32253, 32219, 32183, 32147, 32110, 32072, 32032, 31992,
31950, 31908, 31864, 31820, 31774, 31727, 31680, 31631, 31581, 31531,
31479, 31426, 31372, 31318, 31262, 31205, 31148, 31089, 31030, 30969,
30908, 30845, 30782, 30717, 30652, 30586, 30519, 30451, 30382, 30312,
30242, 30170, 30097, 30024, 29950, 29875, 29799, 29722, 29644, 29566,
29487, 29407, 29326, 29244, 29161, 29078, 28994, 28909, 28823, 28737,
28650, 28562, 28473, 28383, 28293, 28202, 28111, 28018, 27925, 27832,
27737, 27642, 27547, 27450, 27353, 27256, 27157, 27058, 26959, 26859,
26758, 26657, 26555, 26452, 26349, 26246, 26142, 26037, 25932, 25826,
25720, 25613, 25506, 25398, 25290, 25181, 25072, 24962, 24852, 24742,
24631, 24519, 24408, 24295, 24183, 24070, 23957, 23843, 23729, 23615,
23500, 23385, 23269, 23154, 23038, 22922, 22805, 22688, 22571, 22454,
22336, 22218, 22100, 21982, 21863, 21745, 21626, 21507, 21387, 21268,
21148, 21029, 20909, 20789, 20668, 20548, 20428, 20307, 20187, 20066,
19945, 19824, 19704, 19583, 19462, 19341, 19220, 19099, 18978, 18856,
18735, 18614, 18493, 18372, 18251, 18131, 18010, 17889, 17768, 17648,
17527, 17407, 17286, 17166, 17046, 16926, 16806, 16687, 16567, 16448,
16328, 16209, 16090, 15972, 15853, 15735, 15617, 15499, 15381, 15264,
15146, 15030, 14913, 14796, 14680, 14564, 14448, 14333, 14218, 14103,
13988, 13874, 13760, 13647, 13533, 13420, 13308, 13196, 13084, 12972,
12861, 12750, 12639, 12529, 12419, 12310, 12201, 12092, 11984, 11876,
11769, 11662, 11555, 11449, 11343, 11238, 11133, 11029, 10925, 10821,
10718, 10616, 10513, 10412, 10310, 10210, 10109, 10009, 9910, 9811,
9713, 9615, 9517, 9421, 9324, 9228, 9133, 9038, 8944, 8850,
8756, 8664, 8571, 8480, 8388, 8298, 8207, 8118, 8029, 7940,
7852, 7765, 7678, 7591, 7505, 7420, 7335, 7251, 7168, 7084,
7002, 6920, 6839, 6758, 6677, 6598, 6518, 6440, 6362, 6284,
6207, 6131, 6055, 5980, 5906, 5831, 5758, 5685, 5613, 5541,
5470, 5399, 5329, 5259, 5190, 5122, 5054, 4987, 4920, 4854,
4789, 4724, 4659, 4595, 4532, 4469, 4407, 4346, 4285, 4224,
4164, 4105, 4046, 3988, 3930, 3873, 3816, 3760, 3705, 3650,
3595, 3541, 3488, 3435, 3383, 3331, 3280, 3229, 3179, 3129,
3080, 3032, 2984, 2936, 2889, 2843, 2797, 2751, 2706, 2662,
2618, 2574, 2531, 2489, 2447, 2405, 2364, 2324, 2284, 2244,
2205, 2167, 2129, 2091, 2054, 2017, 1981, 1945, 1910, 1875,
1840, 1806, 1773, 1740, 1707, 1675, 1643, 1611, 1581, 1550,
1520, 1490, 1461, 1432, 1404, 1376, 1348, 1321, 1294, 1267,
1241, 1216, 1190, 1165, 1141, 1117, 1093, 1069, 1046, 1023,
1001, 979, 957, 936, 915, 894, 874, 854, 834, 815,
796, 777, 759, 741, 723, 706, 689, 672, 655, 639,
623, 608, 592, 577, 562, 548, 534, 520, 506, 492,
479, 466, 453, 441, 429, 417, 405, 394, 382, 371,
361, 350, 340, 330, 320, 310, 300, 291, 282, 273,
265, 256, 248, 240, 232, 224, 217, 209, 202, 195,
188, 181, 175, 169, 162, 156, 150, 145, 139, 134,
128, 123, 118, 113, 109, 104, 100, 95, 91, 87,
83, 79, 75, 72, 68, 65, 62, 58, 55, 52,
49, 47, 44, 41, 39, 36, 34, 32, 30, 28,
26, 24, 22, 20
};


/*
#! /usr/bin/perl
Expand Down Expand Up @@ -1616,3 +1751,46 @@ for ($i=0; $i < $len; $i++) {
print "\n" unless ($len % 10) == 9;
print "};\n";
*/

/*
#! /usr/bin/python

import numpy
import scipy.special

"https://en.wikipedia.org/wiki/Window_function"

N=255

scale = 32767.4 / 0.999931

def transform(x):
x *= 32768
x[x>32767] = 32767
return (x+0.5).astype(numpy.int16)

def kaiser(x, len, a=3):
a = a * numpy.pi
x = 2*x/(len-1)-1
return scipy.special.i0(a * numpy.sqrt(1-x*x)) / scipy.special.i0(a)

if __name__ == "__main__":
len = 1024
cols = 10
name = "KaiserBessel"
func = kaiser
kwargs = {'a': 3}

y = func(numpy.arange(0,len), len, **kwargs)
y = transform(y)

print(f"const int16_t AudioWindow{name}{len}[] __attribute__ ((aligned (4))) = {{")

tail = ","
for i in range(0, len, cols):
if i+cols >= len:
tail = ""
print(",".join(map("{:6d}".format,y[i:i+cols])) + tail)

print("};")
*/
2 changes: 2 additions & 0 deletions gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4933,6 +4933,7 @@ <h3>Notes</h3>
<li><span class=literal>AudioWindowHamming256</span></li>
<li><span class=literal>AudioWindowCosine256</span></li>
<li><span class=literal>AudioWindowTukey256</span></li>
<li><span class=literal>AudioWindowKaiserBessel256</span></li>
</ul>
</p>
</script>
Expand Down Expand Up @@ -5000,6 +5001,7 @@ <h3>Notes</h3>
<li><span class=literal>AudioWindowHamming1024</span></li>
<li><span class=literal>AudioWindowCosine1024</span></li>
<li><span class=literal>AudioWindowTukey1024</span></li>
scrain777 marked this conversation as resolved.
Show resolved Hide resolved
<li><span class=literal>AudioWindowKaiserBessel1024</span></li>
</ul>
</p>
<p>1024 point FFT has a peak CPU usage of approx 52% on Teensy 3.1.
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ AudioWindowWelch256 LITERAL1
AudioWindowHamming256 LITERAL1
AudioWindowCosine256 LITERAL1
AudioWindowTukey256 LITERAL1
AudioWindowKaiserBessel256 LITERAL1

FILTER_LOPASS LITERAL1
FILTER_HIPASS LITERAL1
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": "sound, audio, FFT, filter, effect",
"description": "Teensy Audio Library",
"url": "http://www.pjrc.com/teensy/td_libs_Audio.html",
"version": "1.3",
"version": "1.4",
"export": {
"exclude": [
"gui",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Audio
version=1.3
version=1.4
author=Paul Stoffregen
maintainer=Paul Stoffregen
sentence=Teensy Audio Library - Flexible, High Quality Audio Processing
Expand Down