def __init__(self, parent=None): super().__init__(parent) self.setObjectName("Levels_Widget") self.gridLayout = QtWidgets.QGridLayout(self) self.gridLayout.setObjectName("gridLayout") font = QtGui.QFont() font.setPointSize(14) font.setWeight(75) font.setBold(True) self.label_peak = QtWidgets.QLabel(self) self.label_peak.setFont(font) # QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft self.label_peak.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight) self.label_peak.setObjectName("label_peak") self.label_peak_legend = QtWidgets.QLabel(self) self.label_peak_legend.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignRight) self.label_peak_legend.setObjectName("label_peak_legend") self.label_rms = QtWidgets.QLabel(self) self.label_rms.setFont(font) self.label_rms.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight) self.label_rms.setObjectName("label_rms") self.label_rms_legend = QtWidgets.QLabel(self) self.label_rms_legend.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignRight) self.label_rms_legend.setObjectName("label_rms_legend") self.meter = qsynthMeter(self) self.meter.setStyleSheet(STYLESHEET) self.meter.setObjectName("meter") self.gridLayout.addWidget(self.label_peak, 0, 0, 1, 1) self.gridLayout.addWidget(self.label_peak_legend, 1, 0, 1, 1) self.gridLayout.addWidget(self.label_rms, 2, 0, 1, 1) self.gridLayout.addWidget(self.label_rms_legend, 3, 0, 1, 1) self.gridLayout.addWidget(self.meter, 4, 0, 1, 1) self.label_rms.setText("+00.0") self.label_peak.setText("+00.0") self.label_rms_legend.setText("dB FS\n RMS") self.label_peak_legend.setText("dB FS\n Peak") self.label_rms.setTextFormat(QtCore.Qt.PlainText) self.label_peak.setTextFormat(QtCore.Qt.PlainText) # self.label_rms.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)) # self.label_rms_legend.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)) # self.label_peak.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)) # self.label_peak_legend.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)) self.audiobuffer = None # initialize the settings dialog self.settings_dialog = Levels_Settings_Dialog(self) # initialize the class instance that will do the fft self.proc = audioproc() # time = SMOOTH_DISPLAY_TIMER_PERIOD_MS/1000. #DISPLAY # time = 0.025 #IMPULSE setting for a sound level meter # time = 0.125 #FAST setting for a sound level meter # time = 1. #SLOW setting for a sound level meter self.response_time = 0.300 # 300ms is a common value for VU meters # 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 = self.response_time * SAMPLING_RATE N = 5 * n self.alpha = 1. - (1. - w)**(1. / (n + 1)) self.kernel = (1. - self.alpha)**(np.arange(0, N)[::-1]) # first channel self.level_rms = -30. self.level_max = -30. self.old_rms = 1e-30 self.old_max = 1e-30 # second channel self.level_rms_2 = -30. self.level_max_2 = -30. self.old_rms_2 = 1e-30 self.old_max_2 = 1e-30 response_time_peaks = 0.025 # 25ms for instantaneous peaks n2 = response_time_peaks / (SMOOTH_DISPLAY_TIMER_PERIOD_MS / 1000.) self.alpha2 = 1. - (1. - w)**(1. / (n2 + 1)) self.two_channels = False self.i = 0
def __init__(self, parent=None, logger=None): QtGui.QWidget.__init__(self, parent) self.setObjectName("Levels_Widget") self.gridLayout = QtGui.QGridLayout(self) self.gridLayout.setObjectName("gridLayout") self.label_rms = QtGui.QLabel(self) font = QtGui.QFont() font.setPointSize(14) font.setWeight(75) font.setBold(True) self.label_rms.setFont(font) self.label_rms.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing) self.label_rms.setObjectName("label_rms") self.gridLayout.addWidget(self.label_rms, 0, 0, 1, 1) self.meter = qsynthMeter(self) self.meter.setStyleSheet(STYLESHEET) self.meter.setObjectName("meter") self.gridLayout.addWidget(self.meter, 0, 1, 2, 1) self.label_peak = QtGui.QLabel(self) self.label_peak.setFont(font) self.label_peak.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft) self.label_peak.setObjectName("label_peak") self.gridLayout.addWidget(self.label_peak, 0, 2, 1, 1) self.label_rms_legend = QtGui.QLabel(self) self.label_rms_legend.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTop | QtCore.Qt.AlignTrailing) self.label_rms_legend.setObjectName("label_rms_legend") self.gridLayout.addWidget(self.label_rms_legend, 1, 0, 1, 1) self.label_peak_legend = QtGui.QLabel(self) self.label_peak_legend.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) self.label_peak_legend.setObjectName("label_peak_legend") self.gridLayout.addWidget(self.label_peak_legend, 1, 2, 1, 1) self.label_rms.setText("-100.0") self.label_peak.setText("-100.0") self.label_rms_legend.setText("dBFS\n RMS") self.label_peak_legend.setText("dBFS\n peak") #self.label_rms.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) #self.label_rms_legend.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) #self.label_peak.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) #self.label_peak_legend.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) # store the logger instance if logger is None: self.logger = parent.parent.logger else: self.logger = logger self.audiobuffer = None # initialize the settings dialog self.settings_dialog = Levels_Settings_Dialog(self, self.logger) # initialize the class instance that will do the fft self.proc = audioproc(self.logger) #time = SMOOTH_DISPLAY_TIMER_PERIOD_MS/1000. #DISPLAY #time = 0.025 #IMPULSE setting for a sound level meter #time = 0.125 #FAST setting for a sound level meter #time = 1. #SLOW setting for a sound level meter self.response_time = 0.125 # 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 = self.response_time * SAMPLING_RATE N = 4096 self.alpha = 1. - (1. - w)**(1. / (n + 1)) self.kernel = (1. - self.alpha)**(arange(0, N)[::-1]) # first channel self.old_rms = 1e-30 self.old_max = 1e-30 # second channel self.old_rms_2 = 1e-30 self.old_max_2 = 1e-30 n2 = self.response_time / (SMOOTH_DISPLAY_TIMER_PERIOD_MS / 1000.) self.alpha2 = 1. - (1. - w)**(1. / (n2 + 1)) self.two_channels = False