515 |
kaklik |
1 |
#!/usr/bin/env python
|
|
|
2 |
##################################################
|
|
|
3 |
# Gnuradio Python Flow Graph
|
|
|
4 |
# Title: Sonar
|
|
|
5 |
# Author: Kaklik
|
|
|
6 |
# Description: Sonar waform generator
|
|
|
7 |
# Generated: Sat Feb 14 20:14:10 2009
|
|
|
8 |
##################################################
|
|
|
9 |
|
|
|
10 |
from gnuradio import audio
|
|
|
11 |
from gnuradio import gr
|
|
|
12 |
from gnuradio.wxgui import scopesink2
|
|
|
13 |
from grc_gnuradio import wxgui as grc_wxgui
|
|
|
14 |
import wx
|
|
|
15 |
|
|
|
16 |
class Sonar(grc_wxgui.top_block_gui):
|
|
|
17 |
|
|
|
18 |
def __init__(self):
|
|
|
19 |
grc_wxgui.top_block_gui.__init__(
|
|
|
20 |
self,
|
|
|
21 |
title="GRC - Executing: Sonar",
|
|
|
22 |
icon="/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png",
|
|
|
23 |
)
|
|
|
24 |
|
|
|
25 |
##################################################
|
|
|
26 |
# Variables
|
|
|
27 |
##################################################
|
|
|
28 |
self.samp_rate = samp_rate = 96000
|
|
|
29 |
self.ampl = ampl = .4
|
|
|
30 |
|
|
|
31 |
##################################################
|
|
|
32 |
# Controls
|
|
|
33 |
##################################################
|
|
|
34 |
_ampl_control = grc_wxgui.slider_horizontal_control(
|
|
|
35 |
window=self.GetWin(),
|
|
|
36 |
callback=self.set_ampl,
|
|
|
37 |
label="Volume",
|
|
|
38 |
value=ampl,
|
|
|
39 |
min=0,
|
|
|
40 |
max=.5,
|
|
|
41 |
num_steps=100,
|
|
|
42 |
slider_length=200,
|
|
|
43 |
)
|
|
|
44 |
self.GridAdd(_ampl_control, 0, 0, 1, 2)
|
|
|
45 |
|
|
|
46 |
##################################################
|
|
|
47 |
# Blocks
|
|
|
48 |
##################################################
|
|
|
49 |
self.audio_sink = audio.sink(96000, "hw:1,0", True)
|
|
|
50 |
self.audio_source_0 = audio.source(96000, "hw:1,0", True)
|
|
|
51 |
self.gr_sig_source_x = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 39000, ampl, 0)
|
|
|
52 |
self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
|
|
|
53 |
self.GetWin(),
|
|
|
54 |
title="Scope Plot",
|
|
|
55 |
sample_rate=250000,
|
|
|
56 |
frame_decim=15,
|
|
|
57 |
v_scale=None,
|
|
|
58 |
t_scale=.0001,
|
|
|
59 |
num_inputs=2,
|
|
|
60 |
)
|
|
|
61 |
self.wxgui_scopesink2_0.win.set_format_line()
|
|
|
62 |
self.Add(self.wxgui_scopesink2_0.win)
|
|
|
63 |
|
|
|
64 |
##################################################
|
|
|
65 |
# Connections
|
|
|
66 |
##################################################
|
|
|
67 |
self.connect((self.audio_source_0, 0), (self.wxgui_scopesink2_0, 1))
|
|
|
68 |
self.connect((self.gr_sig_source_x, 0), (self.audio_sink, 0))
|
|
|
69 |
self.connect((self.gr_sig_source_x, 0), (self.wxgui_scopesink2_0, 0))
|
|
|
70 |
|
|
|
71 |
def set_samp_rate(self, samp_rate):
|
|
|
72 |
self.samp_rate = samp_rate
|
|
|
73 |
self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)
|
|
|
74 |
self.gr_sig_source_x.set_sampling_freq(self.samp_rate)
|
|
|
75 |
|
|
|
76 |
def set_ampl(self, ampl):
|
|
|
77 |
self.ampl = ampl
|
|
|
78 |
self.gr_sig_source_x.set_amplitude(self.ampl)
|
|
|
79 |
|
|
|
80 |
if __name__ == '__main__':
|
|
|
81 |
if gr.enable_realtime_scheduling() != gr.RT_OK:
|
|
|
82 |
print "Error: failed to enable realtime scheduling."
|
|
|
83 |
tb = Sonar()
|
|
|
84 |
tb.Run()
|
|
|
85 |
|