77# Generated: Mon Jun 8 12:38:35 2015
88##################################################
99from gnuradio import analog
10- from gnuradio import blocks
11- from gnuradio import eng_notation
1210from gnuradio import filter
1311from gnuradio import gr
1412from gnuradio .eng_option import eng_option
1513from gnuradio .filter import firdes
16- from optparse import OptionParser
1714import osmosdr
1815import time
19-
20- from audiostream import get_output , AudioSample
21- from struct import *
22- import numpy
16+ import tinyalsa
2317
2418from kivy .app import App
2519from kivy .uix .widget import Widget
2620
2721
28- import os
29-
30- class AudioSink (gr .sync_block ):
31- "AudioSink"
32- def __init__ (self ):
33- gr .sync_block .__init__ (
34- self ,
35- name = "AudioSink" ,
36- #in_sig = [numpy.float32,numpy.float32], # Input signature: 2 float at a time
37- in_sig = [numpy .int ,numpy .int ], # Input signature: 2 int at a time
38- out_sig = [], # Output signature: 1 float at a time
39- )
40- self .stream = get_output (channels = 2 , buffersize = 2048 , rate = 48000 )
41- self .sample = AudioSample ()
42- self .stream .add_sample (self .sample )
43- #self.scale=pow(2.,14)
44- self .first = True
45- print ('AudioSink initialized' )
46-
47- def work (self , input_items , output_items ):
48- if self .first :
49- self .sample .play ()
50- self .first = False
51-
52- count = len (input_items [0 ])
53- for i in range (0 , count ):
54- self .sample .write (pack ('<hh' ,input_items [0 ][i ],input_items [1 ][i ]))
55-
56- return count
57-
58- def starte (self ):
59- self .sample .play ()
60-
61- def halte (self ):
62- self .sample .stop ()
22+ #import os
6323
6424class Rtlradio (gr .top_block ):
6525
@@ -74,11 +34,8 @@ def __init__(self):
7434 ##################################################
7535 # Blocks
7636 ##################################################
77- self .tinyalsa_talsa_sink_0 = AudioSink ()
78- self .blocks_float_to_int_0 = blocks .float_to_int (1 , pow (2. ,15 ))
79- print ('+++Vor osmo' )
37+ self .tinyalsa_talsa_sink_0 = tinyalsa .talsa_sink (48000 , 1 , 0 )
8038 self .rtlsdr_source_0 = osmosdr .source ( args = "numchan=" + str (1 ) + " " + "rtl=0" )
81- print ('+++Nach osmo' )
8239 self .rtlsdr_source_0 .set_sample_rate (samp_rate )
8340 self .rtlsdr_source_0 .set_center_freq (88.8e6 , 0 )
8441 self .rtlsdr_source_0 .set_freq_corr (0 , 0 )
@@ -90,7 +47,7 @@ def __init__(self):
9047 self .rtlsdr_source_0 .set_bb_gain (20 , 0 )
9148 self .rtlsdr_source_0 .set_antenna ("" , 0 )
9249 self .rtlsdr_source_0 .set_bandwidth (0 , 0 )
93-
50+
9451 self .low_pass_filter_0 = filter .fir_filter_ccf (10 , firdes .low_pass (
9552 4 , samp_rate , 48000 , 5000 , firdes .WIN_HAMMING , 6.76 ))
9653 self .analog_fm_demod_cf_0 = analog .fm_demod_cf (
@@ -106,13 +63,12 @@ def __init__(self):
10663 ##################################################
10764 # Connections
10865 ##################################################
109-
110- self .connect ((self .analog_fm_demod_cf_0 , 0 ), (self .blocks_float_to_int_0 , 0 ))
111- self .connect ((self .blocks_float_to_int_0 , 0 ) , (self .tinyalsa_talsa_sink_0 , 0 ))
112- self .connect ((self .blocks_float_to_int_0 , 0 ) , (self .tinyalsa_talsa_sink_0 , 1 ))
66+ self .connect ((self .analog_fm_demod_cf_0 , 0 ), (self .tinyalsa_talsa_sink_0 , 0 ))
67+ self .connect ((self .analog_fm_demod_cf_0 , 0 ), (self .tinyalsa_talsa_sink_0 , 1 ))
11368 self .connect ((self .low_pass_filter_0 , 0 ), (self .analog_fm_demod_cf_0 , 0 ))
11469 self .connect ((self .rtlsdr_source_0 , 0 ), (self .low_pass_filter_0 , 0 ))
11570
71+
11672 def get_samp_rate (self ):
11773 return self .samp_rate
11874
@@ -131,7 +87,7 @@ def build(self):
13187 rootWindow = RtlradioWindow ()
13288 self .tb = Rtlradio ()
13389 self .started = 0
134- print ("####Environment" , os .environ )
90+ # print("####Environment", os.environ)
13591 return rootWindow
13692
13793 def startstop_audio (self ):
@@ -140,24 +96,12 @@ def startstop_audio(self):
14096 self .started = 0
14197 print ('Vor stop' )
14298 self .tb .stop ()
143- #self.tb.tinyalsa_talsa_sink_0.halte()
14499 print ('Nach stop' )
145100 else :
146101 print ('Vor start' )
147102 self .started = 1
148103 self .tb .start ()
149- #self.tb.tinyalsa_talsa_sink_0.starte()
150104 print ('Nach start' )
151105
152106if __name__ == '__main__' :
153107 RtlradioApp ().run ()
154- # parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
155- # (options, args) = parser.parse_args()
156- # tb = dial_tone()
157- # tb.start()
158- # try:
159- # raw_input('Press Enter to quit: ')
160- # except EOFError:
161- # pass
162- # tb.stop()
163- # tb.wait()
0 commit comments