import wave, struct, math, json, hashlib, pathlib
root=pathlib.Path(__file__).parent
sr=22050
samples=[]
for i in range(sr*4):
    t=i/sr
    gain=min(1,max(0,(t-.4)/.03),max(0,(3.4-t)/.02)) if .4<=t<3.4 else 0
    samples.append(round(0.25*gain*math.sin(2*math.pi*261.6255653005986*t)*32767))
with wave.open(str(root/'source.wav'),'wb') as f:
    f.setparams((1,2,sr,len(samples),'NONE','not compressed'))
    f.writeframes(struct.pack('<'+'h'*len(samples),*samples))
meta={'sampleRate':sr,'samples':len(samples),'durationSeconds':4,'toneStartSeconds':.4,'toneEndSeconds':3.4,'frequencyHz':261.6255653005986,'peakTarget':.25,'attackSeconds':.03,'releaseSeconds':.02,'source':'New owned sine fixture, not reused prior MP3; no live instrument recorded','wavSHA256':hashlib.sha256((root/'source.wav').read_bytes()).hexdigest()}
(root/'source-generation.json').write_text(json.dumps(meta,indent=2),encoding='utf8')
