예제 #1
0
 def _set_audio_device_box(self):
     # format: "idx - device name"
     devices = AudioDevice().list_devices()
     items = []
     for device in devices:
         index = device['index']
         name = device['name']
         item = str(index) + ' - ' + name
         items.append(item)
     self.ui.audioDeviceBox.addItems(items)
예제 #2
0
 def start_recording(self):
     self.file_path = self._get_save_path()
     # initialize stream
     audio_device_index = self._get_audio_device_index()
     for device in AudioDevice().list_devices():
         if device['index'] == audio_device_index:
             channels = device['channels']
     # TODO: Now I set `channels=1` to make the audio file to be mono.
     # It's only for the current audio interface. It's supposed to be
     # variable `channels`. Also it can be improved by specifying a certain
     # channel of input device, and always making the audio file mono.
     self.recording_file = Recorder(channels=1).open(
         self.file_path, audio_device_index)
     self.recording_file.start_recording()
     # update objects
     # update the buttons' status
     self.is_recording = True
     self._update_status()
     # clean up any text in promptLabel
     self.ui.promptLabel.setText('')
     # start counting
     self.timer.start(1000)
예제 #3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        # Default values. Updated if found in config.JSON
        self.use_qt_thread = False
        self.rhythm_algorithm = "multifeature"
        self.default_device_name = ""
        self.show_video_preview = True
        self.video_loop_bpm = 60
        self.video_update_skip_ms = 100
        self.limit_tempo_by_default = False
        self.tempo_lower_limit = 60.0
        self.tempo_upper_limit = 120.0
        self.screen = 0

        self.spotify_track_id = ""

        self.read_config()

        self.setWindowTitle("Gandalf Enjoys Music")
        self.desktop = QApplication.desktop()

        self.audio = AudioDevice(self.default_device_name)
        self.input_devices = self.audio.get_input_device_names()

        self.audio_changed.connect(self.audio.change_audio_input)

        if self.use_qt_thread:
            self.bpm_extractor = BPMQt(self.update_bpm,
                                       algorithm=self.rhythm_algorithm)
        else:
            self.bpm_extractor = BPMmp(self.update_bpm,
                                       algorithm=self.rhythm_algorithm)

        self.audio.data_ready.connect(self.bpm_extractor.start_bpm_calculation)

        self.init_ui()
import matplotlib.animation
import numpy
import threading

# engine = engine_factory.v_four_90_deg()
# engine = engine_factory.w_16()
# engine = engine_factory.v_8_LS()
# engine = engine_factory.inline_5_crossplane()
# engine = engine_factory.inline_6()
engine = engine_factory.boxer_4_crossplane_custom(
    [1, 1, 0, 0])  # (rando := random.randrange(360)))
# engine = engine_factory.boxer_4_half()
# engine = engine_factory.random()
# engine = engine_factory.fake_rotary_2rotor()

audio_device = AudioDevice()
stream = audio_device.play_stream(engine.gen_audio)

print('\nEngine is running...')
# print(rando)

RATE = 44100
BUFFER = 882

fig = plt.figure()
line1 = plt.plot([], [])[0]
line2 = plt.plot([], [])[0]

r = range(0, int(RATE / 2 + 1), int(RATE / BUFFER))
l = len(r)
예제 #5
0
    def __init__(self, logger):
        self.logger = logger
        super(MainWindow, self).__init__()
        self.ui = Terzpegelmesser.Ui_MainWindow()
        self.ui.setupUi(self)
        self.chunk_number = 0
        self.buffer_timer_time = 0.
        self.cpu_percent = 0.
        self.setMinimumSize(1000, 600)
        # Initialize the audio data ring buffer
        self.audiobuffer = AudioBuffer(self.logger)
        # Initialize the audio device
        self.audio_device = AudioDevice(self.logger)
        # Initialize the blocklength
        self.blocklength = 2048
        self.ui.BoxFFT.setCurrentIndex(6)
        self.logger.push("initial set Blocksize to " + str(self.blocklength))
        # Initialize the frequency weighting flag
        self.weight = 0
        # Initialize the number of samples shown in waveform monitor
        self.window = 128
        # Initialize the number of periods shown in waveform monitor
        self.NumberOfPeriods = 10
        # Initialize the flag for lin (0) and log (1) fft plotting
        self.plotflag = 1
        devices = self.audio_device.get_readable_devices_list()

        for device in devices:
            self.ui.DeviceList.addItem(device)

        current_device = self.audio_device.get_readable_current_device()
        self.ui.DeviceList.setCurrentIndex(current_device)
        self.display_timer = QTimer()
        self.display_timer.setInterval(SMOOTH_DISPLAY_TIMER_PERIOD_MS)
        self.connect(self.display_timer, SIGNAL('timeout()'),
                      self.update_buffer)
        self.connect(self.ui.ButtonStartStop, SIGNAL('triggered()'),
                     self.stream_run)
        self.connect(self.ui.DeviceList, SIGNAL('currentIndexChanged(int)'),
                     self.input_device_changed)
        self.connect(self.ui.BoxFFT, SIGNAL('currentIndexChanged(int)'),
                      self.update_blocklength)

        self.ui.action32.triggered.connect(lambda: self.update_blocklength(0))
        self.ui.action32.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(0))
        self.ui.action64.triggered.connect(lambda: self.update_blocklength(1))
        self.ui.action64.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(1))
        self.ui.action128.triggered.connect(lambda: self.update_blocklength(2))
        self.ui.action128.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(2))
        self.ui.action256.triggered.connect(lambda: self.update_blocklength(3))
        self.ui.action256.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(3))
        self.ui.action512.triggered.connect(lambda: self.update_blocklength(4))
        self.ui.action512.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(4))
        self.ui.action1024.triggered.connect(lambda: self.update_blocklength(
            5))
        self.ui.action1024.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(5))
        self.ui.action2048.triggered.connect(lambda: self.update_blocklength(
            6))
        self.ui.action2048.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(6))
        self.ui.action4096.triggered.connect(lambda: self.update_blocklength(
            7))
        self.ui.action4096.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(7))
        self.ui.action8192.triggered.connect(lambda: self.update_blocklength(
            8))
        self.ui.action8192.triggered.connect(
            lambda: self.ui.BoxFFT.setCurrentIndex(8))

        self.ui.actionNone.triggered.connect(lambda: self.update_weight(0))
        self.ui.actionNone.triggered.connect(
            lambda: self.ui.BoxBew.setCurrentIndex(0))
        self.ui.actionA.triggered.connect(lambda: self.update_weight(1))
        self.ui.actionA.triggered.connect(
            lambda: self.ui.BoxBew.setCurrentIndex(1))
        self.ui.actionC.triggered.connect(lambda: self.update_weight(2))
        self.ui.actionC.triggered.connect(
            lambda: self.ui.BoxBew.setCurrentIndex(2))

        self.connect(self.ui.BoxBew, SIGNAL('currentIndexChanged(int)'),
                      self.update_weight)
        self.connect(self.ui.RadioLin, SIGNAL("clicked()"),
                      self.update_plotflag_lin)
        self.connect(self.ui.RadioLog, SIGNAL("clicked()"),
                      self.update_plotflag_log)

        self.ui.actionLogarithmic.triggered.connect(self.update_plotflag_log)
        self.ui.actionLogarithmic.triggered.connect(
            lambda: self.ui.RadioLog.setChecked(True))
        self.ui.actionLinear.triggered.connect(self.update_plotflag_lin)
        self.ui.actionLinear.triggered.connect(
            lambda: self.ui.RadioLin.setChecked(True))

        self.connect(self.ui.push_plus, SIGNAL("clicked()"),
                      self.update_NumberOfPeriods_minus)
        self.ui.actionZoom_Out.triggered.connect(
                    self.update_NumberOfPeriods_plus)

        self.connect(self.ui.push_minus, SIGNAL("clicked()"),
                      self.update_NumberOfPeriods_plus)
        self.ui.actionZoom_In.triggered.connect(
                    self.update_NumberOfPeriods_minus)

        self.gain_plotter = (
                        gain_plotter.Gain_Plotter(self.ui.PlotGainVerlauf,
                                                       self.audiobuffer))
        self.spektro_plotter = (
                third_octave_plotter.SpektroPlotter(self.ui.PlotTerzpegel,
                                                            self.audiobuffer))
        self.waveform = waveform.Oszi(self.ui.PlotWellenform,
                                      self.audiobuffer, self.NumberOfPeriods)
        self.channelplotter = (
                        channel_plotter.ChannelPlotter(self.ui.PlotKanalpegel,
                                                             self.audiobuffer))
        self.specgramplot = (
                spectrogram_plotter.Spectrogram_Plot(self.ui.PlotSpektrogramm,
                                                            self.audiobuffer))
        self.spektro_plotter_2 = (
                third_octave_plotter.SpektroPlotter(self.ui.PlotTerzpegel_2,
                                                            self.audiobuffer))
        self.fft_plot = fft_plotter.FFTPlotter(self.ui.PlotFFT,
                                               self.audiobuffer,
                                               self.blocklength, self.plotflag)
    # if the startStop button is clicked, the timer starts and the stream is
    # filled with acoustic data
        self.ui.ButtonStartStop.clicked.connect(self.stream_run)
        self.ui.ButtonStartStop.state = 0
        self.display_timer.timeout.connect(self.update_plot)