diff options
Diffstat (limited to 'util/sample_parser.py')
| -rwxr-xr-x | util/sample_parser.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/util/sample_parser.py b/util/sample_parser.py new file mode 100755 index 000000000..70e193aee --- /dev/null +++ b/util/sample_parser.py | |||
| @@ -0,0 +1,39 @@ | |||
| 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 | # print(str(waveFile.getparams())) | ||
| 23 | # sys.exit() | ||
| 24 | |||
| 25 | if (waveFile.getsampwidth() != 2): | ||
| 26 | raise(Exception("This script currently only works with 16bit audio files")) | ||
| 27 | |||
| 28 | length = waveFile.getnframes() | ||
| 29 | out = "#define DAC_SAMPLE_CUSTOM_LENGTH " + str(length) + "\n\n" | ||
| 30 | out += "static const dacsample_t dac_sample_custom[" + str(length) + "] = {" | ||
| 31 | for i in range(0,length): | ||
| 32 | if (i % 8 == 0): | ||
| 33 | out += "\n " | ||
| 34 | waveData = waveFile.readframes(1) | ||
| 35 | data = struct.unpack("<h", waveData) | ||
| 36 | out += str(int((int(data[0]) + 0x8000) / 16)) + ", " | ||
| 37 | out = out[:-2] | ||
| 38 | out += "\n};" | ||
| 39 | print(out) | ||
