I have written a code for joining two wave files.It works fine when i am joining larger segments but as i need to join very small segments the clarity is not good.
I have learned that the signal processing technique such a windowed join can be used to improve the joining of file.
y[n] = w[n]s[n]
Multiply value of signal at sample number n by the value of a windowing function
hamming window w[n]= .54 – .46*cos(2*Pi*n)/L 0
I am not understanding how to get the value to signal at sample n and how to implement this??
the code i am using for joining is
import wave
m=['C:/begpython/S0001_0002.wav', 'C:/begpython/S0001_0001.wav']
i=1
a=m[i]
infiles = [a, "C:/begpython/S0001_0002.wav", a]
outfile = "C:/begpython/S0001_00367.wav"
data= []
data1=[]
for infile in infiles:
w = wave.open(infile, 'rb')
data1=[w.getnframes]
data.append( [w.getparams(), w.readframes(w.getnframes())] )
#data1 = [ord(character) for character in data1]
#print data1
#data1 = ''.join(chr(character) for character in data1)
w.close()
output = wave.open(outfile, 'wb')
output.setparams(data[0][0])
output.writeframes(data[0][1])
output.writeframes(data[1][1])
output.writeframes(data[2][1])
output.close()
during joining i am manipulating using byte format for frames.now have to use integer or float format to perform operation on them i guess,if what i am thinking is true,how can i do this?
It’s probably not the best solution, but I’m sure it will work. Maybe you find existing libs or so for some steps, I dont know for Python. The steps I suggest are:
for each frame (depending on frame
size, litte/big endian,
signed/unsigned).
values into windows, e.g. sample
0-511, 512-1023, …
windows that you want to join.
array, the inverse operation of the
first step.
Old Post:
You have to calculate the sample value, in java a function for a 2 byte/frame soundfile would look like this:
Normally you will have to care about whether or not the file uses little endian, I don’t know if the Python lib will take this into account.
Once you have created all sample values, you have to divide your file into windows, e.g. of size 512 samples. Then you can window the values, and create back the byte values. For 16bit it would look like this: