Esempio n. 1
0
def defaultTest():
  str_time = time.time()    
  (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe-A4.wav'))
  w = np.hamming(511)
  N = 512
  H = 256
  y = stft(x, fs, w, N, H)
  print "time taken for computation " + str(time.time()-str_time)  
Esempio n. 2
0
def defaultTest():
    str_time = time.time()
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/mridangam.wav'))
    w = np.blackman(901)
    N = 1024
    t = -70
    y, ys, yr = sprModel(x, fs, w, N, t)
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 3
0
def defaultTest():
  str_time = time.time()
  (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/ocean.wav'))
  w = np.hamming(512)
  N = 512
  H = 256
  stocf = 0.5
  y = stochasticModel(x, w, N, H, stocf)
  print "time taken for computation " + str(time.time()-str_time)
Esempio n. 4
0
def defaultTest():
    str_time = time.time()
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/mridangam.wav'))
    w = np.blackman(601)
    N = 2048
    t = -70
    stocf = 0.2
    y, ys, yst = spsModel(x, fs, w, N, t, stocf)
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 5
0
def defaultTest():
  str_time = time.time()
    
  (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe.wav'))
  w = np.hamming(511)
  N = 512
  t = -60
  fig = plt.figure()
  y = sineModel(x, fs, w, N, t)
  print "time taken for computation " + str(time.time()-str_time)  
Esempio n. 6
0
def defaultTest():
    
    str_time = time.time()
      
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe-A4.wav'))
    w = np.hamming(801)
    N = 1024
    H = 200
    t = -70
    y = stftPeaksModel(x, fs, w, N, H, t)
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 7
0
def defaultTest():
    str_time = time.time()    
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/sax-phrase-short.wav'))
    w = np.blackman(701)
    N = 1024
    t = -80
    nH = 30
    minf0 = 400
    maxf0 = 700
    f0et = 5
    maxhd = 0.2
    y = harmonicModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd)    
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 8
0
def defaultTest():
    str_time = time.time()    
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/speech-female.wav'))
    w = np.hamming(601)
    N = 1024
    t = -80
    nH = 30
    minf0 = 200
    maxf0 = 500
    f0et = 2
    maxhd = 0.2
    y = harmonicModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd)    
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 9
0
def defaultTest():
  
  str_time = time.time()
    
  (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/speech-female.wav'))
  w = np.hamming(801)
  N = 1024
  t = -120
  maxnS = 30
  stocf = 0.5
  y, yh, ys = sps(x, fs, w, N, t, maxnS, stocf)

  print "time taken for computation " + str(time.time()-str_time)  
Esempio n. 10
0
def defaultTest():
    
    str_time = time.time()
    fs, x = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/soprano-E4.wav'))
    fs, x2 = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/violin-B3.wav'))
    
    
    w = np.hamming(1025)
    N = 2048
    t = -150
    nH = 200
    minf0 = 100
    maxf0 = 400
    f0et = 5
    maxhd = 0.2
    stocf = 0.1
    dur = x.size/fs
    f0intp = np.array([[ 0, dur], [0, 1]])
    htintp = np.array([[ 0, dur], [0, 1]]) 
    rintp = np.array([[ 0, dur], [0, 1]])
    y, yh, ys = hpsMorph(x, x2, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, f0intp, htintp, rintp)

    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 11
0
def defaultTest():
    str_time = time.time()
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/sax-phrase-short.wav'))
    w = np.blackman(801)
    N = 1024
    t = -90
    nH = 50
    minf0 = 350
    maxf0 = 700
    f0et = 10
    maxhd = 0.2
    stocf = 0.2
    y, yh, yst = hpsModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 12
0
def defaultTest():
    str_time = time.time()
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../sounds/speech-female.wav"))
    w = np.blackman(801)
    N = 1024
    t = -90
    nH = 50
    minf0 = 350
    maxf0 = 700
    f0et = 10
    maxhd = 0.2
    stocf = 0.5
    maxnpeaksTwm = 5
    y, yh, ys = hps(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, maxnpeaksTwm)
    print "time taken for computation " + str(time.time() - str_time)
Esempio n. 13
0
def defaultTest():
    
    str_time = time.time()
      
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe-A4.wav'))
    w = np.blackman(801)
    N = 1024
    t = -80
    nH = 30
    minf0 = 400
    maxf0 = 600
    f0et = 5
    maxhd = 0.2
    stocf = 0.5
    y, yh, ys = hpsModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)

    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 14
0
def defaultTest():
    
    str_time = time.time()
      
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/speech-female.wav'))
    w = np.hamming(1025)
    N = 1024
    t = -120
    nH = 30
    minf0 = 200
    maxf0 = 500
    f0et = 5
    maxhd = 0.2
    stocf = 0.5
    y, yh, ys = hpsModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)

    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 15
0
def defaultTest():
    
    str_time = time.time()
   
    #(fs, x) = wp.wavread('../../sounds/oboe.wav')
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe.wav'))
    w = np.hamming(1025)
    N = 1024
    t = -120
    nH = 30
    minf0 = 200
    maxf0 = 500
    f0et = 2
    maxhd = 0.2
    y, yh, yr = hprModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd)
    
    print "time taken for computation " + str(time.time()-str_time)
Esempio n. 16
0
    N = 1024
    t = -80
    nH = 30
    minf0 = 400
    maxf0 = 600
    f0et = 5
    maxhd = 0.2
    stocf = 0.5
    y, yh, ys = hpsModel(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)

    print "time taken for computation " + str(time.time()-str_time)
    
    
if __name__ == '__main__':
      
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe-A4.wav'))
    w = np.blackman(801)
    N = 1024
    t = -80
    nH = 30
    minf0 = 400
    maxf0 = 600
    f0et = 5
    maxhd = 0.2
    stocf = 0.5
    y, yh, ys = hpsModel(x[0:44100], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)


    wp.play(y, fs)
    wp.play(yh, fs)
    wp.play(ys, fs)
            final_peaks = hloc[ind]
            parray = np.zeros([final_peaks.size,2])
            parray[:,0]=pin/float(fs)
            parray[:,1]=final_peaks*float(fs)/N
            specPeaks = np.append(specPeaks, parray,axis=0)
        pin += H
        frmNum += 1
    frmTime = np.array(frmTime)                               # The time at the centre of the frames
    plt.hold(True)
    plt.pcolormesh(frmTime,binFreq,YSpec)
    plt.scatter(specPeaks[:,0]+(0.5*H/float(fs)), specPeaks[:,1], s=10, marker='x')
    plt.xlabel('Time(s)')
    plt.ylabel('Frequency(Hz)')
    plt.autoscale(tight=True)
    plt.show()
    return YSpec

# example call of sineModelPlot function
if __name__ == '__main__':
    (fs, x) = wp.wavread('../../../../sounds/sax-phrase-short.wav')
    w = np.blackman(901)
    N = 2048
    t = -70
    nH = 10
    minf0 = 300
    maxf0 = 650
    f0et = 4
    maxhd = 0.2
    maxFreq = fs/15.0
    YSpec = harmonicModelPlot(x,fs,w,N,t,nH, minf0, maxf0, f0et, maxhd, maxFreq)
   
Esempio n. 18
0
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hamming, triang, blackmanharris
from scipy.fftpack import fft, ifft, fftshift
import math
import sys, os, functools, time

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/spectralModels/'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/basicFunctions/'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/spectralModelsPlotting/'))

import hprModel, hpsModel, hprModelSpectrogramPlot
import smsWavplayer as wp

if __name__ == '__main__':
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../sounds/speech-male.wav'))
    w = np.blackman(1001)
    N = 1024
    t = -90
    nH = 100
    minf0 = 60
    maxf0 = 180
    f0et = 3
    maxhd = 0.2
    maxFreq = 1000
    start = 0*fs
    end = x.size
    maxnpeaksTwm = 5
    stocf = .2
    #y, yh, yr = hprModel.hprModel(x[start:end], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, maxnpeaksTwm)
    hprModelSpectrogramPlot.hprModelPlot(x[start:end], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, maxFreq, maxnpeaksTwm)
Esempio n. 19
0
    ys[ri:ri+Ns] += sw*ysw                                       # overlap-add for sines
    yst[ri:ri+Ns] += sw*ystw                                       # overlap-add for residual
    pin += H                                                     # advance sound pointer
  
  y = ys+yst                                                      # sum of sinusoidal and residual components
  return y, ys, yst


def defaultTest():
    str_time = time.time()
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/mridangam.wav'))
    w = np.blackman(601)
    N = 2048
    t = -70
    stocf = 0.2
    y, ys, yst = spsModel(x, fs, w, N, t, stocf)
    print "time taken for computation " + str(time.time()-str_time)
  
if __name__ == '__main__':
    
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/mridangam.wav'))
    w = np.blackman(601)
    N = 2048
    t = -70
    stocf = 0.2
    y, ys, yst = spsModel(x, fs, w, N, t, stocf)

    wp.play(y, fs)
    wp.play(ys, fs)
    wp.play(yst, fs)
Esempio n. 20
0
    iploc, ipmag, ipphase = PP.peakInterp(mX, pX, ploc)   # refine peak values by interpolation
  
  #-----synthesis-----
    plocs = iploc*Ns/N;                                   # adapt peak locations to size of synthesis FFT
    Y = GS.genSpecSines(plocs, ipmag, ipphase, Ns)        # generate sines in the spectrum         
    fftbuffer = np.real( ifft(Y) )                        # compute inverse FFT
    yw[:hNs-1] = fftbuffer[hNs+1:]                        # undo zero-phase window
    yw[hNs-1:] = fftbuffer[:hNs+1] 
    y[pin-hNs:pin+hNs] += sw*yw                           # overlap-add and apply a synthesis window
    pin += H                                              # advance sound pointer
    
  return y

def defaultTest():
  str_time = time.time()
    
  (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/oboe-A4.wav'))
  w = np.hamming(511)
  N = 1024
  t = -60
  y = sineModel(x, fs, w, N, t)
  print "time taken for computation " + str(time.time()-str_time)  
  
# example call of sineModel function
if __name__ == '__main__':
  (fs, x) = wp.wavread('../../sounds/oboe-A4.wav')
  w = np.hamming(511)
  N = 1024
  t = -60
  y = sineModel(x, fs, w, N, t)
  wp.play(y, fs)
    fftbuffer = np.real( ifft(Y) )                         # inverse FFT
    y[pin-hM:pin+hM] += H*ws*fftbuffer                     # overlap-add
    pin += H 
    frmNum += 1
  
  frmTime = np.array(frmTime)                               # The time at the centre of the frames
  plt.figure(1)
  plt.subplot(2,1,1)
  plt.pcolormesh(frmTime,binFreq,XSpec)
  plt.autoscale(tight=True)
  plt.title('X spectrogram')

  plt.subplot(2,1,2)
  plt.pcolormesh(frmTime,binFreq,YSpec)
  plt.autoscale(tight=True)
  plt.title('X stochastic approx. spectrogram')
  plt.show()
  
  return y    
    
# example call of stochasticModel function
if __name__ == '__main__':
  (fs, x) = wp.wavread('../../sounds/ocean.wav')
  w = np.hamming(1024)
  N = 1024
  H = 512
  stocf = 0.3
  maxFreq = fs
  y = stochasticModelSpectrogramPlot(x, w, N, H, stocf, maxFreq)
  wp.play(y, fs)
Esempio n. 22
0
    # -----synthesis-----
    mY = resample(mXenv, hN)  # interpolate to original size
    pY = 2 * np.pi * np.random.rand(hN)  # generate phase random values
    Y = np.zeros(N, dtype=complex)
    Y[:hN] = 10 ** (mY / 20) * np.exp(1j * pY)  # generate positive freq.
    Y[hN + 1 :] = 10 ** (mY[:0:-1] / 20) * np.exp(-1j * pY[:0:-1])  # generate negative freq.

    fftbuffer = np.real(ifft(Y))  # inverse FFT
    y = ws * fftbuffer * N / 2  # overlap-add

    return mX, pX, mY, pY, y


# example call of stochasticModel function
if __name__ == "__main__":
    (fs, x) = wp.wavread("../../../../sounds/ocean.wav")
    w = np.hanning(1024)
    N = 1024
    stocf = 0.2
    maxFreq = 10000.0
    lastbin = N * maxFreq / fs
    first = 1000
    last = first + w.size
    mX, pX, mY, pY, y = stochasticModel(x[first:last], w, N, stocf)

    plt.figure(1)
    plt.subplot(4, 1, 1)
    plt.plot(np.arange(first, last) / float(fs), x[first:last] * w)
    plt.axis([first / float(fs), last / float(fs), min(x[first:last] * w), max(x[first:last] * w)])
    plt.title("xw")
    plt.subplot(4, 1, 2)
Esempio n. 23
0
    minf0 = 100
    maxf0 = 400
    f0et = 5
    maxhd = 0.2
    stocf = 0.1
    dur = x.size/fs
    f0intp = np.array([[ 0, dur], [0, 1]])
    htintp = np.array([[ 0, dur], [0, 1]]) 
    rintp = np.array([[ 0, dur], [0, 1]])
    y, yh, ys = hpsMorph(x, x2, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, f0intp, htintp, rintp)

    print "time taken for computation " + str(time.time()-str_time)
  
if __name__ == '__main__':
      
    fs, x = wp.wavread('../../sounds/soprano-E4.wav')
    fs, x2 = wp.wavread('../../sounds/violin-B3.wav')

    w = np.hamming(1025)
    N = 2048
    t = -150
    nH = 200
    minf0 = 100
    maxf0 = 400
    f0et = 5
    maxhd = 0.2
    stocf = 0.1
    dur = x.size/fs
    f0intp = np.array([[ 0, dur], [0, 1]])
    htintp = np.array([[ 0, dur], [0, 1]]) 
    rintp = np.array([[ 0, dur], [0, 1]])
Esempio n. 24
0
  yhw[hNs-1:] = fftbuffer[:hNs+1] 
    
  fftbuffer = np.zeros(Ns)
  fftbuffer = np.real(ifft(Yr))                                # inverse FFT of residual spectrum
  yrw[:hNs-1] = fftbuffer[hNs+1:]                              # undo zero-phase window
  yrw[hNs-1:] = fftbuffer[:hNs+1]
    
  yh[ri:ri+Ns] += sw*yhw                                       # overlap-add for sines
  yr[ri:ri+Ns] += sw*yrw                                       # overlap-add for residual
  
  y = yh+yr                                                      # sum of harmonic and residual components
  return mX, hloc, hmag, mXr, mYh, mYr, mYs

  
if __name__ == '__main__':
  (fs, x) = wp.wavread('../../../../sounds/flute-A4.wav')
  w = np.blackman(601)
  N = 2048
  Ns = 512
  t = -90
  nH = 30
  minf0 = 350
  maxf0 = 600
  f0et = 10
  maxhd = 0.2
  stocf = .2
  maxFreq = 10000.0
  lastbin = N*maxFreq/fs
  first = 40000
  last = first+w.size
  mX, hloc, hmag, mXr, mYh, mYr, mYs = hprModelFrame(x[first:last], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf)
Esempio n. 25
0
import matplotlib.pyplot as plt
import numpy as np
from scipy.fftpack import fft
import smsWavplayer as wp

N = 1024
hN = N/2
M = 601
hM = (M+1)/2
w = np.blackman(M)

(fs, x) = wp.wavread('oboe.wav')
xw = x[40000:40000+M] * w

plt.figure(1)
fftbuffer = np.zeros(N)                         
fftbuffer[:hM] = xw[hM-1:] 
fftbuffer[N-hM+1:] = xw[:hM-1]
plt.subplot(3,1,1)
plt.plot(np.arange(N), fftbuffer, 'b')
plt.axis([0, N, min(xw), max(xw)])
plt.title('fftbuffer')

X = fft(fftbuffer)
mX = 20*np.log10(abs(X[:hN]))       
plt.subplot(3,1,2)
plt.plot(fs*np.arange(hN)/float(N),mX, 'r')
plt.axis([250,3300,-20,max(mX)])
plt.title('Magintude spectrum: abs(X)')

pX = np.unwrap(np.angle(X[0:hN]))       
Esempio n. 26
0
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hamming, triang, blackmanharris
from scipy.fftpack import fft, ifft, fftshift
import math
import sys, os, functools, time

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/spectralModels/'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/basicFunctions/'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../code/spectralModelsPlotting/'))

import hprModel, hpsModel, hprModelSpectrogramPlot
import smsWavplayer as wp

if __name__ == '__main__':
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../sounds/sax-phrase.wav'))
    w = np.blackman(801)
    N = 1024
    t = -90
    nH = 50
    minf0 = 340
    maxf0 = 700
    f0et = 7
    maxhd = 0.2
    maxFreq = 2000
    start = 0*fs
    end = x.size
    maxnpeaksTwm = 5
    stocf = .2
    y, yh, yr = hprModel.hprModel(x[start:end], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, maxnpeaksTwm)
    y, yh, yst = hpsModel.hpsModel(x[start:end], fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, maxnpeaksTwm)
Esempio n. 27
0
    w = np.blackman(801)
    N = 1024
    t = -90
    nH = 50
    minf0 = 350
    maxf0 = 700
    f0et = 10
    maxhd = 0.2
    stocf = 0.5
    maxnpeaksTwm = 5
    y, yh, ys = hps(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, maxnpeaksTwm)
    print "time taken for computation " + str(time.time() - str_time)


if __name__ == "__main__":
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../sounds/speech-female.wav"))
    w = np.blackman(901)
    N = 1024
    t = -90
    nH = 40
    minf0 = 100
    maxf0 = 400
    f0et = 3
    maxhd = 0.1
    stocf = 0.5
    maxnpeaksTwm = 5
    y, yh, ys = hps(x, fs, w, N, t, nH, minf0, maxf0, f0et, maxhd, stocf, maxnpeaksTwm)

    wp.play(y, fs)
    wp.play(yh, fs)
    wp.play(ys, fs)
Esempio n. 28
0
def defaultTest():
    
    str_time = time.time()
	  
    (fs, x) = wp.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/speech-female.wav'))
    
    w = np.hamming(801)
    N = 1024
    t = -120
    maxnS = 30
    stocf = 0.5
    y, yh, ys = spsTimescale(x, fs, w, N, t, maxnS, stocf)

    print "time taken for computation " + str(time.time()-str_time)
  
if __name__ == '__main__':     
	  
    (fs, x) = wp.wavread('../../sounds/speech-female.wav')
    # wp.play(x, fs)

    w = np.hamming(801)
    N = 1024
    t = -120
    maxnS = 30
    stocf = 0.5
    y, yh, ys = spsTimescale(x, fs, w, N, t, maxnS, stocf)

    wp.play(x, fs)
    wp.play(y, fs)
    # wp.play(yh, fs)
    # wp.play(ys, fs)