Esempio n. 1
0
    def __init__(self, parent, logger=PrintLogger()):
        super().__init__(parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Spectrum_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneSpect = HistPlot(self, self.logger)
        self.PlotZoneSpect.setObjectName("PlotZoneSpect")
        self.gridLayout.addWidget(self.PlotZoneSpect, 0, 0, 1, 1)

        self.spec_min = DEFAULT_SPEC_MIN
        self.spec_max = DEFAULT_SPEC_MAX
        self.weighting = DEFAULT_WEIGHTING
        self.response_time = DEFAULT_RESPONSE_TIME

        self.PlotZoneSpect.setspecrange(self.spec_min, self.spec_max)
        self.PlotZoneSpect.setweighting(self.weighting)

        self.filters = octave_filters(DEFAULT_BANDSPEROCTAVE)
        self.dispbuffers = [0] * DEFAULT_BANDSPEROCTAVE * NOCTAVE

        # set kernel and parameters for the smoothing filter
        self.setresponsetime(self.response_time)

        # initialize the settings dialog
        self.settings_dialog = OctaveSpectrum_Settings_Dialog(self, self.logger)
Esempio n. 2
0
    def __init__(self, parent=None, logger=PrintLogger()):
        super().__init__(parent)
        self.setObjectName("LongLevels_Widget")

        self.logger = logger

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneUp = TimePlot(self, self.logger)
        self.PlotZoneUp.setObjectName("PlotZoneUp")
        self.PlotZoneUp.setverticaltitle("Level (dB FS RMS)")
        self.PlotZoneUp.sethorizontaltitle("Time (min)")
        self.PlotZoneUp.setTrackerFormatter(lambda x, y: "%.3g min, %.3g" % (x, y))

        self.level_min = DEFAULT_LEVEL_MIN
        self.level_max = DEFAULT_LEVEL_MAX
        self.PlotZoneUp.setverticalrange(self.level_min, self.level_max)

        self.gridLayout.addWidget(self.PlotZoneUp, 0, 0, 1, 1)

        self.logger = logger
        self.audiobuffer = None

        # initialize the settings dialog
        self.settings_dialog = LongLevels_Settings_Dialog(self, self.logger)

        # initialize the class instance that will do the fft
        self.proc = audioproc(self.logger)

        self.level = None # 1e-30
        self.level_rms = -200.

        self.two_channels = False

        self.i = 0

        self.old_index = 0

        #self.response_time = 60. # 1 minute
        self.response_time = 20.

        # how many times we should decimate to end up with 100 points in the kernel
        self.Ndec = int(max(0, np.floor((np.log2(self.response_time * SAMPLING_RATE/100.)))))

        Ngauss = 4
        self.b = np.array(gauss(10*Ngauss+1, 2.*Ngauss))
        self.a = np.zeros(self.b.shape)
        self.a[0] = 1.
        self.zf = np.zeros(max(len(self.b), len(self.a)) - 1)

        self.subsampled_sampling_rate = SAMPLING_RATE / 2 ** (self.Ndec)
        self.subsampler = Subsampler(self.Ndec)

        self.length_seconds = 60.*10
        # actually this should be linked to the pixel width of the plot area
        self.length_samples = self.length_seconds * self.subsampled_sampling_rate

        # ringbuffer for the subsampled data
        self.ringbuffer = RingBuffer(self.logger)
Esempio n. 3
0
    def __init__(self, parent, audiobackend, logger=PrintLogger()):
        super().__init__(parent)

        self.logger = logger

        self.setObjectName("Spectrogram_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneImage = ImagePlot(self, self.logger, audiobackend)
        self.PlotZoneImage.setObjectName("PlotZoneImage")
        self.gridLayout.addWidget(self.PlotZoneImage, 0, 1, 1, 1)

        self.audiobuffer = None
        self.audiobackend = audiobackend

        # initialize the class instance that will do the fft
        self.proc = audioproc(self.logger)

        self.maxfreq = DEFAULT_MAXFREQ
        self.proc.set_maxfreq(self.maxfreq)
        self.minfreq = DEFAULT_MINFREQ
        self.fft_size = 2 ** DEFAULT_FFT_SIZE * 32
        self.proc.set_fftsize(self.fft_size)
        self.spec_min = DEFAULT_SPEC_MIN
        self.spec_max = DEFAULT_SPEC_MAX
        self.weighting = DEFAULT_WEIGHTING

        self.update_weighting()
        self.freq = self.proc.get_freq_scale()

        self.timerange_s = DEFAULT_TIMERANGE
        self.canvas_width = 100.

        self.old_index = 0
        self.overlap = 3. / 4.
        self.overlap_frac = Fraction(3, 4)
        self.dT_s = self.fft_size * (1. - self.overlap) / float(SAMPLING_RATE)

        self.PlotZoneImage.setlog10freqscale()  # DEFAULT_FREQ_SCALE = 1 #log10
        self.PlotZoneImage.setfreqrange(self.minfreq, self.maxfreq)
        self.PlotZoneImage.setspecrange(self.spec_min, self.spec_max)
        self.PlotZoneImage.setweighting(self.weighting)
        self.PlotZoneImage.settimerange(self.timerange_s, self.dT_s)
        self.update_jitter()

        sfft_rate_frac = Fraction(SAMPLING_RATE, self.fft_size) / (Fraction(1) - self.overlap_frac) / 1000
        self.PlotZoneImage.set_sfft_rate(sfft_rate_frac)

        # initialize the settings dialog
        self.settings_dialog = Spectrogram_Settings_Dialog(self, self.logger)

        self.audiobackend.underflow.connect(self.PlotZoneImage.plotImage.canvasscaledspectrogram.syncOffsets)

        self.last_data_time = 0.

        self.mustRestart = False
Esempio n. 4
0
    def __init__(self, parent, sharedGLWidget, logger=PrintLogger()):
        super().__init__(parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Spectrum_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneSpect = SpectrumPlotWidget(self, sharedGLWidget,
                                                self.logger)
        self.PlotZoneSpect.setObjectName("PlotZoneSpect")
        self.gridLayout.addWidget(self.PlotZoneSpect, 0, 0, 1, 1)

        # initialize the class instance that will do the fft
        self.proc = audioproc(self.logger)

        self.maxfreq = DEFAULT_MAXFREQ
        self.proc.set_maxfreq(self.maxfreq)
        self.minfreq = DEFAULT_MINFREQ
        self.fft_size = 2**DEFAULT_FFT_SIZE * 32
        self.proc.set_fftsize(self.fft_size)
        self.spec_min = DEFAULT_SPEC_MIN
        self.spec_max = DEFAULT_SPEC_MAX
        self.weighting = DEFAULT_WEIGHTING
        self.dual_channels = False
        self.response_time = DEFAULT_RESPONSE_TIME

        self.update_weighting()
        self.freq = self.proc.get_freq_scale()

        self.old_index = 0
        self.overlap = 3. / 4.

        self.update_display_buffers()

        # set kernel and parameters for the smoothing filter
        self.setresponsetime(self.response_time)

        self.PlotZoneSpect.setlogfreqscale()  #DEFAULT_FREQ_SCALE = 1 #log10
        self.PlotZoneSpect.setfreqrange(self.minfreq, self.maxfreq)
        self.PlotZoneSpect.setspecrange(self.spec_min, self.spec_max)
        self.PlotZoneSpect.setweighting(self.weighting)
        self.PlotZoneSpect.set_peaks_enabled(True)
        self.PlotZoneSpect.set_baseline_displayUnits(0.)
        self.PlotZoneSpect.setShowFreqLabel(DEFAULT_SHOW_FREQ_LABELS)

        # initialize the settings dialog
        self.settings_dialog = Spectrum_Settings_Dialog(self, self.logger)
Esempio n. 5
0
    def __init__(self, parent, sharedGLWidget, logger=PrintLogger()):
        super().__init__(parent)

        self.audiobuffer = None
        self.logger = logger

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneUp = TimePlot(self, sharedGLWidget, self.logger)
        self.PlotZoneUp.setObjectName("PlotZoneUp")
        self.gridLayout.addWidget(self.PlotZoneUp, 0, 0, 1, 1)

        self.settings_dialog = Scope_Settings_Dialog(self, self.logger)

        self.timerange = DEFAULT_TIMERANGE
Esempio n. 6
0
    def __init__(self, parent=None, logger=PrintLogger()):
        QtGui.QWidget.__init__(self, parent)

        self.audiobuffer = None
        self.logger = logger

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneUp = TimePlot(self, self.logger)
        self.PlotZoneUp.setObjectName("PlotZoneUp")
        self.gridLayout.addWidget(self.PlotZoneUp, 0, 0, 1, 1)

        self.setStyleSheet(STYLESHEET)

        self.settings_dialog = Scope_Settings_Dialog(self, self.logger)

        self.timerange = DEFAULT_TIMERANGE
Esempio n. 7
0
    def __init__(self, parent, logger=PrintLogger()):
        QtGui.QWidget.__init__(self, parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Spectrum_Widget")
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneSpect = HistPlot(self, self.logger)
        self.PlotZoneSpect.setObjectName("PlotZoneSpect")
        self.gridLayout.addWidget(self.PlotZoneSpect, 0, 0, 1, 1)

        self.setStyleSheet(STYLESHEET)

        self.spec_min = DEFAULT_SPEC_MIN
        self.spec_max = DEFAULT_SPEC_MAX
        self.weighting = DEFAULT_WEIGHTING
        self.response_time = DEFAULT_RESPONSE_TIME

        self.PlotZoneSpect.setspecrange(self.spec_min, self.spec_max)
        self.PlotZoneSpect.setweighting(self.weighting)

        self.filters = octave_filters(DEFAULT_BANDSPEROCTAVE)
        #self.bankbuffers = [RingBuffer() for band in range(0, DEFAULT_BANDSPEROCTAVE*NOCTAVE)]
        self.dispbuffers = [0] * DEFAULT_BANDSPEROCTAVE * NOCTAVE

        # 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
        decs = self.filters.get_decs()
        ns = [self.response_time * SAMPLING_RATE / dec for dec in decs]
        Ns = [2 * 4096 / dec for dec in decs]
        self.alphas = [1. - (1. - w)**(1. / (n + 1)) for n in ns]
        #print ns, Ns
        self.kernels = self.compute_kernels(self.alphas, Ns)

        # initialize the settings dialog
        self.settings_dialog = OctaveSpectrum_Settings_Dialog(
            self, self.logger)
Esempio n. 8
0
    def __init__(self, parent, logger=PrintLogger()):
        QtGui.QWidget.__init__(self, parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Spectrum_Widget")
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        #self.PlotZoneSpect = SpectPlot(self, self.logger)
        self.PlotZoneSpect = GLPlotWidget(self, self.logger)
        self.PlotZoneSpect.setObjectName("PlotZoneSpect")
        self.gridLayout.addWidget(self.PlotZoneSpect, 0, 0, 1, 1)

        self.setStyleSheet(STYLESHEET)

        # initialize the class instance that will do the fft
        self.proc = audioproc(self.logger)

        self.maxfreq = DEFAULT_MAXFREQ
        self.proc.set_maxfreq(self.maxfreq)
        self.minfreq = DEFAULT_MINFREQ
        self.fft_size = 2**DEFAULT_FFT_SIZE * 32
        self.proc.set_fftsize(self.fft_size)
        self.spec_min = DEFAULT_SPEC_MIN
        self.spec_max = DEFAULT_SPEC_MAX
        self.weighting = DEFAULT_WEIGHTING
        self.dual_channels = False

        self.PlotZoneSpect.setlogfreqscale()  #DEFAULT_FREQ_SCALE = 1 #log10
        self.PlotZoneSpect.setfreqrange(self.minfreq, self.maxfreq)
        self.PlotZoneSpect.setspecrange(self.spec_min, self.spec_max)
        self.PlotZoneSpect.setweighting(self.weighting)
        self.PlotZoneSpect.set_peaks_enabled(True)
        self.PlotZoneSpect.set_baseline_displayUnits(0.)
        self.PlotZoneSpect.setShowFreqLabel(DEFAULT_SHOW_FREQ_LABELS)

        # initialize the settings dialog
        self.settings_dialog = Spectrum_Settings_Dialog(self, self.logger)
Esempio n. 9
0
    def __init__(self, parent=None, logger=PrintLogger()):
        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, 0, 1, 4, 1)

        self.label_rms.setText("-100.0")
        self.label_peak.setText("-100.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.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.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
Esempio n. 10
0
    def __init__(self, parent, audiobackend, logger=PrintLogger()):
        QtGui.QWidget.__init__(self, parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Generator_Widget")
        self.gridLayout = QtGui.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")

        self.comboBox_generator_kind = QtGui.QComboBox(self)
        self.comboBox_generator_kind.setObjectName("comboBox_generator_kind")
        self.comboBox_generator_kind.addItem("Sine")
        self.comboBox_generator_kind.addItem("White noise")
        self.comboBox_generator_kind.addItem("Pink noise")
        self.comboBox_generator_kind.addItem("Sweep")
        self.comboBox_generator_kind.addItem("Burst")
        self.comboBox_generator_kind.setCurrentIndex(
            DEFAULT_GENERATOR_KIND_INDEX)

        sinePageWidget = QtGui.QWidget(self)
        whitePageWidget = QtGui.QWidget(self)
        pinkPageWidget = QtGui.QWidget(self)
        sweepPageWidget = QtGui.QWidget(self)
        burstPageWidget = QtGui.QWidget(self)

        self.stackedLayout = QtGui.QStackedLayout()
        self.stackedLayout.addWidget(sinePageWidget)
        self.stackedLayout.addWidget(whitePageWidget)
        self.stackedLayout.addWidget(pinkPageWidget)
        self.stackedLayout.addWidget(sweepPageWidget)
        self.stackedLayout.addWidget(burstPageWidget)

        self.spinBox_sine_frequency = QtGui.QSpinBox(sinePageWidget)
        self.spinBox_sine_frequency.setKeyboardTracking(False)
        self.spinBox_sine_frequency.setMinimum(20)
        self.spinBox_sine_frequency.setMaximum(22000)
        self.spinBox_sine_frequency.setProperty("value",
                                                DEFAULT_SINE_FREQUENCY)
        self.spinBox_sine_frequency.setObjectName("spinBox_sine_frequency")
        self.spinBox_sine_frequency.setSuffix(" Hz")

        self.sineLayout = QtGui.QFormLayout(sinePageWidget)
        self.sineLayout.addRow("Frequency:", self.spinBox_sine_frequency)

        self.spinBox_sweep_startfrequency = QtGui.QSpinBox(sweepPageWidget)
        self.spinBox_sweep_startfrequency.setKeyboardTracking(False)
        self.spinBox_sweep_startfrequency.setMinimum(20)
        self.spinBox_sweep_startfrequency.setMaximum(22000)
        self.spinBox_sweep_startfrequency.setProperty(
            "value", DEFAULT_SWEEP_STARTFREQUENCY)
        self.spinBox_sweep_startfrequency.setObjectName(
            "spinBox_sweep_startfrequency")
        self.spinBox_sweep_startfrequency.setSuffix(" Hz")

        self.spinBox_sweep_stopfrequency = QtGui.QSpinBox(sweepPageWidget)
        self.spinBox_sweep_stopfrequency.setKeyboardTracking(False)
        self.spinBox_sweep_stopfrequency.setMinimum(20)
        self.spinBox_sweep_stopfrequency.setMaximum(22000)
        self.spinBox_sweep_stopfrequency.setProperty(
            "value", DEFAULT_SWEEP_STOPFREQUENCY)
        self.spinBox_sweep_stopfrequency.setObjectName(
            "spinBox_sweep_stopfrequency")
        self.spinBox_sweep_stopfrequency.setSuffix(" Hz")

        self.spinBox_sweep_period = QtGui.QDoubleSpinBox(sweepPageWidget)
        self.spinBox_sweep_period.setKeyboardTracking(False)
        self.spinBox_sweep_period.setDecimals(2)
        self.spinBox_sweep_period.setSingleStep(1)
        self.spinBox_sweep_period.setMinimum(0.01)
        self.spinBox_sweep_period.setMaximum(60)
        self.spinBox_sweep_period.setProperty("value", DEFAULT_SWEEP_PERIOD_S)
        self.spinBox_sweep_period.setObjectName("spinBox_sweep_period")
        self.spinBox_sweep_period.setSuffix(" s")

        self.sweepLayout = QtGui.QFormLayout(sweepPageWidget)
        self.sweepLayout.addRow("Start frequency:",
                                self.spinBox_sweep_startfrequency)
        self.sweepLayout.addRow("Stop frequency:",
                                self.spinBox_sweep_stopfrequency)
        self.sweepLayout.addRow("Period:", self.spinBox_sweep_period)

        self.spinBox_burst_period = QtGui.QDoubleSpinBox(burstPageWidget)
        self.spinBox_burst_period.setKeyboardTracking(False)
        self.spinBox_burst_period.setDecimals(2)
        self.spinBox_burst_period.setSingleStep(1)
        self.spinBox_burst_period.setMinimum(0.01)
        self.spinBox_burst_period.setMaximum(60)
        self.spinBox_burst_period.setProperty("value", DEFAULT_BURST_PERIOD_S)
        self.spinBox_burst_period.setObjectName("spinBox_burst_period")
        self.spinBox_burst_period.setSuffix(" s")

        self.burstLayout = QtGui.QFormLayout(burstPageWidget)
        self.burstLayout.addRow("Period:", self.spinBox_burst_period)

        self.t = 0.
        self.t_start = 0.
        self.t_stop = RAMP_LENGTH
        self.state = stopped

        self.audiobackend = audiobackend

        self.p = pyaudio.PyAudio()

        self.device = None
        self.stream = None

        # we will try to open all the input devices until one
        # works, starting by the default input device
        for device in self.audiobackend.output_devices:
            self.logger.push("Opening the stream")
            self.stream = self.open_output_stream(device)
            self.device = device

            self.logger.push("Trying to write to output device %d" % device)
            if self.test_output_stream(self.stream):
                self.logger.push("Success")
                break
            else:
                self.logger.push("Fail")

        #stream.close()
        #self.p.terminate()

        self.startStopButton = QtGui.QPushButton(self)

        startStopIcon = QtGui.QIcon()
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/start.svg"),
                                QtGui.QIcon.Normal, QtGui.QIcon.Off)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"),
                                QtGui.QIcon.Normal, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"),
                                QtGui.QIcon.Active, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"),
                                QtGui.QIcon.Selected, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"),
                                QtGui.QIcon.Disabled, QtGui.QIcon.On)
        self.startStopButton.setIcon(startStopIcon)

        self.startStopButton.setObjectName("generatorStartStop")
        self.startStopButton.setText("Start")
        self.startStopButton.setToolTip("Start/Stop generator")
        self.startStopButton.setCheckable(True)
        self.startStopButton.setChecked(False)

        self.gridLayout.addWidget(self.startStopButton, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.comboBox_generator_kind, 1, 0, 1, 1)
        self.gridLayout.addLayout(self.stackedLayout, 2, 0, 1, 1)

        self.connect(self.comboBox_generator_kind,
                     QtCore.SIGNAL('activated(int)'),
                     self.stackedLayout.setCurrentIndex)
        self.connect(self.startStopButton, QtCore.SIGNAL('toggled(bool)'),
                     self.startStopButton_toggle)

        #self.setStyleSheet(STYLESHEET)

        #self.response_time = DEFAULT_RESPONSE_TIME

        # initialize the settings dialog
        self.settings_dialog = Generator_Settings_Dialog(self, self.logger)

        devices = self.audiobackend.get_readable_output_devices_list()
        for device in devices:
            self.settings_dialog.comboBox_outputDevice.addItem(device)

        if self.device <> None:
            self.settings_dialog.comboBox_outputDevice.setCurrentIndex(
                self.audiobackend.output_devices.index(self.device))

        self.connect(self.settings_dialog.comboBox_outputDevice,
                     QtCore.SIGNAL('currentIndexChanged(int)'),
                     self.device_changed)

        self.sweepGenerator = SweepGenerator()
        self.connect(self.spinBox_sweep_startfrequency,
                     QtCore.SIGNAL('valueChanged(int)'),
                     self.sweepGenerator.setf1)
        self.connect(self.spinBox_sweep_stopfrequency,
                     QtCore.SIGNAL('valueChanged(int)'),
                     self.sweepGenerator.setf2)
        self.connect(self.spinBox_sweep_period,
                     QtCore.SIGNAL('valueChanged(double)'),
                     self.sweepGenerator.setT)
Esempio n. 11
0
    def __init__(self, parent=None, logger=PrintLogger()):
        super().__init__(parent)

        self.audiobuffer = None
        self.logger = logger

        self.previous_delay_message = ""
        self.previous_correlation_message = ""
        self.previous_polarity_message = ""
        self.previous_channel_info_message = ""

        self.setObjectName("Delay_Estimator_Widget")
        self.layout = QtWidgets.QFormLayout(self)
        self.layout.setObjectName("layout")

        font = QtGui.QFont()
        font.setPointSize(14)
        font.setWeight(75)
        font.setBold(True)

        self.delay_label = QtWidgets.QLabel(self)
        self.delay_label.setFont(font)
        self.delay_label.setObjectName("delay_label")

        self.delay_text_label = QtWidgets.QLabel(self)
        self.delay_text_label.setObjectName("delay_text_label")
        self.delay_text_label.setText("Delay:")

        self.correlation_label = QtWidgets.QLabel(self)
        self.correlation_label.setObjectName("Correlation_label")

        self.correlation_text_label = QtWidgets.QLabel(self)
        self.correlation_text_label.setObjectName("correlation_text_label")
        self.correlation_text_label.setText("Confidence:")

        self.polarity_label = QtWidgets.QLabel(self)
        self.polarity_label.setFont(font)
        self.polarity_label.setObjectName("polarity_label")

        self.polarity_text_label = QtWidgets.QLabel(self)
        self.polarity_text_label.setObjectName("polarity_text_label")
        self.polarity_text_label.setText("Polarity:")

        self.channel_info_label = QtWidgets.QLabel(self)
        self.channel_info_label.setObjectName("channel_info_label")

        self.layout.addRow(self.delay_text_label, self.delay_label)
        self.layout.addRow(self.correlation_text_label, self.correlation_label)
        self.layout.addRow(self.polarity_text_label, self.polarity_label)
        self.layout.addRow(None, self.channel_info_label)

        self.settings_dialog = Delay_Estimator_Settings_Dialog(
            self, self.logger)

        # We will decimate several times
        # no decimation => 1/fs = 23 µs resolution
        # 1 ms resolution => fs = 1000 Hz is enough => can divide the sampling rate by 44 !
        # if I decimate 2 times (2**2 = 4 => 0.092 ms (3 cm) resolution)!
        # if I decimate 3 times (2**3 = 8 => 0.184 ms (6 cm) resolution)!
        # if I decimate 4 times (2**4 = 16 => 0.368 ms (12 cm) resolution)!
        # if I decimate 5 times (2**5 = 32 => 0.7 ms (24 cm) resolution)!
        # (actually, I could fit a gaussian on the cross-correlation peak to get
        # higher resolution even at low sample rates)
        self.Ndec = 2
        self.subsampled_sampling_rate = SAMPLING_RATE / 2**(self.Ndec)
        [self.bdec, self.adec] = generated_filters.PARAMS['dec']
        self.bdec = numpy.array(self.bdec)
        self.adec = numpy.array(self.adec)
        self.zfs0 = subsampler_filtic(self.Ndec, self.bdec, self.adec)
        self.zfs1 = subsampler_filtic(self.Ndec, self.bdec, self.adec)

        # ringbuffers for the subsampled data
        self.ringbuffer0 = RingBuffer(self.logger)
        self.ringbuffer1 = RingBuffer(self.logger)

        self.delayrange_s = DEFAULT_DELAYRANGE  # confidence range

        self.old_Xcorr = None

        self.old_index = 0

        self.two_channels = False
        self.delay_ms = 0.
        self.distance_m = 0.
        self.correlation = 0.
        self.Xcorr_extremum = 0.
Esempio n. 12
0
    def __init__(self, parent, audiobackend, logger=PrintLogger()):
        super().__init__(parent)

        self.logger = logger
        self.audiobuffer = None

        self.setObjectName("Generator_Widget")
        self.grid_layout = QtWidgets.QGridLayout(self)
        self.grid_layout.setObjectName("grid_layout")

        self.generators = []
        self.generators.append(SineGenerator(self, logger))
        self.generators.append(WhiteGenerator(self, logger))
        self.generators.append(PinkGenerator(self, logger))
        self.generators.append(SweepGenerator(self, logger))
        self.generators.append(BurstGenerator(self, logger))

        self.combobox_generator_kind = QtWidgets.QComboBox(self)
        self.combobox_generator_kind.setObjectName("combobox_generator_kind")

        self.stacked_settings_layout = QtWidgets.QStackedLayout()

        for generator in self.generators:
            self.combobox_generator_kind.addItem(generator.name)
            self.stacked_settings_layout.addWidget(generator.settingsWidget())

        self.combobox_generator_kind.setCurrentIndex(DEFAULT_GENERATOR_KIND_INDEX)

        self.t = 0.
        self.t_start = 0.
        self.t_stop = RAMP_LENGTH
        self.state = STOPPED

        self.audiobackend = audiobackend

        self.stream_stop_ramp_finished.connect(self.stop_stream_after_ramp)

        self.device = None
        self.stream = None

        # we will try to open all the output devices until one
        # works, starting by the default input device
        for device in self.audiobackend.output_devices:
            self.logger.push("Opening the stream")
            try:
                self.stream = self.audiobackend.open_output_stream(device, self.audio_callback)
                self.stream.start_stream()
                self.stream.stop_stream()
                self.device = device
                self.logger.push("Success")
                break
            except:
                self.logger.push("Fail")

        self.start_stop_button = QtWidgets.QPushButton(self)

        startStopIcon = QtGui.QIcon()
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/start.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"), QtGui.QIcon.Active, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"), QtGui.QIcon.Selected, QtGui.QIcon.On)
        startStopIcon.addPixmap(QtGui.QPixmap(":/images-src/stop.svg"), QtGui.QIcon.Disabled, QtGui.QIcon.On)
        self.start_stop_button.setIcon(startStopIcon)

        self.start_stop_button.setObjectName("generatorStartStop")
        self.start_stop_button.setText("Start")
        self.start_stop_button.setToolTip("Start/Stop generator")
        self.start_stop_button.setCheckable(True)
        self.start_stop_button.setChecked(False)

        self.grid_layout.addWidget(self.start_stop_button, 0, 0, 1, 1)
        self.grid_layout.addWidget(self.combobox_generator_kind, 1, 0, 1, 1)
        self.grid_layout.addLayout(self.stacked_settings_layout, 2, 0, 1, 1)

        self.combobox_generator_kind.activated.connect(self.stacked_settings_layout.setCurrentIndex)
        self.start_stop_button.toggled.connect(self.start_stop_button_toggle)

        # initialize the settings dialog
        devices = self.audiobackend.get_readable_output_devices_list()
        if self.device is not None:
            device_index = self.audiobackend.output_devices.index(self.device)
        else:
            device_index = None
        self.settings_dialog = Generator_Settings_Dialog(self, self.logger, devices, device_index)

        self.settings_dialog.combobox_output_device.currentIndexChanged.connect(self.device_changed)
Esempio n. 13
0
    def __init__(self, parent=None, logger=PrintLogger()):
        super().__init__(parent)
        self.setObjectName("LongLevels_Widget")

        self.logger = logger

        self.setObjectName("Scope_Widget")
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.PlotZoneUp = TimePlot(self, self.logger)
        self.PlotZoneUp.setObjectName("PlotZoneUp")
        self.PlotZoneUp.setverticaltitle("Level (dB FS RMS)")
        self.PlotZoneUp.sethorizontaltitle("Time (min)")
        self.PlotZoneUp.setTrackerFormatter(lambda x, y: "%.3g min, %.3g" %
                                            (x, y))

        self.level_min = DEFAULT_LEVEL_MIN
        self.level_max = DEFAULT_LEVEL_MAX
        self.PlotZoneUp.setverticalrange(self.level_min, self.level_max)

        self.gridLayout.addWidget(self.PlotZoneUp, 0, 0, 1, 1)

        self.logger = logger
        self.audiobuffer = None

        # initialize the settings dialog
        self.settings_dialog = LongLevels_Settings_Dialog(self, self.logger)

        # initialize the class instance that will do the fft
        self.proc = audioproc(self.logger)

        #self.response_time = 60. # 1 minute
        self.response_time = 1.

        # 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

        # how many times we should decimate to end up with 100 points in the kernel
        self.Ndec = int(
            max(0,
                np.floor(
                    (np.log2(self.response_time * SAMPLING_RATE / 100.)))))

        n = self.response_time * SAMPLING_RATE / 2**self.Ndec
        N = int(5 * n)
        self.alpha = 1. - (1. - w)**(1. / (n + 1))
        self.kernel = (1. - self.alpha)**(np.arange(0, N)[::-1])

        self.level = None  # 1e-30
        self.level_rms = -200.

        self.two_channels = False

        self.i = 0

        self.subsampled_sampling_rate = SAMPLING_RATE / 2**(self.Ndec)
        self.subsampler = Subsampler(self.Ndec)

        self.old_index = 0

        self.length_seconds = 60. * 10
        # actually this should be linked to the pixel width of the plot area
        self.length_samples = self.length_seconds * self.subsampled_sampling_rate

        # ringbuffer for the subsampled data
        self.ringbuffer = RingBuffer(self.logger)