I made a program using python 3.7, numpy, and scipy that generates waveforms using the digits of pi, and stitches them together to make a "song". My only problem is that there are gaps between each note.
I have tried using mathematical functions that make the waves fade out for each note, I tried getting the notes to overlap a bit (With little luck of figuring it out), and a few more crazy things that didn't do anything...
import numpy as np
from scipy.io.wavfile import write
pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848"
piarray = list(pi)
piarray.remove(".")
print(piarray)
# Samples per second
sps = 44100
# Frequency / pitch of the sine wave
freq_hz = 440.0
# Duration
duration_s = 0.2
each_sample_number = np.arange(duration_s * sps)
for i in range(len(piarray)):
if(piarray[i] == "0"):
freq_hz = 277.18
elif(piarray[i] == "1"):
freq_hz = 311.13
elif(piarray[i] == "2"):
freq_hz = 369.99
elif(piarray[i] == "3"):
freq_hz = 415.30
elif(piarray[i] == "4"):
freq_hz = 466.16
elif(piarray[i] == "5"):
freq_hz = 554.37
elif(piarray[i] == "6"):
freq_hz = 622.25
elif(piarray[i] == "7"):
freq_hz = 739.99
elif(piarray[i] == "8"):
freq_hz = 830.61
else:
freq_hz = 932.33
waveform = np.sin(2 * np.pi * each_sample_number * freq_hz / sps)*0.3
#The line above and below this one make an individual note.
waveform_integers = np.int16(waveform * 32767)
if(i == 0):
waveformc = waveform_integers
print(waveformc)
else:
waveformc = np.append(waveformc, waveform_integers, axis=None)
write('song.wav', sps, waveformc)
print("DONE")
I have tried searching for solutions to this specific problem, but I haven't found anything related anywhere. I would just like the wave file to not have gaps between each notes, but there is. Thanks for any help you can give me!