Skip to content

Commit

Permalink
GUI: make audio player independed of reception using volume= 0 for ST…
Browse files Browse the repository at this point in the history
…OP and valve block for RECORD
  • Loading branch information
MLsmd committed Aug 27, 2017
1 parent ac15d36 commit 6228a4b
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 179 deletions.
148 changes: 69 additions & 79 deletions apps/DABstep
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import dab.constants as constants
import math
import json
import sip
import os

resolution_width = 0
resolution_height = 0
Expand Down Expand Up @@ -50,10 +49,11 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.subch = -1
self.dabplus = True
self.need_new_init = True
self.recorder = False
self.file_path = "None"
self.src_is_USRP = True
self.receiver_running = False
self.audio_playing = False
self.recording = False

# table preparations
header = self.table_mci.horizontalHeader()
Expand Down Expand Up @@ -85,11 +85,13 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.timer_audio_sampling_rate = QTimer()
self.timer_audio_sampling_rate.timeout.connect(self.adjust_audio_sampling_rate)
# stop button click stops audio reception
self.btn_stop.clicked.connect(self.stop_reception)
self.btn_stop.hide()
self.btn_stop.clicked.connect(self.stop_audio)
# volume slider moved
self.slider_volume.valueChanged.connect(self.set_volume)
# record button
self.btn_record.clicked.connect(self.record_audio)
self.btn_record.setCheckable(True)

######################################################################
# DEVELOPER MODE
Expand Down Expand Up @@ -251,7 +253,8 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.label_path.setStyleSheet('color: black')
# set up and start flowgraph
self.my_receiver = usrp_dab_rx.usrp_dab_rx(self.spin_dab_mode.value(), self.spinbox_frequency.value(), self.bit_rate, self.address, self.size, self.protection, self.audio_bit_rate, self.dabplus,
self.src_is_USRP, self.file_path, self.recorder)
self.src_is_USRP, self.file_path)
self.my_receiver.set_volume(0)
self.my_receiver.start()
# status bar
self.statusBar.showMessage("Reception is running.")
Expand All @@ -262,6 +265,11 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.update_service_info()
self.btn_update_info.setEnabled(True)
self.snr_update()
self.slider_volume.setEnabled(True)
self.btn_play.setEnabled(True)
self.btn_stop.setEnabled(True)
self.btn_update_info.setEnabled(True)
self.btn_record.setEnabled(True)
self.snr_timer.start(1000)
self.firecode_timer.start(120)
self.receiver_running = True
Expand All @@ -270,6 +278,14 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.my_receiver.stop()
self.receiver_running = False
self.btn_init.setText("start receiver")
self.slider_volume.setEnabled(False)
self.btn_play.setEnabled(False)
self.btn_stop.setEnabled(False)
self.btn_update_info.setEnabled(False)
self.btn_record.setEnabled(False)
self.btn_play.show()
self.btn_stop.hide()
self.audio_playing = False
self.statusBar.showMessage("Receiver stopped.")

def update_service_info(self):
Expand Down Expand Up @@ -311,9 +327,9 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
# enable/disable buttons
self.btn_play.setEnabled(True)
self.btn_record.setEnabled(True)
# new subch was selected
self.btn_play.setText("Play")
self.slider_volume.setEnabled(False)
if self.audio_playing:
self.btn_stop.show()
self.btn_play.show()

# get selected sub-channel by its ID
ID = self.table_mci.item(self.table_mci.currentRow(), 0).text()
Expand Down Expand Up @@ -378,48 +394,44 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.snr_timer.start(1000)

def play_audio(self):
if not self.slider_volume.isEnabled():
# play button pressed
self.btn_play.setText("Mute")
self.btn_stop.setEnabled(True)
self.slider_volume.setEnabled(True)
self.btn_update_info.setEnabled(True)
self.slider_volume.setValue(self.volume)
self.set_volume()
# if selected sub-channel is not the current sub-channel we have to reconfigure the receiver
if self.subch is not self.table_mci.currentRow():
self.subch = self.table_mci.currentRow()
dev_mode_opened = False
if self.dev_mode_active:
dev_mode_opened = True
self.dev_mode_close()
self.snr_timer.stop()
self.firecode_timer.stop()
self.my_receiver.stop()
self.my_receiver = usrp_dab_rx.usrp_dab_rx(self.spin_dab_mode.value(),
self.spinbox_frequency.value(), self.bit_rate,
self.address, self.size,
self.protection, self.audio_bit_rate, self.dabplus,
self.src_is_USRP, self.file_path, self.recorder)

self.my_receiver.start()
self.statusBar.showMessage("Audio playing.")
self.dev_mode_init()
if dev_mode_opened:
self.dev_mode_open()
else:
# mute button pressed
self.btn_play.setText("Play")
self.volume = self.slider_volume.value()
self.slider_volume.setValue(0)
self.slider_volume.setEnabled(False)
self.set_volume()
self.need_new_init = False
# play button pressed
# if selected sub-channel is not the current sub-channel we have to reconfigure the receiver
if self.subch is not self.table_mci.currentRow():
self.subch = self.table_mci.currentRow()
dev_mode_opened = False
if self.dev_mode_active:
dev_mode_opened = True
self.dev_mode_close()
self.snr_timer.stop()
self.firecode_timer.stop()
self.my_receiver.stop()
self.my_receiver = usrp_dab_rx.usrp_dab_rx(self.spin_dab_mode.value(),
self.spinbox_frequency.value(), self.bit_rate,
self.address, self.size,
self.protection, self.audio_bit_rate, self.dabplus,
self.src_is_USRP, self.file_path)
self.my_receiver.set_volume(float(self.slider_volume.value()) / 100)
self.my_receiver.start()
self.statusBar.showMessage("Audio playing.")
self.dev_mode_init()
if dev_mode_opened:
self.dev_mode_open()
self.my_receiver.set_volume(float(self.slider_volume.value()) / 100)
self.audio_playing = True
# start timer for snr update again
self.snr_timer.start(1000)
self.firecode_timer.start(120)
# start audio sampling rate timer
self.timer_audio_sampling_rate.start(500)
# toggle start/stop button
self.btn_play.hide()
self.btn_stop.show()

def stop_audio(self):
self.my_receiver.set_volume(0)
self.audio_playing = False
self.btn_play.show()
self.btn_stop.hide()

def adjust_audio_sampling_rate(self):
self.timer_audio_sampling_rate.stop()
Expand All @@ -433,49 +445,27 @@ class DABstep(QtGui.QMainWindow, user_frontend.Ui_MainWindow):
self.spinbox_frequency.value(), self.bit_rate,
self.address, self.size,
self.protection, self.audio_bit_rate, self.dabplus,
self.src_is_USRP, self.file_path, self.recorder)
self.src_is_USRP, self.file_path)

self.my_receiver.start()
elif new_sampling_rate == -1:
self.timer_audio_sampling_rate.start(200)

def stop_reception(self):
# close dev mode
self.btn_dev_mode_close.hide()
self.btn_dev_mode_open.show()
self.btn_dev_mode_open.setEnabled(False)
# stop flowgraph
self.my_receiver.stop()
# enable/disable buttons
self.btn_stop.setEnabled(False)
self.btn_play.setText("Play")
self.btn_play.setEnabled(True)
self.slider_volume.setEnabled(False)
self.btn_update_info.setEnabled(False)
self.btn_record.setEnabled(True)
self.recorder = False
# stop snr updates because no flowgraph is running to measure snr
self.snr_timer.stop()
self.firecode_timer.stop()
self.statusBar.showMessage("Reception stopped.")

def record_audio(self):
# enable/disable buttons
self.btn_record.setEnabled(False)
self.btn_play.setEnabled(False)
self.btn_stop.setEnabled(True)
self.recorder = True
# start flowgraph
self.my_receiver = usrp_dab_rx.usrp_dab_rx(self.spin_dab_mode.value(), self.spinbox_frequency.value(), self.bit_rate, self.address, self.size,
self.protection, self.audio_bit_rate, self.dabplus,
self.src_is_USRP, self.file_path, self.recorder)

self.my_receiver.start()
self.statusBar.showMessage("Recording audio ...")
if self.recording:
self.my_receiver.set_valve_closed(True)
self.recording = False
self.btn_record.setChecked(False)

else:
self.my_receiver.set_valve_closed(False)
self.recording = True
self.btn_record.setChecked(True)

def set_volume(self):
# map volume from [0:100] to [0:1]
self.my_receiver.set_volume(float(self.slider_volume.value()) / 100)
if self.audio_playing:
# map volume from [0:100] to [0:1]
self.my_receiver.set_volume(float(self.slider_volume.value()) / 100)

def get_ensemble_info(self):
self.json = self.my_receiver.get_ensemble_info()
Expand Down
Loading

0 comments on commit 6228a4b

Please sign in to comment.