Пример #1
0
def get_audio_energy(path, filename, fps):
  full_path = path + filename
  time, data = audio_to_array(full_path)
  sample_rate = sndfile(full_path).samplerate()
  total_frames = 0
  avg_e = 0.0
  
  for i in xrange(0, len(time), int(sample_rate / fps)):
    data[i] = abs(data[i])
    total_frames = total_frames + 1
    avg_e = avg_e + data[i]

  avg_e = avg_e / total_frames
  t = []
  
  for i in xrange(0, len(time), int(sample_rate / fps)):
    t.append(data[i])

  r = kaiser.convolve_kaiser(70, 5, t)
  energy = []
  max_r = max(r)
  
  for i in range(len(r)):
    v = r[i] / max_r * 100.0 * (1.0 - avg_e)
    energy.append(v)

  return energy
Пример #2
0
	def plotplot(self,wplot,oplots,outplot=None,multiplot = 0):
		from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
		import re
		import Gnuplot
		# audio data
		time,data = audio_to_array(self.input)
		f = make_audio_plot(time,data)

		# check if ground truth exists
		#timet,pitcht = self.gettruth()
		#if timet and pitcht:
		#	oplots = [Gnuplot.Data(timet,pitcht,with_='lines',
		#		title='ground truth')] + oplots

		t = Gnuplot.Data(0,0,with_='impulses') 

		g = gnuplot_init(outplot)
		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
		g('set multiplot')
		# hack to align left axis
		g('set lmargin 15')
		# plot waveform and onsets
		g('set size 1,0.3')
		g('set origin 0,0.7')
		g('set xrange [0:%f]' % max(time)) 
		g('set yrange [-1:1]') 
		g.ylabel('amplitude')
		g.plot(f)
		g('unset title')
		# plot onset detection function


		g('set size 1,0.7')
		g('set origin 0,0')
		g('set xrange [0:%f]' % max(time))
		g('set yrange [20:100]')
		g('set key right top')
		g('set noclip one') 
		#g('set format x ""')
		#g('set log y')
		#g.xlabel('time (s)')
		g.ylabel('f0 (Hz)')
		if multiplot:
			for i in range(len(oplots)):
				# plot onset detection functions
				g('set size 1,%f' % (0.7/(len(oplots))))
				g('set origin 0,%f' % (float(i)*0.7/(len(oplots))))
				g('set xrange [0:%f]' % max(time))
				g.plot(oplots[i])
		else:
			g.plot(*oplots)
Пример #3
0
    def plotplot(self, wplot, oplots, outplot=None, multiplot=0):
        from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
        import re
        import Gnuplot
        # audio data
        time, data = audio_to_array(self.input)
        f = make_audio_plot(time, data)

        # check if ground truth exists
        #timet,pitcht = self.gettruth()
        #if timet and pitcht:
        #	oplots = [Gnuplot.Data(timet,pitcht,with_='lines',
        #		title='ground truth')] + oplots

        t = Gnuplot.Data(0, 0, with_='impulses')

        g = gnuplot_init(outplot)
        g('set title \'%s\'' % (re.sub('.*/', '', self.input)))
        g('set multiplot')
        # hack to align left axis
        g('set lmargin 15')
        # plot waveform and onsets
        g('set size 1,0.3')
        g('set origin 0,0.7')
        g('set xrange [0:%f]' % max(time))
        g('set yrange [-1:1]')
        g.ylabel('amplitude')
        g.plot(f)
        g('unset title')
        # plot onset detection function

        g('set size 1,0.7')
        g('set origin 0,0')
        g('set xrange [0:%f]' % max(time))
        g('set yrange [20:100]')
        g('set key right top')
        g('set noclip one')
        #g('set format x ""')
        #g('set log y')
        #g.xlabel('time (s)')
        g.ylabel('f0 (Hz)')
        if multiplot:
            for i in range(len(oplots)):
                # plot onset detection functions
                g('set size 1,%f' % (0.7 / (len(oplots))))
                g('set origin 0,%f' % (float(i) * 0.7 / (len(oplots))))
                g('set xrange [0:%f]' % max(time))
                g.plot(oplots[i])
        else:
            g.plot(*oplots)
Пример #4
0
	def plotplot(self,wplot,oplots,outplot=None,multiplot = 0):
		from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
		import re
		import Gnuplot
		# audio data
		time,data = audio_to_array(self.input)
		f = make_audio_plot(time,data)

		# check if ground truth exists
		#timet,pitcht = self.gettruth()
		#if timet and pitcht:
		#	oplots = [Gnuplot.Data(timet,pitcht,with='lines',
		#		title='ground truth')] + oplots

		t = Gnuplot.Data(0,0,with='impulses') 
Пример #5
0
    def plotplot(self, wplot, oplots, outplot=None, extension=None, xsize=1.0, ysize=1.0, spectro=False):
        from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec
        import re

        # prepare the plot
        g = gnuplot_create(outplot=outplot, extension=extension)
        g("set title '%s'" % (re.sub(".*/", "", self.input)))
        if spectro:
            g("set size %f,%f" % (xsize, 1.3 * ysize))
        else:
            g("set size %f,%f" % (xsize, ysize))
        g("set multiplot")

        # hack to align left axis
        g("set lmargin 3")
        g("set rmargin 6")

        if spectro:
            import Gnuplot

            minf = 50
            maxf = 500
            data, time, freq = audio_to_spec(self.input, minf=minf, maxf=maxf)
            g("set size %f,%f" % (1.24 * xsize, 0.34 * ysize))
            g("set origin %f,%f" % (-0.12, 0.65 * ysize))
            g("set xrange [0.:%f]" % time[-1])
            g("set yrange [%f:%f]" % (minf, maxf))
            g("set pm3d map")
            g("unset colorbox")
            g("set lmargin 0")
            g("set rmargin 0")
            g("set tmargin 0")
            g("set palette rgbformulae -25,-24,-32")
            g.xlabel("time (s)", offset=(0, 1.0))
            g.ylabel("freq (Hz)")
            g("set origin 0,%f" % (1.0 * ysize))
            g('set format x "%1.1f"')
            # if log:
            # 	g('set yrange [%f:%f]' % (max(10,minf),maxf))
            # 	g('set log y')
            g.splot(Gnuplot.GridData(data, time, freq, binary=1, title=""))
        else:
            # plot waveform and onsets
            time, data = audio_to_array(self.input)
            wplot = [make_audio_plot(time, data)] + wplot
            g("set origin 0,%f" % (0.7 * ysize))
            g("set size %f,%f" % (xsize, 0.3 * ysize))
            g('set format y "%1f"')
            g("set xrange [0:%f]" % max(time))
            g("set yrange [-1:1]")
            g("set noytics")
            g("set y2tics -1,1")
            g.xlabel("time (s)", offset=(0, 0.7))
            g.ylabel("amplitude")
            g.plot(*wplot)

            # default settings for next plots
        g("unset title")
        g('set format x ""')
        g('set format y "%3e"')
        g("set tmargin 0")
        g.xlabel("")

        N = len(oplots)
        y = 0.7 * ysize  # the vertical proportion of the plot taken by onset functions
        delta = 0.035  # the constant part of y taken by last plot label and data
        for i in range(N):
            # plot onset detection functions
            g("set size %f,%f" % (xsize, (y - delta) / N))
            g("set origin 0,%f" % ((N - i - 1) * (y - delta) / N + delta))
            g("set nokey")
            g("set xrange [0:%f]" % (self.lenofunc * self.params.step))
            g("set yrange [0:%f]" % (1.1 * oplots[i][2]))
            g('set y2tics ("0" 0, "%d" %d)' % (round(oplots[i][2]), round(oplots[i][2])))
            g.ylabel(oplots[i][1])
            if i == N - 1:
                g("set size %f,%f" % (xsize, (y - delta) / N + delta))
                g("set origin 0,0")
                g.xlabel("time (s)", offset=(0, 0.7))
                g("set format x")
            g.plot(*oplots[i][0])

        g("unset multiplot")
Пример #6
0
    def plotplot(self,
                 wplot,
                 oplots,
                 titles,
                 outplot=None,
                 extension=None,
                 xsize=1.,
                 ysize=1.,
                 multiplot=1,
                 midi=1,
                 truth=1):
        from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot
        import re
        import Gnuplot

        # check if ground truth exists
        if truth:
            timet, pitcht = self.gettruth()
            if timet and pitcht:
                oplots = [
                    Gnuplot.Data(
                        timet, pitcht, with_='lines', title='ground truth')
                ] + oplots

        g = gnuplot_create(outplot=outplot, extension=extension)
        g('set title \'%s\'' % (re.sub('.*/', '', self.input)))
        g('set size %f,%f' % (xsize, ysize))
        g('set multiplot')
        # hack to align left axis
        g('set lmargin 4')
        g('set rmargin 4')
        # plot waveform
        time, data = audio_to_array(self.input)
        wplot = [make_audio_plot(time, data)]
        g('set origin 0,%f' % (0.7 * ysize))
        g('set size %f,%f' % (xsize, 0.3 * ysize))
        #g('set format y "%1f"')
        g('set xrange [0:%f]' % max(time))
        g('set yrange [-1:1]')
        g('set noytics')
        g('set y2tics -1,1')
        g.xlabel('time (s)', offset=(0, 0.7))
        g.ylabel('amplitude')
        g.plot(*wplot)

        # default settings for next plots
        g('unset title')
        g('set format x ""')
        g('set format y "%3e"')
        g('set tmargin 0')
        g.xlabel('')
        g('set noclip one')

        if not midi:
            g('set log y')
            #g.xlabel('time (s)')
            g.ylabel('f0 (Hz)')
            g('set yrange [100:%f]' % self.params.pitchmax)
        else:
            g.ylabel('midi')
            g('set yrange [%f:%f]' % (aubio_freqtomidi(
                self.params.pitchmin), aubio_freqtomidi(self.params.pitchmax)))
            g('set y2tics %f,%f' %
              (round(aubio_freqtomidi(self.params.pitchmin) + .5), 12))

        if multiplot:
            N = len(oplots)
            y = 0.7 * ysize  # the vertical proportion of the plot taken by onset functions
            delta = 0.035  # the constant part of y taken by last plot label and data
            for i in range(N):
                # plot pitch detection functions
                g('set size %f,%f' % (xsize, (y - delta) / N))
                g('set origin 0,%f' % ((N - i - 1) * (y - delta) / N + delta))
                g('set nokey')
                g('set xrange [0:%f]' % max(time))
                g.ylabel(titles[i])
                if i == N - 1:
                    g('set size %f,%f' % (xsize, (y - delta) / N + delta))
                    g('set origin 0,0')
                    g.xlabel('time (s)', offset=(0, 0.7))
                    g('set format x')
                g.plot(oplots[i])
        else:
            g('set key right top')
            g.plot(*oplots)
        g('unset multiplot')
Пример #7
0
	def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False):
		from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec
		import re
		# prepare the plot
		g = gnuplot_create(outplot=outplot, extension=extension)
		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
		if spectro:
			g('set size %f,%f' % (xsize,1.3*ysize) )
		else:
			g('set size %f,%f' % (xsize,ysize) )
		g('set multiplot')

		# hack to align left axis
		g('set lmargin 3')
		g('set rmargin 6')

		if spectro:
			import Gnuplot
			minf = 50
			maxf = 500 
			data,time,freq = audio_to_spec(self.input,minf=minf,maxf=maxf)
			g('set size %f,%f' % (1.24*xsize , 0.34*ysize) )
			g('set origin %f,%f' % (-0.12,0.65*ysize))
			g('set xrange [0.:%f]' % time[-1]) 
			g('set yrange [%f:%f]' % (minf,maxf))
			g('set pm3d map')
			g('unset colorbox')
			g('set lmargin 0')
			g('set rmargin 0')
			g('set tmargin 0')
			g('set palette rgbformulae -25,-24,-32')
			g.xlabel('time (s)',offset=(0,1.))
			g.ylabel('freq (Hz)')
			g('set origin 0,%f' % (1.0*ysize) ) 
			g('set format x "%1.1f"')
			#if log:
			#	g('set yrange [%f:%f]' % (max(10,minf),maxf))
			#	g('set log y')
			g.splot(Gnuplot.GridData(data,time,freq, binary=1, title=''))
		else:
			# plot waveform and onsets
			time,data = audio_to_array(self.input)
			wplot = [make_audio_plot(time,data)] + wplot
			g('set origin 0,%f' % (0.7*ysize) )
			g('set size %f,%f' % (xsize,0.3*ysize))
			g('set format y "%1f"')
			g('set xrange [0:%f]' % max(time)) 
			g('set yrange [-1:1]') 
			g('set noytics')
			g('set y2tics -1,1')
			g.xlabel('time (s)',offset=(0,0.7))
			g.ylabel('amplitude')
			g.plot(*wplot)

		# default settings for next plots
		g('unset title')
		g('set format x ""')
		g('set format y "%3e"')
		g('set tmargin 0')
		g.xlabel('')

		N = len(oplots)
		y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
		delta = 0.035 # the constant part of y taken by last plot label and data
		for i in range(N):
			# plot onset detection functions
			g('set size %f,%f' % ( xsize, (y-delta)/N))
			g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
			g('set nokey')
			g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
			g('set yrange [0:%f]' % (1.1*oplots[i][2]))
			g('set y2tics ("0" 0, "%d" %d)' % (round(oplots[i][2]),round(oplots[i][2])))
			g.ylabel(oplots[i][1])
			if i == N-1:
				g('set size %f,%f' % ( xsize, (y-delta)/N + delta ) )
				g('set origin 0,0')
				g.xlabel('time (s)', offset=(0,0.7))
				g('set format x')
			g.plot(*oplots[i][0])

		g('unset multiplot')
Пример #8
0
	def plotplot(self,wplot,oplots,titles,outplot=None,extension=None,xsize=1.,ysize=1.,multiplot = 1, midi = 1, truth = 1):
		from aubio.gnuplot import gnuplot_create , audio_to_array, make_audio_plot
		import re
		import Gnuplot

		# check if ground truth exists
		if truth:
			timet,pitcht = self.gettruth()
			if timet and pitcht:
				oplots = [Gnuplot.Data(timet,pitcht,with='lines',
					title='ground truth')] + oplots

		g = gnuplot_create(outplot=outplot, extension=extension)
		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
		g('set size %f,%f' % (xsize,ysize) )
		g('set multiplot')
		# hack to align left axis
		g('set lmargin 4')
		g('set rmargin 4')
    # plot waveform
		time,data = audio_to_array(self.input)
		wplot = [make_audio_plot(time,data)]
		g('set origin 0,%f' % (0.7*ysize) )
		g('set size %f,%f' % (xsize,0.3*ysize))
		#g('set format y "%1f"')
		g('set xrange [0:%f]' % max(time)) 
		g('set yrange [-1:1]') 
		g('set noytics')
		g('set y2tics -1,1')
		g.xlabel('time (s)',offset=(0,0.7))
		g.ylabel('amplitude')
		g.plot(*wplot)

		# default settings for next plots
		g('unset title')
		g('set format x ""')
		g('set format y "%3e"')
		g('set tmargin 0')
		g.xlabel('')
		g('set noclip one') 

		if not midi:
			g('set log y')
			#g.xlabel('time (s)')
			g.ylabel('f0 (Hz)')
			g('set yrange [100:%f]' % self.params.pitchmax) 
		else: 
			g.ylabel('midi')
			g('set yrange [%f:%f]' % (aubio_freqtomidi(self.params.pitchmin), aubio_freqtomidi(self.params.pitchmax)))
			g('set y2tics %f,%f' % (round(aubio_freqtomidi(self.params.pitchmin)+.5),12))
		
		if multiplot:
			N = len(oplots)
			y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
			delta = 0.035 # the constant part of y taken by last plot label and data
			for i in range(N):
				# plot pitch detection functions
				g('set size %f,%f' % ( xsize, (y-delta)/N))
				g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
				g('set nokey')
				g('set xrange [0:%f]' % max(time))
				g.ylabel(titles[i])
				if i == N-1:
					g('set size %f,%f' % (xsize, (y-delta)/N + delta ) )
					g('set origin 0,0')
					g.xlabel('time (s)', offset=(0,0.7))
					g('set format x')
				g.plot(oplots[i])
		else:
			g('set key right top')
			g.plot(*oplots)
		g('unset multiplot')