diff options
Diffstat (limited to 'util/wavetable_parser.py')
-rwxr-xr-x | util/wavetable_parser.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/util/wavetable_parser.py b/util/wavetable_parser.py new file mode 100755 index 000000000..be0f01f7b --- /dev/null +++ b/util/wavetable_parser.py | |||
@@ -0,0 +1,40 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Copyright 2019 Jack Humbert | ||
4 | # | ||
5 | # This program is free software: you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation, either version 2 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | # | ||
18 | |||
19 | import wave, struct, sys | ||
20 | |||
21 | waveFile = wave.open(sys.argv[1], 'r') | ||
22 | |||
23 | length = waveFile.getnframes() | ||
24 | out = "#define DAC_WAVETABLE_CUSTOM_LENGTH " + str(int(length / 256)) + "\n\n" | ||
25 | out += "static const dacsample_t dac_wavetable_custom[" + str(int(length / 256)) + "][256] = {" | ||
26 | for i in range(0,length): | ||
27 | if (i % 8 == 0): | ||
28 | out += "\n " | ||
29 | if (i % 256 == 0): | ||
30 | out = out[:-2] | ||
31 | out += "{\n " | ||
32 | waveData = waveFile.readframes(1) | ||
33 | data = struct.unpack("<h", waveData) | ||
34 | out += str(int((int(data[0]) + 0x8000) / 16)) + ", " | ||
35 | if (i % 256 == 255): | ||
36 | out = out[:-2] | ||
37 | out += "\n }," | ||
38 | out = out[:-1] | ||
39 | out += "\n};" | ||
40 | print(out) | ||