Last active
December 22, 2019 16:46
-
-
Save AndrewBelt/cb51345d453fb34aba020faf4e6674d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts an 8-bit RGB PNG to a 16-bit WAV wavetable bank. | |
# The brightness of the pixel at (x, y) converts to the value of sample x in bank y. | |
import sys | |
import os | |
import numpy as np | |
import scipy.io.wavfile | |
import imageio | |
path = sys.argv[1] | |
x = imageio.imread(path) | |
x = np.sum(x, 2) / (3*256) | |
x = 2 * x - 1 | |
x = x.flatten() | |
x = (x * 32767).astype(np.int16) | |
(root, _) = os.path.splitext(path) | |
wav_path = root + ".wav" | |
scipy.io.wavfile.write(wav_path, 44100, x) | |
print("Wrote " + wav_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment