Skip to content

Commit

Permalink
When a demodulator has no output, Receiver follows suit.
Browse files Browse the repository at this point in the history
This requires special handling in Top but is more CPU-efficient and
correct than the previous strategy of producing a zeroed output.
  • Loading branch information
kpreid committed Jan 28, 2016
1 parent 71264c2 commit 626dcc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 5 additions & 10 deletions shinysdr/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __update_demodulator_info(self):
self.__demod_stereo = output_type.get_kind() == 'STEREO'
self.__output_type = SignalType(
kind='STEREO',
sample_rate=output_type.get_sample_rate() if self.__demod_output else _dummy_audio_rate)
sample_rate=output_type.get_sample_rate() if self.__demod_output else 0)

def __do_connect(self, reason):
#log.msg(u'receiver do_connect: %s' % (reason,))
Expand Down Expand Up @@ -152,15 +152,10 @@ def __do_connect(self, reason):
# TODO: should mix left and right or something
self.connect((self.__demodulator, 0), self.probe_audio)
else:
# Dummy output.
# TODO: Teach top block about no-audio so we don't have to have a dummy output.
throttle = blocks.throttle(gr.sizeof_float, _dummy_audio_rate)
throttle.set_max_output_buffer(_dummy_audio_rate // 10) # ensure smooth output
self.connect(
analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0),
throttle)
for ch in xrange(self.__audio_channels):
self.connect(throttle, (self, ch))
# Dummy output, ignored by containing block
source_of_nothing = blocks.vector_source_f([])
for ch in xrange(0, self.__audio_channels):
self.connect(source_of_nothing, (self, ch))

if self.__output_type != self.__last_output_type:
self.__last_output_type = self.__output_type
Expand Down
9 changes: 8 additions & 1 deletion shinysdr/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ def _do_connect(self):
log.err('Flow graph: Refusing to connect more than 6 receivers')
break
self.connect(self._sources[receiver.get_device_name()].get_rx_driver(), receiver)
audio_rs.input(receiver, receiver.get_output_type().get_sample_rate(), receiver.get_audio_destination())
receiver_output_type = receiver.get_output_type()
if receiver_output_type.get_sample_rate() <= 0:
# receiver has dummy output, connect it to something to satisfy flow graph structure
for ch in xrange(0, self.__audio_manager.get_channels()):
self.connect((receiver, ch), blocks.null_sink(gr.sizeof_float))
else:
assert receiver_output_type.get_kind() == 'STEREO'
audio_rs.input(receiver, receiver_output_type.get_sample_rate(), receiver.get_audio_destination())

self.__has_a_useful_receiver = audio_rs.finish_bus_connections()

Expand Down

0 comments on commit 626dcc7

Please sign in to comment.