
# cantus firmus 2 second

import numpy as np
from numpy import linspace, append
from scipy.io.wavfile import write

freqSamp=44100
duration=2
stereoNote=np.empty([2,duration*freqSamp],float)

freqNote=441
numRpts=freqSamp//freqNote
print(freqNote,numRpts)
halfRpts=numRpts//2

firstHalf=linspace(1.0,1.0,halfRpts,False).astype(float)
lastHalf=linspace(-1.0,-1.0,halfRpts,False).astype(float)
squData=append(firstHalf,lastHalf)

rpts=duration*freqNote-1
squNote=squData
while rpts>0:
    squNote=append(squNote,squData)
    rpts=rpts-1

print(squNote.shape)

# fourth up 1 second

duration=1
freqNote=630
numRpts=freqSamp//freqNote
print(freqNote,numRpts)
halfRpts=numRpts//2

firstHalf=linspace(1.0,1.0,halfRpts,False).astype(float)
lastHalf=linspace(-1.0,-1.0,halfRpts,False).astype(float)
fourthData=append(firstHalf,lastHalf)

rpts=duration*freqNote-1
fourthNote=fourthData
while rpts>0:
    fourthNote=append(fourthNote,fourthData)
    rpts=rpts-1

print(fourthNote.shape)
    
# octave down 1 second
    
duration=1
freqNote=225
numRpts=freqSamp//freqNote
print(freqNote,numRpts)
halfRpts=numRpts//2

firstHalf=linspace(1.0,1.0,halfRpts,False).astype(float)
lastHalf=linspace(-1.0,-1.0,halfRpts,False).astype(float)
octaveData=append(firstHalf,lastHalf)

rpts=duration*freqNote-1
octaveNote=octaveData
while rpts>0:
    octaveNote=append(octaveNote,octaveData)
    rpts=rpts-1

print (octaveNote.shape)

# stereo 2 seconds

oct4th=append(octaveNote,fourthNote)

level=0.67
squNote=level*squNote
print(oct4th.shape)
stereoNote=np.array((oct4th,squNote))
stereoNote=stereoNote.transpose()

print('stereo',stereoNote.shape,stereoNote.ndim)
print(stereoNote)

write('stereo.wav',freqSamp,stereoNote)
