def defaultTest(): str_time = time.time() (fs, x) = WIO.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)
import matplotlib.pyplot as plt import numpy as np import sys import math sys.path.append('../../../software/models/') import waveIO as WIO import dftAnal as DF (fs, x) = WIO.wavread('../../../sounds/violin-B3.wav') w = np.hamming(1024) N = 1024 pin = 5000 hM1 = int(math.floor((w.size+1)/2)) hM2 = int(math.floor(w.size/2)) x1 = x[pin-hM1:pin+hM2] mX, pX = DF.dftAnal(x1, w, N) plt.figure(1, figsize=(9.5, 5)) plt.subplot(311) plt.plot(np.arange(-hM1, hM2), x1, lw=1.5) plt.axis([-hM1, hM2, min(x1), max(x1)]) plt.ylabel('amplitude') plt.title('x (violin-B3.wav)') plt.subplot(3,1,2) plt.plot(np.arange(N/2), mX, 'r', lw=1.5) plt.axis([0,N/2,-90,max(mX)]) plt.title ('magnitude spectrum: mX = 20*log10(abs(X))') plt.ylabel('amplitude (dB)')
import matplotlib.pyplot as plt import numpy as np import sys import math sys.path.append('../../../software/models/') import waveIO as WIO import dftAnal as DF (fs, x) = WIO.wavread('../../../sounds/violin-B3.wav') w = np.hamming(1024) N = 1024 pin = 5000 hM1 = int(math.floor((w.size + 1) / 2)) hM2 = int(math.floor(w.size / 2)) x1 = x[pin - hM1:pin + hM2] mX, pX = DF.dftAnal(x1, w, N) plt.figure(1, figsize=(9.5, 5)) plt.subplot(311) plt.plot(np.arange(-hM1, hM2), x1, lw=1.5) plt.axis([-hM1, hM2, min(x1), max(x1)]) plt.ylabel('amplitude') plt.title('x (violin-B3.wav)') plt.subplot(3, 1, 2) plt.plot(np.arange(N / 2), mX, 'r', lw=1.5) plt.axis([0, N / 2, -90, max(mX)]) plt.title('magnitude spectrum: mX = 20*log10(abs(X))') plt.ylabel('amplitude (dB)')
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) = WIO.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) = WIO.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) WIO.play(y, fs) WIO.play(ys, fs) WIO.play(yst, fs)
from scipy.signal import hamming, triang, blackmanharris from scipy.fftpack import ifft, fftshift import math import sys, os, functools, time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import sineModelAnal as SA import sineModelSynth as SS import waveIO as WIO import sineSubtraction as SSub (fs, x) = WIO.wavread('../../../sounds/carnatic.wav') w = np.blackman(2001) N = 2048 t = -90 minSineDur = .2 maxnSines = 200 freqDevOffset = 20 freqDevSlope = 0.02 Ns = 512 H = Ns/4 tfreq, tmag, tphase = SA.sineModelAnal(x, fs, w, N, H, t, maxnSines, minSineDur, freqDevOffset, freqDevSlope) y = SS.sineModelSynth(tfreq, tmag, tphase, Ns, H, fs) xr = SSub.sineSubtraction(x, Ns, H, tfreq, tmag, tphase, fs) #mXr, pXr = ST.stftAnal(xr, fs, hamming(H*2), H*2, H)
import matplotlib.pyplot as plt import numpy as np import time, os, sys import math from scipy.signal import blackman sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions_C/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import waveIO as WIO import dftAnal as DF (fs, x) = WIO.wavread('../../../sounds/piano.wav') pin = .3*fs w = np.blackman(1001) N = 1024 hM1 = int(math.floor((w.size+1)/2)) hM2 = int(math.floor(w.size/2)) x1 = x[pin-hM1:pin+hM2] mX, pX = DF.dftAnal(x1, w, N) plt.figure(1) plt.subplot(311) plt.plot(np.arange(-hM1, hM2)/float(fs), x1, lw=1.5) plt.axis([-hM1/float(fs), hM2/float(fs), min(x1), max(x1)]) plt.ylabel('amplitude') plt.title('x (piano.wav)') plt.subplot(3,1,2) plt.plot(fs*np.arange(N/2)/float(N), mX, 'r', lw=1.5)
mXenv = resample(np.maximum(-200, mX), mX.size*stocf) # decimate the mag spectrum pX = np.angle(X[:hN]) #-----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 = fftbuffer*N/2 return mX, pX, mY, pY, y # example call of stochasticModel function if __name__ == '__main__': (fs, x) = WIO.wavread('../../../sounds/ocean.wav') w = np.hanning(1024) N = 1024 stocf = 0.1 maxFreq = 10000.0 lastbin = N*maxFreq/fs first = 1000 last = first+w.size mX, pX, mY, pY, y = stochasticModelFrame(x[first:last], w, N, stocf) plt.figure(1) plt.subplot(3,1,1) plt.plot(np.arange(0, fs/2.0, fs/float(N)), mY, 'r', label="mY") plt.axis([0, maxFreq, -80, max(mX)+3]) plt.title('magnitude spectrum (approx of mX)') plt.subplot(3,1,2)
import numpy as np import matplotlib.pyplot as plt from scipy.signal import hamming, hanning, triang, blackmanharris, resample import math import sys, os, time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import stftAnal as STFT import waveIO as WIO import harmonicModelAnal as HA import sineSubtraction as SS (fs, x) = WIO.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../sounds/flute-A4.wav')) w = np.blackman(551) N = 1024 t = -100 nH = 40 minf0 = 420 maxf0 = 460 f0et = 5 maxnpeaksTwm = 5 minSineDur = .1 harmDevSlope = 0.01 Ns = 512 H = Ns/4 mX, pX = STFT.stftAnal(x, fs, w, N, H) hfreq, hmag, hphase = HA.harmonicModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, maxnpeaksTwm, minSineDur)
import matplotlib.pyplot as plt import numpy as np import sys import math sys.path.append('../../../software/basicFunctions/') sys.path.append('../../../software/models/') import waveIO as WIO import dftAnal as DF (fs, x) = WIO.wavread('../../../sounds/oboe-A4.wav') w = np.hamming(511) N = 512 pin = 5000 hM1 = int(math.floor((w.size+1)/2)) hM2 = int(math.floor(w.size/2)) x1 = x[pin-hM1:pin+hM2] mX, pX = DF.dftAnal(x1, w, N) plt.figure(1, figsize=(9.5, 7)) plt.subplot(311) plt.plot(np.arange(-hM1, hM2), x1, lw=1.5) plt.axis([-hM1, hM2, min(x1), max(x1)]) plt.ylabel('amplitude') plt.title('x (oboe-A4.wav)') plt.subplot(3,1,2) plt.plot(np.arange(N/2), mX, 'r', lw=1.5) plt.axis([0,N/2,min(mX),max(mX)])
import matplotlib.pyplot as plt from scipy.signal import hamming, triang, blackmanharris import math from scipy.fftpack import fft, ifft, fftshift import sys, os, functools, time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/basicFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import dftAnal as DFT import waveIO as WIO import peakProcessing as PP import harmonicDetection as HD import genSpecSines as GS import twm as TWM (fs, x) = WIO.wavread('../../../sounds/flute-A4.wav') pos = .8*fs M = 601 hM1 = int(math.floor((M+1)/2)) hM2 = int(math.floor(M/2)) w = np.hamming(M) N = 1024 t = -100 nH = 40 minf0 = 420 maxf0 = 460 f0et = 5 maxnpeaksTwm = 5 minSineDur = .1 harmDevSlope = 0.01 Ns = 512
import matplotlib.pyplot as plt import numpy as np import sys import math sys.path.append('../../../software/basicFunctions/') sys.path.append('../../../software/models/') import waveIO as WIO import dftAnal as DF (fs, x) = WIO.wavread('../../../sounds/oboe-A4.wav') w = np.hamming(511) N = 512 pin = 5000 hM1 = int(math.floor((w.size + 1) / 2)) hM2 = int(math.floor(w.size / 2)) x1 = x[pin - hM1:pin + hM2] mX, pX = DF.dftAnal(x1, w, N) plt.figure(1, figsize=(9.5, 7)) plt.subplot(311) plt.plot(np.arange(-hM1, hM2), x1, lw=1.5) plt.axis([-hM1, hM2, min(x1), max(x1)]) plt.ylabel('amplitude') plt.title('x (oboe-A4.wav)') plt.subplot(3, 1, 2) plt.plot(np.arange(N / 2), mX, 'r', lw=1.5) plt.axis([0, N / 2, min(mX), max(mX)])
import numpy as np import matplotlib.pyplot as plt from scipy.signal import hamming, hanning, triang, blackmanharris, resample import math import sys, os, time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import stftAnal as STFT import waveIO as WIO import hpsModelAnal as HA import hpsModelSynth as HS (fs, x) = WIO.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../sounds/sax-phrase-short.wav')) w = np.blackman(601) N = 1024 t = -100 nH = 100 minf0 = 350 maxf0 = 700 f0et = 5 maxnpeaksTwm = 5 minSineDur = .1 harmDevSlope = 0.01 Ns = 512 H = Ns/4 stocf = .2 hfreq, hmag, hphase, mYst = HA.hpsModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, maxnpeaksTwm, minSineDur, Ns, stocf)
import numpy as np import matplotlib.pyplot as plt from scipy.signal import hamming, hanning, triang, blackmanharris, resample import math import sys, os, time from scipy.fftpack import fft, ifft import essentia.standard as ess sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/utilFunctions/')) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../software/models/')) import waveIO as WIO lpc = ess.LPC(order=14) N= 512 (fs, x) = WIO.wavread('../../../sounds/soprano-E4.wav') first = 20000 last = first+N x1 = x[first:last] X = fft(hamming(N)*x1) mX = 20 * np.log10(abs(X[:N/2])) coeff = lpc(x1) Y = fft(coeff[0], N) mY = 20 * np.log10(abs(Y[:N/2])) plt.figure(1) plt.subplot(2,1,1) plt.plot(np.arange(first, last)/float(fs), x[first:last], 'b') plt.axis([first/float(fs), last/float(fs), min(x[first:last]), max(x[first:last])])