Beispiel #1
0
    def handle_new_data(self, floatdata):
        # the behaviour of the filters functions is sometimes
        # unexpected when they are called on empty arrays
        if floatdata.shape[1] == 0:
            return

        # for now, take the first channel only
        floatdata = floatdata[0, :]

        # compute the filters' output
        y, decs_unused = self.filters.filter(floatdata)

        # compute the widget data
        sp = [pyx_exp_smoothed_value(kernel, alpha, bankdata ** 2, old) for bankdata, kernel, alpha, old in zip(y, self.kernels, self.alphas, self.dispbuffers)]

        # store result for next computation
        self.dispbuffers = sp

        sp = array(sp)

        if self.weighting is 0:
            w = 0.
        elif self.weighting is 1:
            w = self.filters.A
        elif self.weighting is 2:
            w = self.filters.B
        else:
            w = self.filters.C

        epsilon = 1e-30
        db_spectrogram = 10 * log10(sp + epsilon) + w
        self.PlotZoneSpect.setdata(self.filters.flow, self.filters.fhigh, self.filters.f_nominal, db_spectrogram)
Beispiel #2
0
    def handle_new_data(self, floatdata):
        if floatdata.shape[0] > 1 and not self.two_channels:
            self.meter.setPortCount(2)
            self.two_channels = True
        elif floatdata.shape[0] == 1 and self.two_channels:
            self.meter.setPortCount(1)
            self.two_channels = False

        # first channel
        y1 = floatdata[0, :]

        # exponential smoothing for max
        if len(y1) > 0:
            value_max = np.abs(y1).max()
            if value_max > self.old_max * (1. - self.alpha2):
                self.old_max = value_max
            else:
                # exponential decrease
                self.old_max *= (1. - self.alpha2)

        # exponential smoothing for RMS
        value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y1 ** 2, self.old_rms)
        self.old_rms = value_rms

        self.level_rms = 10. * np.log10(value_rms + 0. * 1e-80)
        self.level_max = 20. * np.log10(self.old_max + 0. * 1e-80)

        if self.two_channels:
            # second channel
            y2 = floatdata[1, :]

            # exponential smoothing for max
            if len(y2) > 0:
                value_max = np.abs(y2).max()
                if value_max > self.old_max_2 * (1. - self.alpha2):
                    self.old_max_2 = value_max
                else:
                    # exponential decrease
                    self.old_max_2 *= (1. - self.alpha2)

            # exponential smoothing for RMS
            value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y2 ** 2, self.old_rms_2)
            self.old_rms_2 = value_rms

            self.level_rms_2 = 10. * np.log10(value_rms + 0. * 1e-80)
            self.level_max_2 = 20. * np.log10(self.old_max_2 + 0. * 1e-80)
Beispiel #3
0
	def update(self):
		if not self.isVisible():
			return

		self.i += 1		

		# get the fresh data
		floatdata = self.audiobuffer.newdata()

		if floatdata.shape[0] > 1 and self.two_channels == False:
			self.meter.setPortCount(2)
			self.two_channels = True
		elif floatdata.shape[0] == 1 and self.two_channels == True:
			self.meter.setPortCount(1)
			self.two_channels = False

		# first channel
		y1 = floatdata[0,:]
		
		# exponential smoothing for max
		if len(y1) > 0:
			value_max = abs(y1).max()
			if value_max > self.old_max*(1.-self.alpha2):
				self.old_max = value_max
			else:
				# exponential decrease
				self.old_max *= (1.-self.alpha2)
		
		# exponential smoothing for RMS
		value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y1**2, self.old_rms)
		self.old_rms = value_rms
		
		level_rms = 10.*log10(value_rms + 0.*1e-80)
		level_max = 20.*log10(self.old_max + 0.*1e-80)
  
		if self.i == LEVEL_TEXT_LABEL_STEPS:
	    		if level_rms > -150.:
	    			string_rms = "%.01f" % level_rms
	    		else:
	    			string_rms = "-Inf"
	    		if level_max > -150.:
	    			string_peak = "%.01f" % level_max
	    		else:
	    			string_peak = "-Inf"

		if not self.two_channels:
			self.meter.setValue(0, level_rms, level_max)
			if self.i == LEVEL_TEXT_LABEL_STEPS:
				self.label_rms.setText(string_rms)
				self.label_peak.setText(string_peak)
		else:
			# second channel
			y2 = floatdata[1,:]
		
			# exponential smoothing for max
			if len(y2) > 0:
				value_max = abs(y2).max()
				if value_max > self.old_max_2*(1.-self.alpha2):
					self.old_max_2 = value_max
				else:
					# exponential decrease
					self.old_max_2 *= (1.-self.alpha2)
			
			# exponential smoothing for RMS
			value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y2**2, self.old_rms_2)
			self.old_rms_2 = value_rms
			
			level_rms_2 = 10.*log10(value_rms + 0.*1e-80)
			level_max_2 = 20.*log10(self.old_max_2 + 0.*1e-80)

			#self.meter.m_iPortCount = 3
			self.meter.setValue(0, level_rms, level_max)
			self.meter.setValue(1, level_rms_2, level_max_2)

			if self.i == LEVEL_TEXT_LABEL_STEPS:
				if level_rms_2 > -150.:
					string_rms_2 = "%.01f" % level_rms_2
				else:
					string_rms_2 = "-Inf"
				if level_max > -150.:
					string_peak_2 = "%.01f" % level_max_2
				else:
					string_peak_2 = "-Inf"

				self.label_rms.setText("Ch1:\n%s\n\nCh2:\n%s" %(string_rms, string_rms_2))
				self.label_peak.setText("Ch1:\n%s\n\nCh2:\n%s" %(string_peak, string_peak_2))

		if self.i == LEVEL_TEXT_LABEL_STEPS:
			self.i = 0

		if 0:
			fft_size = time*SAMPLING_RATE #1024
			maxfreq = SAMPLING_RATE/2
			sp, freq, A, B, C = self.proc.analyzelive(floatdata, fft_size, maxfreq)
			print level_rms, 10*log10((sp**2).sum()*2.), freq.max()
Beispiel #4
0
	def handle_new_data(self, floatdata):
		#the behaviour of the filters functions is sometimes
		#unexpected when they are called on empty arrays
		if floatdata.shape[1] == 0:
			return

		# for now, take the first channel only
		floatdata = floatdata[0,:]

		#compute the filters' output
		y, decs_unused = self.filters.filter(floatdata)
		
		#push to the ring buffer
		#for bankbuffer, bankdata in zip(self.bankbuffers, y):
		#	bankbuffer.push(bankdata**2)
		
		#for bankbuffer, bankdata, dec in zip(self.bankbuffers, y, decs):
			#bankbuffer.push(bankdata**2)
			
			##an exponential smoothing filter is a simple IIR filter
			##s_i = alpha*x_i + (1-alpha)*s_{i-1}
			##we compute alpha so that the N most recent samples represent 100*w percent of the output
			#w = 0.65
			#N = time*SAMPLING_RATE/dec
			#alpha = 1. - (1.-w)**(1./(N+1))
			##filter coefficient
			#forward = [alpha]
			#feedback = [1., -(1. - alpha)]
			#filt, zf = lfilter(forward, feedback, bankdata**2, zi=bankbuffer.data(1))
			#bankbuffer.push(filt)
			#sp += [bankbuffer.data(1)[0]]
			
			#bankbuffer.push(bankdata**2)
			#sp += [self.exp_smoothed_value(time, dec, bankbuffer)]

		#compute the widget data
		#sp = [self.exp_smoothed_value(kernel, alpha, bankdata**2, old) for bankdata, kernel, alpha, old in zip(y, self.kernels, self.alphas, self.dispbuffers)]
		sp = [pyx_exp_smoothed_value(kernel, alpha, bankdata**2, old) for bankdata, kernel, alpha, old in zip(y, self.kernels, self.alphas, self.dispbuffers)] 
		#store result for next computation
		self.dispbuffers = sp

		#un-weighted moving average
		#sp = [bankbuffer.data(time*SAMPLING_RATE/dec).mean() for bankbuffer, dec in zip(self.bankbuffers, decs)]
		
		sp = array(sp)
		
		# Note: the following is largely suboptimal since the filter outputs
		# are computed several times on the same signal...
		#floatdata = self.audiobuffer.data(time*SAMPLING_RATE)
		#y, dec = self.filters.filter(floatdata)
		#sp = [(bank**2).mean() for bank in y]
		#sp = array(sp)[::-1]

		#brute force without decimation
		#y_nodec = octave_filter_bank(self.b, self.a, floatdata)
		#sp_nodec = (y_nodec**2).mean(axis=1)
		
		if self.weighting is 0:
			w = 0.
		elif self.weighting is 1:
			w = self.filters.A
		elif self.weighting is 2:
			w = self.filters.B
		else:
			w = self.filters.C
		
		epsilon = 1e-30
		db_spectrogram = 10*log10(sp + epsilon) + w
		self.PlotZoneSpect.setdata(self.filters.flow, self.filters.fhigh, self.filters.f_nominal, db_spectrogram)
Beispiel #5
0
    def update(self):
        if not self.isVisible():
            return

        #get the fresh data
        floatdata = self.audiobuffer.newdata()

        #the behaviour of the filters functions is sometimes
        #unexpected when they are called on empty arrays
        if floatdata.shape[1] == 0:
            return

        # for now, take the first channel only
        floatdata = floatdata[0, :]

        #compute the filters' output
        y, decs_unused = self.filters.filter(floatdata)

        #push to the ring buffer
        #for bankbuffer, bankdata in zip(self.bankbuffers, y):
        #	bankbuffer.push(bankdata**2)

        #for bankbuffer, bankdata, dec in zip(self.bankbuffers, y, decs):
        #bankbuffer.push(bankdata**2)

        ##an exponential smoothing filter is a simple IIR filter
        ##s_i = alpha*x_i + (1-alpha)*s_{i-1}
        ##we compute alpha so that the N most recent samples represent 100*w percent of the output
        #w = 0.65
        #N = time*SAMPLING_RATE/dec
        #alpha = 1. - (1.-w)**(1./(N+1))
        ##filter coefficient
        #forward = [alpha]
        #feedback = [1., -(1. - alpha)]
        #filt, zf = lfilter(forward, feedback, bankdata**2, zi=bankbuffer.data(1))
        #bankbuffer.push(filt)
        #sp += [bankbuffer.data(1)[0]]

        #bankbuffer.push(bankdata**2)
        #sp += [self.exp_smoothed_value(time, dec, bankbuffer)]

        #compute the widget data
        #sp = [self.exp_smoothed_value(kernel, alpha, bankdata**2, old) for bankdata, kernel, alpha, old in zip(y, self.kernels, self.alphas, self.dispbuffers)]
        sp = [
            pyx_exp_smoothed_value(kernel, alpha, bankdata**2, old)
            for bankdata, kernel, alpha, old in zip(
                y, self.kernels, self.alphas, self.dispbuffers)
        ]
        #store result for next computation
        self.dispbuffers = sp

        #un-weighted moving average
        #sp = [bankbuffer.data(time*SAMPLING_RATE/dec).mean() for bankbuffer, dec in zip(self.bankbuffers, decs)]

        sp = array(sp)

        # Note: the following is largely suboptimal since the filter outputs
        # are computed several times on the same signal...
        #floatdata = self.audiobuffer.data(time*SAMPLING_RATE)
        #y, dec = self.filters.filter(floatdata)
        #sp = [(bank**2).mean() for bank in y]
        #sp = array(sp)[::-1]

        #brute force without decimation
        #y_nodec = octave_filter_bank(self.b, self.a, floatdata)
        #sp_nodec = (y_nodec**2).mean(axis=1)

        if self.weighting is 0:
            w = 0.
        elif self.weighting is 1:
            w = self.filters.A
        elif self.weighting is 2:
            w = self.filters.B
        else:
            w = self.filters.C

        epsilon = 1e-30
        db_spectrogram = 10 * log10(sp + epsilon) + w
        self.PlotZoneSpect.setdata(self.filters.flow, self.filters.fhigh,
                                   self.filters.f_nominal, db_spectrogram)
Beispiel #6
0
    def update(self):
        if not self.isVisible():
            return

        self.i += 1

        # get the fresh data
        floatdata = self.audiobuffer.newdata()

        if floatdata.shape[0] > 1 and self.two_channels == False:
            self.meter.setPortCount(2)
            self.two_channels = True
        elif floatdata.shape[0] == 1 and self.two_channels == True:
            self.meter.setPortCount(1)
            self.two_channels = False

        # first channel
        y1 = floatdata[0, :]

        # exponential smoothing for max
        if len(y1) > 0:
            value_max = abs(y1).max()
            if value_max > self.old_max * (1. - self.alpha2):
                self.old_max = value_max
            else:
                # exponential decrease
                self.old_max *= (1. - self.alpha2)

        # exponential smoothing for RMS
        value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y1**2,
                                           self.old_rms)
        self.old_rms = value_rms

        level_rms = 10. * log10(value_rms + 0. * 1e-80)
        level_max = 20. * log10(self.old_max + 0. * 1e-80)

        if self.i == LEVEL_TEXT_LABEL_STEPS:
            if level_rms > -150.:
                string_rms = "%+05.01f" % level_rms
            else:
                string_rms = "-Inf"
            if level_max > -150.:
                string_peak = "%+05.01f" % level_max
            else:
                string_peak = "-Inf"

        if not self.two_channels:
            self.meter.setValue(0, level_rms, level_max)
            if self.i == LEVEL_TEXT_LABEL_STEPS:
                self.label_rms.setText(string_rms)
                self.label_peak.setText(string_peak)
        else:
            # second channel
            y2 = floatdata[1, :]

            # exponential smoothing for max
            if len(y2) > 0:
                value_max = abs(y2).max()
                if value_max > self.old_max_2 * (1. - self.alpha2):
                    self.old_max_2 = value_max
                else:
                    # exponential decrease
                    self.old_max_2 *= (1. - self.alpha2)

            # exponential smoothing for RMS
            value_rms = pyx_exp_smoothed_value(self.kernel, self.alpha, y2**2,
                                               self.old_rms_2)
            self.old_rms_2 = value_rms

            level_rms_2 = 10. * log10(value_rms + 0. * 1e-80)
            level_max_2 = 20. * log10(self.old_max_2 + 0. * 1e-80)

            #self.meter.m_iPortCount = 3
            self.meter.setValue(0, level_rms, level_max)
            self.meter.setValue(1, level_rms_2, level_max_2)

            if self.i == LEVEL_TEXT_LABEL_STEPS:
                if level_rms_2 > -150.:
                    string_rms_2 = "%+05.01f" % level_rms_2
                else:
                    string_rms_2 = "-Inf"
                if level_max > -150.:
                    string_peak_2 = "%+05.01f" % level_max_2
                else:
                    string_peak_2 = "-Inf"

                self.label_rms.setText("1: %s\n2: %s" %
                                       (string_rms, string_rms_2))
                self.label_peak.setText("1: %s\n2: %s" %
                                        (string_peak, string_peak_2))

        if self.i == LEVEL_TEXT_LABEL_STEPS:
            self.i = 0

        if 0:
            fft_size = time * SAMPLING_RATE  #1024
            maxfreq = SAMPLING_RATE / 2
            sp, freq, A, B, C = self.proc.analyzelive(floatdata, fft_size,
                                                      maxfreq)
            print(level_rms, 10 * log10((sp**2).sum() * 2.), freq.max())