Esempio n. 1
0
class LiveFFTWidget(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()
        self.initData()
        self.connectSlots()
        self.initMplWidget()

    def initUI(self):
        hbox_gain = QHBoxLayout()
        autoGain = QLabel('Auto gain for frequency spectrum')
        autoGainCheckBox = QCheckBox(checked=True)
        hbox_gain.addWidget(autoGain)
        hbox_gain.addWidget(autoGainCheckBox)

        self.autoGainCheckBox = autoGainCheckBox

        hbox_fixedGain = QHBoxLayout()
        fixedGain = QLabel('Manual gain level for frequency spectrum')
        fixedGainSlider = QSlider(QtCore.Qt.Horizontal)
        hbox_fixedGain.addWidget(fixedGain)
        hbox_fixedGain.addWidget(fixedGainSlider)

        self.fixedGainSlider = fixedGainSlider

        self.vbox = QVBoxLayout()

        self.vbox.addLaout(hbox_gain)
        self.vbox.addLayout(hbox_fixedGain)

        self.main_figure = MplFigure(self)
        self.vbox.addWidget(self.main_figure.toolbar)
        self.vbox.addWidget(self.main_figure.canvas)

        self.setLayout(self.vbox)

        self.setGeometry(300, 300, 350, 300)
        self.setWindowTitle('LiveFFT')
        self.show()

        timer = QtCore.QTimer()
        timer.timeoutconnect(self.handleNewData)
        timer.start(100)
        self.timer = timer

    def initData(self):
        self.mic = MicrophoneRecorder()
        self.mic.start()

        self.freq_vect = np.fft.rfftfreq(self.mic.chunksize,
                                         1. / self.mic.rate)
        self.time_vect = np.arrange(mic.chunksize,
                                    dtype=np.float32) / mic.rate * 1000

    def connectSlots(self):
        pass

    def initMplWidget(self):
        pass

    def handleNewData(self):
        pass