#  reading samples of 1 second duration

from math import *
from numpy import linspace,append
from scipy.io.wavfile import read, write

(freqSamp,sawwav)=read('sawflt.wav')
(freqSamp,squwav)=read('squflt.wav')
(freqSamp,triwav)=read('triflt.wav')

onems=freqSamp/1000

# ADSR envelope

attack=floor(50 * onems)
decay=floor(25 * onems)
release=floor(150 * onems)

sustain=0.65
susDur=freqSamp-(attack+decay+release)

# 4 linspace for envelope

A=linspace(0,1,attack,False).astype(float)
D=linspace(1,sustain,decay,False).astype(float)
S=linspace(sustain,sustain,susDur,False).astype(float)
R=linspace(sustain,0,release,False).astype(float)

AD=append(A,D)
ADS=append(AD,S)
ADSR=append(ADS,R )

print(ADSR,ADSR.shape,type(ADSR))
print(sawwav,sawwav.shape,type(sawwav))

saweng=ADSR*sawwav

print(saweng,saweng.shape,type(saweng))

squeng=ADSR*squwav
trieng=ADSR*triwav

write('saweng.wav',freqSamp,saweng)
write('squeng.wav',freqSamp,squeng)
write('trieng.wav',freqSamp,trieng)