summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rwxr-xr-xutil/audio_generate_dac_lut.py67
-rwxr-xr-xutil/chibios-upgrader.sh176
-rwxr-xr-xutil/docker_build.sh2
-rwxr-xr-xutil/install/opensuse.sh31
-rwxr-xr-xutil/install/sabayon.sh15
-rwxr-xr-xutil/sample_parser.py39
-rwxr-xr-xutil/travis_build.sh51
-rwxr-xr-xutil/travis_compiled_push.sh63
-rwxr-xr-xutil/travis_push.sh14
-rw-r--r--util/travis_test.sh15
-rwxr-xr-xutil/wavetable_parser.py40
11 files changed, 247 insertions, 266 deletions
diff --git a/util/audio_generate_dac_lut.py b/util/audio_generate_dac_lut.py
deleted file mode 100755
index c31ba3d7ee..0000000000
--- a/util/audio_generate_dac_lut.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright 2020 JohSchneider
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-AUDIO_DAC_BUFFER_SIZE=256
-AUDIO_DAC_SAMPLE_MAX=4095
-
-def plot(values):
- for v in values:
- print('0'* int(v * 80/AUDIO_DAC_SAMPLE_MAX))
-
-def to_lut(values):
- for v in values:
- print(hex(int(v)), end=", ")
-
-
-from math import sin, tau, pi
-
-samples=[]
-
-def sampleSine():
- for s in range(AUDIO_DAC_BUFFER_SIZE):
- samples.append((sin((s/AUDIO_DAC_BUFFER_SIZE)*tau - pi/2) + 1 )/2* AUDIO_DAC_SAMPLE_MAX)
-
-def sampleTriangle():
- for s in range(AUDIO_DAC_BUFFER_SIZE):
- if s < AUDIO_DAC_BUFFER_SIZE/2:
- samples.append(s/(AUDIO_DAC_BUFFER_SIZE/2) * AUDIO_DAC_SAMPLE_MAX)
- else:
- samples.append(AUDIO_DAC_SAMPLE_MAX - (s-AUDIO_DAC_BUFFER_SIZE/2)/(AUDIO_DAC_BUFFER_SIZE/2) * AUDIO_DAC_SAMPLE_MAX)
-
-#compromise between square and triangle wave,
-def sampleTrapezoidal():
- for i in range(AUDIO_DAC_BUFFER_SIZE):
- a=3 #slope/inclination
- if (i < AUDIO_DAC_BUFFER_SIZE/2):
- s = a * (i * AUDIO_DAC_SAMPLE_MAX/(AUDIO_DAC_BUFFER_SIZE/2)) + (1-a)*AUDIO_DAC_SAMPLE_MAX/2
- else:
- i = i - AUDIO_DAC_BUFFER_SIZE/2
- s = AUDIO_DAC_SAMPLE_MAX - a * (i * AUDIO_DAC_SAMPLE_MAX/(AUDIO_DAC_BUFFER_SIZE/2)) - (1-a)*AUDIO_DAC_SAMPLE_MAX/2
-
- if s < 0:
- s=0
- if s> AUDIO_DAC_SAMPLE_MAX:
- s=AUDIO_DAC_SAMPLE_MAX
- samples.append(s)
-
-
-#sampleSine()
-sampleTrapezoidal()
-#print(samples)
-plot(samples)
-to_lut(samples)
diff --git a/util/chibios-upgrader.sh b/util/chibios-upgrader.sh
new file mode 100755
index 0000000000..ebc12abe7d
--- /dev/null
+++ b/util/chibios-upgrader.sh
@@ -0,0 +1,176 @@
+#!/bin/bash
+
+set -eEuo pipefail
+umask 022
+
+sinfo() { echo "$@" >&2 ; }
+shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; }
+havecmd() { command command type "${1}" >/dev/null 2>&1 || return 1 ; }
+
+this_script="$(realpath "${BASH_SOURCE[0]}")"
+script_dir="$(realpath "$(dirname "$this_script")")"
+qmk_firmware_dir="$(realpath "$script_dir/../")"
+
+declare -A file_hashes
+
+export PATH="$PATH:$script_dir/fmpp/bin"
+
+build_fmpp() {
+ [ -f "$script_dir/fmpp.tar.gz" ] \
+ || wget -O"$script_dir/fmpp.tar.gz" https://github.com/freemarker/fmpp/archive/v0.9.16.tar.gz
+ [ -d "$script_dir/fmpp" ] \
+ || { mkdir "$script_dir/fmpp" && tar xf "$script_dir/fmpp.tar.gz" -C "$script_dir/fmpp" --strip-components=1 ; }
+ pushd "$script_dir/fmpp" >/dev/null 2>&1
+ sed -e "s#bootclasspath.path=.*#bootclasspath.path=$(find /usr/lib/jvm -name 'rt.jar' | sort | tail -n1)#g" \
+ -e "s#ant.jar.path=.*#ant.jar.path=$(find /usr/share/java -name 'ant-1*.jar' | sort | tail -n1)#g" \
+ build.properties.sample > build.properties
+ sed -e 's#source="1.5"#source="1.8"#g' \
+ -e 's#target="1.5"#target="1.8"#g' \
+ build.xml > build.xml.new
+ mv build.xml.new build.xml
+ ant clean
+ ant
+ chmod +x "$script_dir/fmpp/bin/fmpp"
+ popd >/dev/null 2>&1
+}
+
+find_chibi_files() {
+ local search_path="$1"
+ shift
+ local conditions=( "$@" )
+ for file in $(find -L "$search_path" -not -path '*/lib/chibios*' -and -not -path '*/lib/ugfx*' -and -not -path '*/util/*' -and \( "${conditions[@]}" \) | sort) ; do
+ if [ -z "$(grep 'include_next' "$file")" ] ; then
+ echo $file
+ fi
+ done
+}
+
+revert_chibi_files() {
+ local search_path="$1"
+ shead "Reverting ChibiOS config/board files..."
+ for file in $(find_chibi_files "$search_path" -name chconf.h -or -name halconf.h -or -name mcuconf.h -or -name board.c -or -name board.h -or -name board.mk -or -name board.chcfg) ; do
+ pushd "$search_path" >/dev/null 2>&1
+ local relpath=$(realpath --relative-to="$search_path" "$file")
+ git checkout upstream/master -- "$relpath" || git checkout origin/master -- "$relpath" || true
+ popd >/dev/null 2>&1
+ done
+}
+
+populate_file_hashes() {
+ local search_path="$1"
+ shead "Determining duplicate config/board files..."
+ for file in $(find_chibi_files "$search_path" -name chconf.h -or -name halconf.h -or -name mcuconf.h -or -name board.c -or -name board.h) ; do
+ local key="file_$(clang-format "$file" | sha1sum | cut -d' ' -f1)"
+ local relpath=$(realpath --relative-to="$search_path" "$file")
+ file_hashes[$key]="${file_hashes[$key]:-} $relpath"
+ done
+ for file in $(find_chibi_files "$search_path" -name board.mk -or -name board.chcfg) ; do
+ local key="file_$(cat "$file" | sha1sum | cut -d' ' -f1)"
+ local relpath=$(realpath --relative-to="$search_path" "$file")
+ file_hashes[$key]="${file_hashes[$key]:-} $relpath"
+ done
+}
+
+determine_equivalent_files() {
+ local search_file="$1"
+ for K in "${!file_hashes[@]}"; do
+ for V in ${file_hashes[$K]}; do
+ if [[ "$V" == "$search_file" ]] ; then
+ for V in ${file_hashes[$K]}; do
+ echo "$V"
+ done
+ return 0
+ fi
+ done
+ done
+ return 1
+}
+
+deploy_staged_files() {
+ shead "Deploying staged files..."
+ for file in $(find "$qmk_firmware_dir/util/chibios-upgrade-staging" -type f) ; do
+ local relpath=$(realpath --relative-to="$qmk_firmware_dir/util/chibios-upgrade-staging" "$file")
+ sinfo "Deploying staged file: $relpath"
+ for other in $(determine_equivalent_files "$relpath") ; do
+ sinfo " => $other"
+ cp "$qmk_firmware_dir/util/chibios-upgrade-staging/$relpath" "$qmk_firmware_dir/$other"
+ done
+ done
+}
+
+swap_mcuconf_f3xx_f303() {
+ shead "Swapping STM32F3xx_MCUCONF -> STM32F303_MCUCONF..."
+ for file in $(find_chibi_files "$qmk_firmware_dir" -name mcuconf.h) ; do
+ sed -i 's#STM32F3xx_MCUCONF#STM32F303_MCUCONF#g' "$file"
+ dos2unix "$file" >/dev/null 2>&1
+ done
+}
+
+upgrade_conf_files_generic() {
+ local search_filename="$1"
+ local update_script="$2"
+ shead "Updating $search_filename files ($update_script)..."
+ pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
+ for file in $(find_chibi_files "$qmk_firmware_dir" -name "$search_filename") ; do
+ cp -f "$file" "$file.orig"
+ clang-format --style='{IndentPPDirectives: None}' -i "$file"
+ cp -f "$file" "$file.formatted"
+ bash "$update_script" "$file"
+ if ! diff "$file" "$file.formatted" >/dev/null 2>&1 ; then
+ dos2unix "$file" >/dev/null 2>&1
+ else
+ cp -f "$file.orig" "$file"
+ fi
+ rm -f "$file.orig" "$file.formatted"
+ done
+ popd >/dev/null 2>&1
+}
+
+upgrade_chconf_files() {
+ upgrade_conf_files_generic chconf.h update_chconf_rt.sh
+}
+
+upgrade_halconf_files() {
+ upgrade_conf_files_generic halconf.h update_halconf.sh
+}
+
+upgrade_mcuconf_files() {
+ pushd "$qmk_firmware_dir/lib/chibios/tools/updater" >/dev/null 2>&1
+ for f in $(find . -name 'update_mcuconf*') ; do
+ upgrade_conf_files_generic mcuconf.h $f
+ done
+ popd >/dev/null 2>&1
+}
+
+update_staged_files() {
+ shead "Updating staged files with ChibiOS upgraded versions..."
+ for file in $(find "$qmk_firmware_dir/util/chibios-upgrade-staging" -type f) ; do
+ local relpath=$(realpath --relative-to="$qmk_firmware_dir/util/chibios-upgrade-staging" "$file")
+ sinfo "Updating staged file: $relpath"
+ cp "$qmk_firmware_dir/$relpath" "$qmk_firmware_dir/util/chibios-upgrade-staging/$relpath"
+ done
+}
+
+havecmd fmpp || build_fmpp
+revert_chibi_files "$qmk_firmware_dir"
+populate_file_hashes "$qmk_firmware_dir"
+
+shead "Showing duplicate ChibiOS files..."
+for K in "${!file_hashes[@]}"; do
+ sinfo ${K#file_}:
+ for V in ${file_hashes[$K]}; do
+ sinfo " $V"
+ done
+done
+
+if [ "${1:-}" == "-r" ] ; then
+ exit 0
+fi
+
+swap_mcuconf_f3xx_f303
+
+deploy_staged_files
+upgrade_mcuconf_files
+upgrade_chconf_files
+upgrade_halconf_files
+update_staged_files
diff --git a/util/docker_build.sh b/util/docker_build.sh
index 2b109be76d..2c2a26e776 100755
--- a/util/docker_build.sh
+++ b/util/docker_build.sh
@@ -36,7 +36,7 @@ if [ -z "$RUNTIME" ]; then
exit 2
fi
fi
-
+
# Determine arguments
if [ $# -eq 0 ]; then
diff --git a/util/install/opensuse.sh b/util/install/opensuse.sh
new file mode 100755
index 0000000000..47b44ae364
--- /dev/null
+++ b/util/install/opensuse.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+_qmk_install_prepare() {
+ case $(grep ID /etc/os-release) in
+ *15.1*)
+ REPO_RELEASE=Leap_15.1;;
+ *15.2*)
+ REPO_RELEASE=Leap_15.2;;
+ *)
+ #REPO_RELEASE=Tumbleweed;;
+ echo "ERROR: Tumbleweed is currently not supported."
+ exit 1
+ esac
+
+ sudo zypper addrepo https://download.opensuse.org/repositories/devel:gcc/openSUSE_$REPO_RELEASE/devel:gcc.repo
+ sudo zypper addrepo https://download.opensuse.org/repositories/hardware/openSUSE_$REPO_RELEASE/hardware.repo
+ sudo zypper --gpg-auto-import-keys refresh
+}
+
+_qmk_install() {
+ echo "Installing dependencies"
+
+ sudo zypper install -y \
+ make clang gcc unzip wget zip \
+ python3-pip \
+ cross-avr-binutils cross-avr-gcc8 avr-libc \
+ cross-arm-binutils cross-arm-none-gcc8 cross-arm-none-newlib-devel \
+ avrdude dfu-programmer dfu-util
+
+ python3 -m pip install --user -r $QMK_FIRMWARE_DIR/requirements.txt
+}
diff --git a/util/install/sabayon.sh b/util/install/sabayon.sh
new file mode 100755
index 0000000000..fd4f4d8dfd
--- /dev/null
+++ b/util/install/sabayon.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+_qmk_install() {
+ echo "Installing dependencies"
+
+ sudo equo install \
+ app-arch/unzip app-arch/zip net-misc/wget dev-vcs/git sys-devel/clang sys-devel/gcc sys-devel/crossdev \
+ dev-python/pip \
+ dev-embedded/avrdude dev-embedded/dfu-programmer app-mobilephone/dfu-util
+
+ sudo crossdev -s4 --stable --g \<9 --portage --verbose --target avr
+ sudo crossdev -s4 --stable --g \<9 --portage --verbose --target arm-none-eabi
+
+ python3 -m pip install --user -r $QMK_FIRMWARE_DIR/requirements.txt
+}
diff --git a/util/sample_parser.py b/util/sample_parser.py
deleted file mode 100755
index 70e193aee7..0000000000
--- a/util/sample_parser.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright 2019 Jack Humbert
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-import wave, struct, sys
-
-waveFile = wave.open(sys.argv[1], 'r')
-# print(str(waveFile.getparams()))
-# sys.exit()
-
-if (waveFile.getsampwidth() != 2):
- raise(Exception("This script currently only works with 16bit audio files"))
-
-length = waveFile.getnframes()
-out = "#define DAC_SAMPLE_CUSTOM_LENGTH " + str(length) + "\n\n"
-out += "static const dacsample_t dac_sample_custom[" + str(length) + "] = {"
-for i in range(0,length):
- if (i % 8 == 0):
- out += "\n "
- waveData = waveFile.readframes(1)
- data = struct.unpack("<h", waveData)
- out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
-out = out[:-2]
-out += "\n};"
-print(out)
diff --git a/util/travis_build.sh b/util/travis_build.sh
index e7bbe36a7b..ec059b2982 100755
--- a/util/travis_build.sh
+++ b/util/travis_build.sh
@@ -1,40 +1,23 @@
#!/bin/bash
-source util/travis_utils.sh
-
-if [[ "$TRAVIS_COMMIT_MESSAGE" == *"[skip build]"* ]]; then
- echo "Skipping due to commit message"
- exit 0
-fi
-
-if [ "$LOCAL_BRANCH" == "master" ] || [ "$NUM_CORE_CHANGES" != "0" ]; then
- echo "Making default keymaps for all keyboards"
- make all:default
- exit $?
+# if docker is installed - call make within the qmk docker image
+if command -v docker >/dev/null; then
+ function make() {
+ docker run --rm -e MAKEFLAGS="$MAKEFLAGS" -w /qmk_firmware/ -v "$PWD":/qmk_firmware --user $(id -u):$(id -g) qmkfm/base_container make "$@"
+ }
fi
-exit_code=0
+# test force push
+#TRAVIS_COMMIT_RANGE="c287f1bfc5c8...81f62atc4c1d"
-for KB in $(make list-keyboards); do
- KEYBOARD_CHANGES=$(echo "$QMK_CHANGES" | grep -E '^(keyboards/'${KB}'/)')
- if [[ -z "$KEYBOARD_CHANGES" ]]; then
- # skip as no changes for this keyboard
- continue
- fi
+TRAVIS_COMMIT_MESSAGE="${TRAVIS_COMMIT_MESSAGE:-none}"
+TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE:-HEAD~1..HEAD}"
+MAKE_ALL="make all:all"
- KEYMAP_ONLY=$(echo "$KEYBOARD_CHANGES" | grep -cv /keymaps/)
- if [[ $KEYMAP_ONLY -gt 0 ]]; then
- echo "Making all keymaps for $KB"
- make ${KB}:all
- : $((exit_code = $exit_code + $?))
- else
- CHANGED_KEYMAPS=$(echo "$KEYBOARD_CHANGES" | grep -oP '(?<=keyboards/'${KB}'/keymaps/)([a-zA-Z0-9_-]+)(?=\/)')
- for KM in $CHANGED_KEYMAPS ; do
- echo "Making $KM for $KB"
- make ${KB}:${KM}
- : $((exit_code = $exit_code + $?))
- done
- fi
-done
-
-exit $exit_code
+if [[ "$TRAVIS_COMMIT_MESSAGE" != *"[skip build]"* ]] ; then
+ exit_code=0
+ echo "Making all keymaps for all of the ZSA keyboards"
+ eval $MAKE_ALL
+ : $((exit_code = $exit_code + $?))
+ exit $exit_code
+fi
diff --git a/util/travis_compiled_push.sh b/util/travis_compiled_push.sh
deleted file mode 100755
index 6300442fdb..0000000000
--- a/util/travis_compiled_push.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/bash
-
-source util/travis_utils.sh
-source util/travis_push.sh
-
-set -o errexit -o nounset
-
-rev=$(git rev-parse --short HEAD)
-echo "Using git hash ${rev}"
-
-if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]] ; then
-
-git checkout master
-
-git diff --name-only -n 1 ${TRAVIS_COMMIT_RANGE}
-
-if [[ "$TRAVIS_COMMIT_MESSAGE" != *"[skip build]"* ]] ; then
- make generate-keyboards-file SILENT=true > .keyboards
- cd ..
- git clone git@github.com:qmk/qmk.fm.git
- cd qmk.fm
- mv ../qmk_firmware/id_rsa_qmk.fm id_rsa_qmk.fm
- mv ../qmk_firmware/.keyboards .
- ssh-add -D
- eval `ssh-agent -s`
- ssh-add id_rsa_qmk.fm
-
- # don't delete files in case not all keyboards are built
- # rm -f compiled/*.hex
-
- # ignore errors here
- # In theory, this is more flexible, and will allow for additional expansion of additional types of files and other names
- mv ../qmk_firmware/*_default.*{hex,bin} ./compiled/ || true
-
- # get the list of keyboards
- readarray -t keyboards < .keyboards
-
- # replace / with _
- keyboards=("${keyboards[@]//[\/]/_}")
-
- # remove all binaries that don't belong to a keyboard in .keyboards
- for file in "./compiled"/* ; do
- match=0
- for keyboard in "${keyboards[@]}" ; do
- if [[ ${file##*/} = "${keyboard}_default.bin" ]] || [[ ${file##*/} = "${keyboard}_default.hex" ]]; then
- match=1
- break
- fi
- done
- if [[ $match = 0 ]]; then
- echo "Removing deprecated binary: $file"
- rm "$file"
- fi
- done
-
- bash _util/generate_keyboard_page.sh
- git add -A
- git commit -m "generated from qmk/qmk_firmware@${rev}"
- git push git@github.com:qmk/qmk.fm.git
-
-fi
-
-fi
diff --git a/util/travis_push.sh b/util/travis_push.sh
deleted file mode 100755
index 7f7d4c2c64..0000000000
--- a/util/travis_push.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-# Use this by sourcing it in your script.
-
-if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]] ; then
- git config --global user.name "QMK Bot"
- git config --global user.email "hello@qmk.fm"
-
- openssl aes-256-cbc -K $encrypted_b0ee987fd0fc_key -iv $encrypted_b0ee987fd0fc_iv -in secrets.tar.enc -out secrets.tar -d
- tar xvf secrets.tar
-
- chmod 600 id_rsa_qmk_firmware
- chmod 600 id_rsa_qmk.fm
- eval `ssh-agent -s`
- ssh-add id_rsa_qmk_firmware
-fi
diff --git a/util/travis_test.sh b/util/travis_test.sh
index be0cfce001..87a01ba407 100644
--- a/util/travis_test.sh
+++ b/util/travis_test.sh
@@ -1,19 +1,18 @@
#!/bin/bash
-source util/travis_utils.sh
+TRAVIS_COMMIT_MESSAGE="${TRAVIS_COMMIT_MESSAGE:-none}"
+TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE:-HEAD~1..HEAD}"
+
+NUM_CORE_CHANGES=$(echo "$QMK_CHANGES" | grep -Ecv -e '^(docs/)' -e '^(keyboards/)' -e '^(layouts/)' -e '^(util/)' -e '^(lib/python/)' -e '^(bin/qmk)' -e '^(requirements.txt)' -e '(.travis.yml)')
if [[ "$TRAVIS_COMMIT_MESSAGE" == *"[skip test]"* ]]; then
echo "Skipping due to commit message"
exit 0
fi
-exit_code=0
-
-if [ "$LOCAL_BRANCH" == "master" ] || [ "$NUM_CORE_CHANGES" != "0" ]; then
- echo "Running tests."
- make test:all
- : $((exit_code = $exit_code + $?))
-
+if [ "$BRANCH" != "master" ] && [ "$NUM_IMPACTING_CHANGES" == "0" ]; then
+ echo "Skipping due to changes not impacting tests"
+ exit 0
fi
exit $exit_code
diff --git a/util/wavetable_parser.py b/util/wavetable_parser.py
deleted file mode 100755
index be0f01f7b4..0000000000
--- a/util/wavetable_parser.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright 2019 Jack Humbert
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-import wave, struct, sys
-
-waveFile = wave.open(sys.argv[1], 'r')
-
-length = waveFile.getnframes()
-out = "#define DAC_WAVETABLE_CUSTOM_LENGTH " + str(int(length / 256)) + "\n\n"
-out += "static const dacsample_t dac_wavetable_custom[" + str(int(length / 256)) + "][256] = {"
-for i in range(0,length):
- if (i % 8 == 0):
- out += "\n "
- if (i % 256 == 0):
- out = out[:-2]
- out += "{\n "
- waveData = waveFile.readframes(1)
- data = struct.unpack("<h", waveData)
- out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
- if (i % 256 == 255):
- out = out[:-2]
- out += "\n },"
-out = out[:-1]
-out += "\n};"
-print(out)