Exemple #1
0
w = np.blackman(1501)
N = 2048
t = -90
minf0 = 100
maxf0 = 300
f0et = 1
maxnpeaksTwm = 4
H = 128
x1 = x[1.5*fs:1.8*fs]

plt.figure(1, figsize=(9, 7))
mX, pX = STFT.stftAnal(x, fs, w, N, H)
f0 = HM.f0Twm(x, fs, w, N, H, t, minf0, maxf0, f0et)
f0 = UF.cleaningTrack(f0, 5)
yf0 = SM.sinewaveSynth(f0, np.array([0.4]), H, fs)
UF.play(yf0,fs)
f0[f0==0] = np.nan
maxplotfreq = 800.0
numFrames = int(f0.size)
frmTime = H*np.arange(numFrames)/float(fs)                             
binFreq = fs*np.arange(N*maxplotfreq/fs)/N                        
plt.pcolormesh(frmTime, binFreq, np.transpose(mX[:,:N*maxplotfreq/fs+1]))
plt.autoscale(tight=True)
plt.plot(frmTime, f0, linewidth=2, color='k')
plt.autoscale(tight=True)
plt.title('mX + f0 (piano.wav), TWM')

plt.tight_layout()
plt.show()

		pin2 += H2                                     # advance sound pointer
	y = np.delete(y, range(hM1_2))                   # delete half of first window which was added in stftAnal
	y = np.delete(y, range(y.size-hM1_1, y.size))    # add zeros at the end to analyze last sample
	return y

# example call of stftMorph function
if __name__ == '__main__':
	(fs, x1) = UF.wavread('../../sounds/ocean.wav')
	(fs, x2) = UF.wavread('../../sounds/speech-male.wav')
	w1 = np.hamming(1024)
	N1 = 1024
	H1 = 256
	w2 = np.hamming(1024)
	N2 = 1024
	smoothf = .5
	balancef = 0.2
	y = stftMorph(x1, x2, fs, w1, N1, w2, N2, H1, smoothf, balancef)

	w = np.hamming(1024)
	N = 1024
	H = 256
	# design a band stop filter using a hanning window
	startBin = int(N*2000.0/fs)
	nBins = int(N*3000.0/fs)
	bandstop = -np.hanning(nBins) * 40.0
	filt = np.zeros(N/2)
	filt[startBin:startBin+nBins] = bandstop

	y = stftFiltering(y, fs, w, N, H, filt)
	UF.play(y, fs)
Exemple #3
0
  maxnSines = 200
  freqDevOffset = 10
  freqDevSlope = 0.001
  tfreq, tmag, tphase = SM.sineModelAnal(x, fs, w, N, H, t, maxnSines, minSineDur, freqDevOffset, freqDevSlope)
  xr = UF.sineSubtraction(x, N, H, tfreq, tmag, tphase, fs)
  mXr, pXr = STFT.stftAnal(xr, fs, hamming(H*2), H*2, H)
  Ns = 512
  ys = SM.sineModelSynth(tfreq, tmag, tphase, Ns, H, fs)

  plt.figure(1, figsize=(9.5, 7))
  numFrames = int(mXr[:,0].size)
  frmTime = H*np.arange(numFrames)/float(fs)                             
  binFreq = np.arange(H)*float(fs)/(H*2)                       
  plt.pcolormesh(frmTime, binFreq, np.transpose(mXr))
  plt.autoscale(tight=True)

  tfreq[tfreq==0] = np.nan
  numFrames = int(tfreq[:,0].size)
  frmTime = H*np.arange(numFrames)/float(fs) 
  plt.plot(frmTime, tfreq, color='k', ms=3, alpha=1)
  plt.xlabel('Time(s)')
  plt.ylabel('Frequency(Hz)')
  plt.autoscale(tight=True)
  plt.title('sinusoidal + residual components')

  UF.play(ys, fs)
  UF.play(xr, fs)

  plt.tight_layout()
  plt.show()
Exemple #4
0
	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 = hpsModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, minSineDur, Ns, stocf)
	y, yh, yst = hpsModelSynth(hfreq, hmag, hphase, mYst, Ns, H, fs)
 
	UF.play(y, fs)
	UF.play(yh, fs)
	UF.play(yst, fs)

	plt.figure(1, figsize=(9.5, 7)) 
	maxplotfreq = 20000.0
	numFrames = int(mYst[:,0].size)
	sizeEnv = int(mYst[0,:].size)
	frmTime = H*np.arange(numFrames)/float(fs)
	binFreq = (.5*fs)*np.arange(sizeEnv*maxplotfreq/(.5*fs))/sizeEnv                      
	plt.pcolormesh(frmTime, binFreq, np.transpose(mYst[:,:sizeEnv*maxplotfreq/(.5*fs)+1]))
	plt.autoscale(tight=True)

	harms = hfreq*np.less(hfreq,maxplotfreq)
	harms[harms==0] = np.nan
	numFrames = int(harms[:,0].size)
		yhfreq[l,ind_valid] = yhfreq[l,ind_valid] * freqScaling[l]
	
	return yhfreq, yhmag

if __name__ == '__main__':
	(fs, x) = UF.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../sounds/soprano-E4.wav'))
	w = np.blackman(801)
	N = 1024
	t = -90
	nH = 100
	minf0 = 250
	maxf0 = 400
	f0et = 8
	minSineDur = .1
	harmDevSlope = 0.01
	Ns = 512
	H = Ns/4
	hfreq, hmag, hphase = HM.harmonicModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, minSineDur)
	freqScaling = np.array([0, 3, 1, .5])
	freqStretching = np.array([])
	timbrePreservation = 1
	hfreqt, hmagt = harmonicFreqScaling(hfreq, hmag, freqScaling, freqStretching, timbrePreservation, fs)
	timeScaling = np.array([0, 0, 1, .5, 2, 4])
	hfreqt, hmagt = ST.sineTimeScaling(hfreq, hmag, timeScaling)
	yh = SM.sineModelSynth(hfreqt, hmagt, np.array([]), Ns, H, fs) 
	UF.play(yh, fs)  
		



import math
import sys, os, time

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../software/models/'))

import stft as STFT
import utilFunctions as UF
import harmonicModel as HM


(fs, x) = UF.wavread(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../sounds/cello-double.wav'))
w = np.blackman(3501)
N = 2048*2
t = -100
nH = 100
minf0 = 140
maxf0 = 150
f0et = 10
minSineDur = .2
harmDevSlope = 0.001
Ns = 512
H = Ns/4

hfreq, hmag, hphase = HM.harmonicModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, minSineDur)
y = HM.harmonicModelSynth(hfreq, hmag, hphase, Ns, H, fs)
xr = UF.sineSubtraction(x, Ns, H, hfreq, hmag, hphase, fs)

UF.play(x, fs)
UF.play(y, fs)
UF.play(xr, fs)
Exemple #7
0
  t = -100
  nH = 100
  minf0 = 350
  maxf0 = 700
  f0et = 5
  maxnpeaksTwm = 5
  minSineDur = .1
  harmDevSlope = 0.01
  Ns = 512
  H = Ns/4
  hfreq, hmag, hphase = HM.harmonicModelAnal(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope, minSineDur)
  xr = UF.sineSubtraction(x, Ns, H, hfreq, hmag, hphase, fs)
  mXr, pXr = STFT.stftAnal(xr, fs, hamming(Ns), Ns, H)
  yh = HM.harmonicModelSynth(hfreq, hmag, hphase, Ns, H, fs)

  UF.play(yh, fs)
  UF.play(xr, fs)


  plt.figure(1, figsize=(9.5, 7))
  maxplotfreq = 20000.0
  numFrames = int(mXr[:,0].size)
  frmTime = H*np.arange(numFrames)/float(fs)                             
  binFreq = fs*np.arange(Ns*maxplotfreq/fs)/Ns                        
  plt.pcolormesh(frmTime, binFreq, np.transpose(mXr[:,:Ns*maxplotfreq/fs+1]))
  plt.autoscale(tight=True)

  harms = hfreq*np.less(hfreq,maxplotfreq)
  harms[harms==0] = np.nan
  numFrames = int(harms[:,0].size)
  frmTime = H*np.arange(numFrames)/float(fs)