Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
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: Fri Feb 20 19:31:13 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.frequency = frequency = 20000
30
		self.ampl = ampl = .4
31
 
32
		##################################################
33
		# Controls
34
		##################################################
35
		_frequency_control = grc_wxgui.slider_horizontal_control(
36
			window=self.GetWin(),
37
			callback=self.set_frequency,
38
			label='frequency',
39
			value=frequency,
40
			min=5000,
41
			max=30000,
42
			num_steps=1000,
43
			slider_length=500,
44
		)
45
		self.Add(_frequency_control)
46
		_ampl_control = grc_wxgui.slider_horizontal_control(
47
			window=self.GetWin(),
48
			callback=self.set_ampl,
49
			label="Volume",
50
			value=ampl,
51
			min=0,
52
			max=.5,
53
			num_steps=100,
54
			slider_length=200,
55
		)
56
		self.GridAdd(_ampl_control, 0, 0, 1, 2)
57
 
58
		##################################################
59
		# Blocks
60
		##################################################
61
		self.audio_sink = audio.sink(48000, "hw:1,0", True)
62
		self.audio_source_0 = audio.source(48000, "hw:1,0", True)
63
		self.gr_sig_source_x = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, frequency, ampl, 0)
64
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
65
			self.GetWin(),
66
			title="Scope Plot",
67
			sample_rate=samp_rate*2,
68
			frame_decim=15,
69
			v_scale=None,
70
			t_scale=.0001,
71
			num_inputs=2,
72
		)
73
		self.wxgui_scopesink2_0.win.set_format_line()
74
		self.Add(self.wxgui_scopesink2_0.win)
75
 
76
		##################################################
77
		# Connections
78
		##################################################
79
		self.connect((self.gr_sig_source_x, 0), (self.audio_sink, 0))
80
		self.connect((self.gr_sig_source_x, 0), (self.wxgui_scopesink2_0, 0))
81
		self.connect((self.audio_source_0, 0), (self.wxgui_scopesink2_0, 1))
82
 
83
	def set_samp_rate(self, samp_rate):
84
		self.samp_rate = samp_rate
85
		self.gr_sig_source_x.set_sampling_freq(self.samp_rate)
86
		self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate*2)
87
 
88
	def set_frequency(self, frequency):
89
		self.frequency = frequency
90
		self.gr_sig_source_x.set_frequency(self.frequency)
91
 
92
	def set_ampl(self, ampl):
93
		self.ampl = ampl
94
		self.gr_sig_source_x.set_amplitude(self.ampl)
95
 
96
if __name__ == '__main__':
97
	if gr.enable_realtime_scheduling() != gr.RT_OK:
98
		print "Error: failed to enable realtime scheduling."
99
	tb = Sonar()
100
	tb.Run()
101