Skip to content

Instantly share code, notes, and snippets.

@jaap3

jaap3/genwav.py Secret

Created December 27, 2021 17:37
Show Gist options
  • Save jaap3/db27f377056e45d482ab06c69a6c2915 to your computer and use it in GitHub Desktop.
Save jaap3/db27f377056e45d482ab06c69a6c2915 to your computer and use it in GitHub Desktop.
Create wav file / inspect pti file
#!/usr/bin/env python3
import array
import math
import wave
audio = array.array('h')
for n in range(int(44100 / 4)):
audio.append(int(32767 * math.sin(2 * math.pi * 440 * (n / 44100))))
with wave.open('test.wav', 'wb') as f:
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(44100)
f.writeframes(audio.tobytes())
#!/usr/bin/env python3
import pathlib
import wave
test_wav = pathlib.Path('./test.wav') # file generated by genwav.py
test_pti = pathlib.Path('./test.pti') # pti file as created by the Tracker from test.wav
with test_wav.open('rb') as f:
test_wav_data = f.read()
with test_pti.open('rb') as f:
test_pti_data = f.read()
WAV_HEADER_LENGTH = 44
test_wav_header = test_wav_data[0:WAV_HEADER_LENGTH]
test_wav_audio = test_wav_data[WAV_HEADER_LENGTH:]
PTI_HEADER_LENGTH = test_pti_data.index(test_wav_audio) # 392
test_pti_header = test_pti_data[0:PTI_HEADER_LENGTH]
test_pti_audio = test_pti_data[PTI_HEADER_LENGTH]
print(test_pti_header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment