Skip to content

Instantly share code, notes, and snippets.

@amstocker
Last active March 4, 2025 16:13
Show Gist options
  • Select an option

  • Save amstocker/e4b7797b8c35ae580c6585ae8030dad6 to your computer and use it in GitHub Desktop.

Select an option

Save amstocker/e4b7797b8c35ae580c6585ae8030dad6 to your computer and use it in GitHub Desktop.
import numpy as np
import wave
sample_rate = 48000
samples_per_cycle = 256
for z in range(8):
filename = "{}.wav".format(z + 1)
with wave.open(filename, mode="wb") as wav_file:
wav_file.setnchannels(1)
wav_file.setsampwidth(2)
wav_file.setframerate(sample_rate)
for y in range(8):
for x in range(8):
t = np.linspace(0, 1, samples_per_cycle + 1)
# single cycle of a sine wave with an amplitude of 0.5
output = 0.5 * np.sin(2 * np.pi * t)
# normalize waveform and convert to 16 bit integer
output /= np.max(np.abs(output))
output = (output * (2 ** 15 - 1)).astype("<h")
wav_file.writeframes(output[:samples_per_cycle])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment