Commits

Phillip Rhoades committed cafb53f

Ramping code cleanup, long duration wav file frame slip fix, misc code cleanups

  • Participants
  • Parent commits 10b99b5

Comments (0)

Files changed (1)

 	smoothed=[0.0]*(len(list)-window)  
 	for i in range(len(smoothed)):  
 		smoothed[i]=sum(numpy.array(list[i:i+window])*weight)/sum(weight)  
+	for i in range(window):
+		smoothed.append(list[( len(list)-(window+i) )])
 	return smoothed  
 
 ### End Smoothing Function ###
 
-
-### This is the ramping code to keep the mouth from tending towards being all closed or tending towards being all open ###  
-'''
-def ramp_mouth(frames, lenpics, rampup, rampdown):
-	if rampup > 100:
-		rampup = 100
-	if rampdown > 100:
-		rampdown = 100
-	frames_ramped = []
-	maxframes = max(frames)
-	step = maxframes/lenpics
-	rampstepup = (step/100)*rampup
-	rampstepdown = step-((step/100)*rampdown)
-
-	for i in frames:
-		if i < step:
-			if i > (step-rampstepup):
-				print "ramping frame " + str(i) + " UP " + str(rampstepup)
-				i = step + i
-		if i > (maxframes-step):
-			if i < (maxframes-rampstepdown):
-				print "ramping frame " + str(i) + " DOWN " + str(rampstepdown)
-				i = maxframes - step
-		frames_ramped.append(i)
-	return frames_ramped  
-'''
-### End ramping function ###
-
-
 ### This is the ramping code to keep the mouth from tending towards being all closed or tending towards being all open ###  
 
 def ramp_mouth(frames, lenpics, rampup, rampdown):
 wf = wave.open(workingwav, 'rb')
 wfswidth = wf.getsampwidth()
 wfRATE = wf.getframerate()
-wfchunk = wfRATE/framerate
+wfchunk = int(round(wfRATE/float(framerate)))
+#wfchunk = int(wfRATE/float(framerate))
+wfchunkfloat = wfRATE/float(framerate)
+sliprate = wfchunk-wfchunkfloat
+#print "Chunk difference = " + str(wfchunk) + " - " + str(wfchunkfloat) + " " + str(sliprate)
 # use a Blackman window
 wfwindow = numpy.blackman(wfchunk)
 wfframes=wf.getnframes()
 wfduration=wfframes/float(wfRATE)
-
-slice = wfRATE/int(framerate)
+totalframes = int(round(wfduration*framerate))
+slipcounter = 0
 frames = []
 
 ### END Other Misc Prep ###
 ### The Real Mouth Work ###
 max_mouthOpen = len(pics)-1
 
+
 isonframe = 0
 
-for framecounter in range(0,wfframes,slice):
+for framecounter in range(0,totalframes):
 	isonframe = isonframe + 1
-	#samples = map(lambda x:ord(x)-128,dat[i:i+slice])
-	wfdata = wf.readframes(wfchunk)
+	if slipcounter >= wfchunk:
+		slipcounter = slipcounter - wfchunk
+	elif slipcounter <= (wfchunk*-1):
+		wfdata = wf.readframes(wfchunk)
+		wfdata = wf.readframes(wfchunk)
+		slipcounter = slipcounter + wfchunk
+	elif slipcounter > (wfchunk*-1) and slipcounter < wfchunk:
+		wfdata = wf.readframes(wfchunk)
 	if len(wfdata) == wfchunk*wfswidth:
+		wfdataold = wfdata
 		wfindata = numpy.array(wave.struct.unpack("%dh"%(len(wfdata)/wfswidth),wfdata))*wfwindow
-		volume = [numpy.log10(numpy.sqrt(i)) for i in wfindata]
-		volume2 = [x for x in volume if x > 0]
-		volume = sum(volume2) / len(volume)
+		volume1 = [numpy.log10(numpy.sqrt(i)) for i in wfindata]
+		volume2 = [x for x in volume1 if x > 0]
+		volume = sum(volume2) / len(volume1)
 		if math.isnan(volume) is True:
 			volume = 0
-		print str(isonframe) + " " + str(volume)
-	frames.append(volume)
-
-#Decrease "volume" of volume data without modifying wav file
-#frames[:] = [x * .01 for x in frames] 
+		print "Processing frame volumes " + str(isonframe) + " " + str(volume) + " Slip Counter: " + str(slipcounter)
+		frames.append(volume)
+	slipcounter = slipcounter + sliprate
 
 if rampingup != 0 or rampingdown != 0:
 	frames = ramp_mouth(frames, len(pics), rampingup, rampingdown)
 
-if smoothdegree>0:
+if smoothdegree > 0:
 	frames = smoothListGaussian(frames,smoothdegree)
 
-step = max(frames)/max_mouthOpen
 
+step = max(frames)/max_mouthOpen
 #open up a wave
 wf.close()
 wf = wave.open(workingwav, 'rb')
 wfswidth = wf.getsampwidth()
 wfRATE = wf.getframerate()
-wfchunk = wfRATE/framerate
+wfchunk = int(wfRATE/float(framerate))
 # use a Blackman window
 wfwindow = numpy.blackman(wfchunk)
 wfframes=wf.getnframes()
 			else:
 				mouthlist += (pics[mouth])
 				mouthlist += ','
-	print "Building mouth files %i" % int(i)
+	print "Building mouth files " + str(int(i)+1)
 
 ### END The Real Mouth Work ###
 
 	# ------------------------------
 	# Then alpha mov encoding happens
 	# ------------------------------
-	convcmd = "avconv -y -i %s/working.wav -r %i -i %s/frame%s.png -acodec libmp3lame -vcodec qtrle -pix_fmt argb -r %i %s.mov -r %i" % (framedir,framerate,framedir,'%9d',framerate, outputfile, framerate)
+	#convcmd = "avconv -y -i %s/working.wav -r %i -i %s/frame%s.png -acodec libmp3lame -vcodec qtrle -pix_fmt argb -r %i %s.mov -r %i" % (framedir,framerate,framedir,'%9d',framerate, outputfile, framerate)
+	convcmd = "avconv -y -i %s/working.wav -r %i -i %s/frame%s.png -acodec libmp3lame -vcodec qtrle -pix_fmt argb %s.mov" % (framedir,framerate,framedir,'%9d', outputfile)
 	thread = pexpect.spawn(convcmd)
 	cpl = thread.compile_pattern_list([
 		pexpect.EOF,