Skip to content

Commit 7b2adcd

Browse files
authored
Merge pull request #284 from sensorium/fix/Tables
Fix/tables
2 parents b21d60c + 860c186 commit 7b2adcd

39 files changed

+7423
-7021
lines changed

extras/python/make_standard_tables.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/python3
2+
3+
"""
4+
* make_standard_tables.py
5+
*
6+
* This file is part of Mozzi.
7+
*
8+
* Copyright 2012-2024 Thomas Combriat and the Mozzi Team
9+
*
10+
* Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
11+
*
12+
* This file allows to regenerate the standard tables of Mozzi (sin, cos, cosphase, triangle and saw)
13+
"""
14+
15+
import numpy as np # numerics
16+
import textwrap
17+
import os as os
18+
#import math as math # math
19+
20+
folder = ".."+os.sep+".."+os.sep+"tables" + os.sep
21+
22+
def write_header(fout, samplerate,name):
23+
tablename = name.upper()+str(samplerate)
24+
fout.write('#ifndef ' + tablename + '_H_' + '\n')
25+
fout.write('#define ' + tablename + '_H_' + '\n \n')
26+
fout.write("/**\n This table is part of Mozzi\n Generated with extras/python/make_standard_tables.py\n*/\n\n")
27+
fout.write('#include <Arduino.h>'+'\n')
28+
fout.write('#include "mozzi_pgmspace.h"'+'\n \n')
29+
fout.write('#define ' + tablename + '_NUM_CELLS '+ str(samplerate)+'\n')
30+
fout.write('#define ' + tablename + '_SAMPLERATE '+ str(samplerate)+'\n \n')
31+
fout.write('CONSTTABLE_STORAGE(int8_t) ' + tablename + '_DATA [] = {\n')
32+
33+
def write_footer(fout,samplerate,name):
34+
tablename = name.upper()+str(samplerate)
35+
fout.write('\n }; \n \n #endif /* ' + tablename + '_H_ */\n')
36+
37+
38+
39+
40+
41+
#### SIN
42+
43+
SR = [256,512,1024,2048,4096,8192]
44+
name = "sin"
45+
46+
for s in SR:
47+
fout = open(folder+name+str(s)+"_int8.h","w")
48+
49+
write_header(fout,s,name)
50+
51+
t = np.linspace(0,2*np.pi,num=s,endpoint=False)
52+
outstring=""
53+
for i in range(s):
54+
outstring+=str(round(127*np.sin(t[i])))+", "
55+
56+
outstring = textwrap.fill(outstring,80)
57+
fout.write(outstring)
58+
write_footer(fout,s,name)
59+
fout.close()
60+
61+
print("Wrote:"+name.upper()+str(s)+"_INT8")
62+
63+
64+
#### COS
65+
# Note that this is actually a negative cos
66+
67+
SR = [256,512,1024,2048,4096,8192]
68+
name = "cos"
69+
70+
for s in SR:
71+
fout = open(folder+name+str(s)+"_int8.h","w")
72+
73+
write_header(fout,s,name)
74+
75+
t = np.linspace(0,2*np.pi,num=s,endpoint=False)
76+
outstring=""
77+
for i in range(s):
78+
outstring+=str(round(-127*np.cos(t[i])))+", "
79+
80+
outstring = textwrap.fill(outstring,80)
81+
fout.write(outstring)
82+
write_footer(fout,s,name)
83+
fout.close()
84+
85+
print("Wrote:"+name.upper()+str(s)+"_INT8")
86+
87+
88+
#### COSPHASE
89+
90+
SR = [256,2048,8192]
91+
name = "cosphase"
92+
93+
for s in SR:
94+
fout = open(folder+name+str(s)+"_int8.h","w")
95+
96+
write_header(fout,s,name)
97+
98+
t = np.linspace(0,2*np.pi,num=s,endpoint=False)
99+
outstring=""
100+
for i in range(s):
101+
outstring+=str(round(127*np.cos(t[i])))+", "
102+
103+
outstring = textwrap.fill(outstring,80)
104+
fout.write(outstring)
105+
write_footer(fout,s,name)
106+
fout.close()
107+
108+
print("Wrote:"+name.upper()+str(s)+"_INT8")
109+
110+
111+
112+
113+
#### TRIANGLE
114+
115+
SR = [512,1024,2048]
116+
name = "triangle"
117+
118+
for s in SR:
119+
fout = open(folder+name+str(s)+"_int8.h","w")
120+
121+
write_header(fout,s,name)
122+
123+
t = np.linspace(0,2*np.pi,num=s,endpoint=False)
124+
outstring=""
125+
for i in range(s):
126+
if (i<=s/4):
127+
outstring+=str(round(i*127./s*4))+", "
128+
elif (i<=s*3/4):
129+
outstring+=str(round(127-(i-s/4)*(127*2)/(s/2)))+", "
130+
else:
131+
outstring+=str(round(-127.+127.*(i-s*3/4)/s*4))+", "
132+
133+
outstring = textwrap.fill(outstring,80)
134+
fout.write(outstring)
135+
write_footer(fout,s,name)
136+
fout.close()
137+
138+
print("Wrote:"+name.upper()+str(s)+"_INT8")
139+
140+
141+
142+
143+
144+
#### SAW
145+
146+
SR = [256,512,1024,2048,4096,8192]
147+
name = "saw"
148+
149+
for s in SR:
150+
fout = open(folder+name+str(s)+"_int8.h","w")
151+
152+
write_header(fout,s,name)
153+
154+
t = np.linspace(0,2*np.pi,num=s,endpoint=False)
155+
outstring=""
156+
for i in range(s):
157+
outstring+=str(str(round(-127+127*2.*i/(s-1)))+", ")
158+
159+
outstring = textwrap.fill(outstring,80)
160+
fout.write(outstring)
161+
write_footer(fout,s,name)
162+
fout.close()
163+
164+
print("Wrote:"+name.upper()+str(s)+"_INT8")

extras/python/sin1024_int8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## generates a sin-shaped table with values -128 to 127
2-
2+
## NOTE: this table has been generated using the "make_standard_tables.py" script, which produces a symetric table.
33

44
import array
55
import os

tables/brownnoise8192_int8.h

Lines changed: 412 additions & 488 deletions
Large diffs are not rendered by default.

tables/chum78_int8.h

Lines changed: 413 additions & 468 deletions
Large diffs are not rendered by default.

tables/cos1024_int8.h

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,81 @@
11
#ifndef COS1024_H_
22
#define COS1024_H_
3+
4+
/**
5+
This table is part of Mozzi
6+
Generated with extras/python/make_standard_tables.py
7+
*/
38

49
#include <Arduino.h>
510
#include "mozzi_pgmspace.h"
6-
11+
712
#define COS1024_NUM_CELLS 1024
813
#define COS1024_SAMPLERATE 1024
9-
10-
CONSTTABLE_STORAGE(int8_t) COS1024_DATA [] =
11-
{
12-
-128, -128, -128, -128, -128, -128, -128,
13-
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
14-
-128, -127, -127, -127, -127, -127, -127, -127, -127, -126, -126, -126, -126,
15-
-126, -126, -126, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124,
16-
-123, -123, -123, -123, -123, -122, -122, -122, -122, -121, -121, -121, -120,
17-
-120, -120, -120, -119, -119, -119, -118, -118, -118, -118, -117, -117, -117,
18-
-116, -116, -116, -115, -115, -114, -114, -114, -113, -113, -113, -112, -112,
19-
-111, -111, -111, -110, -110, -109, -109, -109, -108, -108, -107, -107, -106,
20-
-106, -106, -105, -105, -104, -104, -103, -103, -102, -102, -101, -101, -100,
21-
-100, -99, -99, -98, -98, -97, -97, -96, -96, -95, -95, -94, -94, -93, -93, -92,
22-
-92, -91, -90, -90, -89, -89, -88, -88, -87, -86, -86, -85, -85, -84, -84, -83,
23-
-82, -82, -81, -80, -80, -79, -79, -78, -77, -77, -76, -75, -75, -74, -74, -73,
24-
-72, -72, -71, -70, -70, -69, -68, -68, -67, -66, -66, -65, -64, -64, -63, -62,
25-
-62, -61, -60, -59, -59, -58, -57, -57, -56, -55, -55, -54, -53, -52, -52, -51,
26-
-50, -49, -49, -48, -47, -47, -46, -45, -44, -44, -43, -42, -41, -41, -40, -39,
27-
-38, -38, -37, -36, -35, -35, -34, -33, -32, -32, -31, -30, -29, -29, -28, -27,
28-
-26, -25, -25, -24, -23, -22, -22, -21, -20, -19, -19, -18, -17, -16, -15, -15,
29-
-14, -13, -12, -11, -11, -10, -9, -8, -8, -7, -6, -5, -4, -4, -3, -2, -1, -1, 0,
30-
1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 17, 18,
31-
19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 28, 28, 29, 30, 31, 31, 32, 33, 34,
32-
34, 35, 36, 37, 37, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 46, 47, 48, 48,
33-
49, 50, 51, 51, 52, 53, 54, 54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63,
34-
63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 71, 72, 73, 73, 74, 74, 75, 76,
35-
76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 83, 83, 84, 84, 85, 85, 86, 87, 87, 88,
36-
88, 89, 89, 90, 91, 91, 92, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98, 98,
37-
99, 99, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 105, 106,
38-
106, 107, 107, 108, 108, 108, 109, 109, 110, 110, 110, 111, 111, 112, 112, 112,
39-
113, 113, 113, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117, 117, 117, 118,
40-
118, 118, 119, 119, 119, 119, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122,
41-
122, 122, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125,
42-
125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127,
43-
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
44-
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
45-
127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 125, 125, 125, 125,
46-
125, 125, 125, 124, 124, 124, 124, 124, 123, 123, 123, 123, 123, 122, 122, 122,
47-
122, 122, 121, 121, 121, 121, 120, 120, 120, 119, 119, 119, 119, 118, 118, 118,
48-
117, 117, 117, 117, 116, 116, 116, 115, 115, 115, 114, 114, 113, 113, 113, 112,
49-
112, 112, 111, 111, 110, 110, 110, 109, 109, 108, 108, 108, 107, 107, 106, 106,
50-
106, 105, 105, 104, 104, 103, 103, 102, 102, 101, 101, 100, 100, 99, 99, 98, 98,
51-
97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92, 91, 91, 90, 89, 89, 88, 88, 87,
52-
87, 86, 85, 85, 84, 84, 83, 83, 82, 81, 81, 80, 79, 79, 78, 78, 77, 76, 76, 75,
53-
74, 74, 73, 73, 72, 71, 71, 70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 63, 62,
54-
61, 61, 60, 59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49, 48, 48,
55-
47, 46, 46, 45, 44, 43, 43, 42, 41, 40, 40, 39, 38, 37, 37, 36, 35, 34, 34, 33,
56-
32, 31, 31, 30, 29, 28, 28, 27, 26, 25, 24, 24, 23, 22, 21, 21, 20, 19, 18, 18,
57-
17, 16, 15, 14, 14, 13, 12, 11, 10, 10, 9, 8, 7, 7, 6, 5, 4, 3, 3, 2, 1, 0, 0,
58-
-1, -2, -3, -4, -4, -5, -6, -7, -8, -8, -9, -10, -11, -11, -12, -13, -14, -15,
59-
-15, -16, -17, -18, -19, -19, -20, -21, -22, -22, -23, -24, -25, -25, -26, -27,
60-
-28, -29, -29, -30, -31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39,
61-
-40, -41, -41, -42, -43, -44, -44, -45, -46, -47, -47, -48, -49, -49, -50, -51,
62-
-52, -52, -53, -54, -55, -55, -56, -57, -57, -58, -59, -59, -60, -61, -62, -62,
63-
-63, -64, -64, -65, -66, -66, -67, -68, -68, -69, -70, -70, -71, -72, -72, -73,
64-
-74, -74, -75, -75, -76, -77, -77, -78, -79, -79, -80, -80, -81, -82, -82, -83,
65-
-84, -84, -85, -85, -86, -86, -87, -88, -88, -89, -89, -90, -90, -91, -92, -92,
66-
-93, -93, -94, -94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100,
67-
-100, -101, -101, -102, -102, -103, -103, -104, -104, -105, -105, -106, -106,
68-
-106, -107, -107, -108, -108, -109, -109, -109, -110, -110, -111, -111, -111,
69-
-112, -112, -113, -113, -113, -114, -114, -114, -115, -115, -116, -116, -116,
70-
-117, -117, -117, -118, -118, -118, -118, -119, -119, -119, -120, -120, -120,
71-
-120, -121, -121, -121, -122, -122, -122, -122, -123, -123, -123, -123, -123,
72-
-124, -124, -124, -124, -124, -125, -125, -125, -125, -125, -126, -126, -126,
73-
-126, -126, -126, -126, -127, -127, -127, -127, -127, -127, -127, -127, -128,
74-
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
75-
-128, -128, -128, -128, -128, -128,
76-
};
77-
78-
#endif /* COS1024_H_ */
14+
15+
CONSTTABLE_STORAGE(int8_t) COS1024_DATA [] = {
16+
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127,
17+
-127, -127, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126,
18+
-125, -125, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -124,
19+
-123, -123, -123, -123, -123, -122, -122, -122, -122, -122, -121, -121, -121,
20+
-121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118, -117,
21+
-117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, -113, -113,
22+
-113, -112, -112, -112, -111, -111, -111, -110, -110, -109, -109, -109, -108,
23+
-108, -107, -107, -106, -106, -106, -105, -105, -104, -104, -103, -103, -102,
24+
-102, -102, -101, -101, -100, -100, -99, -99, -98, -98, -97, -97, -96, -96, -95,
25+
-95, -94, -94, -93, -93, -92, -91, -91, -90, -90, -89, -89, -88, -88, -87, -86,
26+
-86, -85, -85, -84, -84, -83, -82, -82, -81, -81, -80, -79, -79, -78, -78, -77,
27+
-76, -76, -75, -74, -74, -73, -72, -72, -71, -71, -70, -69, -69, -68, -67, -67,
28+
-66, -65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56,
29+
-55, -54, -54, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, -44,
30+
-44, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -35, -35, -34, -33, -32,
31+
-32, -31, -30, -29, -29, -28, -27, -26, -26, -25, -24, -23, -22, -22, -21, -20,
32+
-19, -19, -18, -17, -16, -16, -15, -14, -13, -12, -12, -11, -10, -9, -9, -8, -7,
33+
-6, -5, -5, -4, -3, -2, -2, -1, 0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11,
34+
12, 12, 13, 14, 15, 16, 16, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26,
35+
27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41,
36+
42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54, 54, 55, 56,
37+
56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69,
38+
70, 71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82,
39+
82, 83, 84, 84, 85, 85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93,
40+
94, 94, 95, 95, 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, 102, 102,
41+
102, 103, 103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109, 109,
42+
109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115,
43+
115, 115, 116, 116, 116, 117, 117, 117, 118, 118, 118, 118, 119, 119, 119, 120,
44+
120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123, 123,
45+
123, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126,
46+
126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127,
47+
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
48+
127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126,
49+
126, 125, 125, 125, 125, 125, 125, 125, 124, 124, 124, 124, 124, 124, 123, 123,
50+
123, 123, 123, 122, 122, 122, 122, 122, 121, 121, 121, 121, 120, 120, 120, 120,
51+
119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 116, 116, 116, 115, 115, 115,
52+
114, 114, 114, 113, 113, 113, 112, 112, 112, 111, 111, 111, 110, 110, 109, 109,
53+
109, 108, 108, 107, 107, 106, 106, 106, 105, 105, 104, 104, 103, 103, 102, 102,
54+
102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93,
55+
92, 91, 91, 90, 90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81,
56+
81, 80, 79, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 71, 70, 69, 69,
57+
68, 67, 67, 66, 65, 65, 64, 63, 63, 62, 61, 61, 60, 59, 58, 58, 57, 56, 56, 55,
58+
54, 54, 53, 52, 51, 51, 50, 49, 49, 48, 47, 46, 46, 45, 44, 44, 43, 42, 41, 41,
59+
40, 39, 38, 38, 37, 36, 35, 35, 34, 33, 32, 32, 31, 30, 29, 29, 28, 27, 26, 26,
60+
25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13, 12, 12, 11, 10,
61+
9, 9, 8, 7, 6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5, -6, -7, -8,
62+
-9, -9, -10, -11, -12, -12, -13, -14, -15, -16, -16, -17, -18, -19, -19, -20,
63+
-21, -22, -22, -23, -24, -25, -26, -26, -27, -28, -29, -29, -30, -31, -32, -32,
64+
-33, -34, -35, -35, -36, -37, -38, -38, -39, -40, -41, -41, -42, -43, -44, -44,
65+
-45, -46, -46, -47, -48, -49, -49, -50, -51, -51, -52, -53, -54, -54, -55, -56,
66+
-56, -57, -58, -58, -59, -60, -61, -61, -62, -63, -63, -64, -65, -65, -66, -67,
67+
-67, -68, -69, -69, -70, -71, -71, -72, -72, -73, -74, -74, -75, -76, -76, -77,
68+
-78, -78, -79, -79, -80, -81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -86,
69+
-87, -88, -88, -89, -89, -90, -90, -91, -91, -92, -93, -93, -94, -94, -95, -95,
70+
-96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102, -102,
71+
-102, -103, -103, -104, -104, -105, -105, -106, -106, -106, -107, -107, -108,
72+
-108, -109, -109, -109, -110, -110, -111, -111, -111, -112, -112, -112, -113,
73+
-113, -113, -114, -114, -114, -115, -115, -115, -116, -116, -116, -117, -117,
74+
-117, -118, -118, -118, -118, -119, -119, -119, -120, -120, -120, -120, -121,
75+
-121, -121, -121, -122, -122, -122, -122, -122, -123, -123, -123, -123, -123,
76+
-124, -124, -124, -124, -124, -124, -125, -125, -125, -125, -125, -125, -125,
77+
-126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -127, -127,
78+
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127,
79+
};
80+
81+
#endif /* COS1024_H_ */

0 commit comments

Comments
 (0)