~ubuntu-branches/ubuntu/trusty/gnuradio/trusty-updates

« back to all changes in this revision

Viewing changes to gnuradio-examples/python/audio/audio_fft.py

  • Committer: Package Import Robot
  • Author(s): A. Maitland Bottoms
  • Date: 2012-02-26 21:26:16 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120226212616-vsfkbi1158xshdql
Tags: 3.5.1-1
* new upstream version, re-packaged from scratch with modern tools
    closes: #642716, #645332, #394849, #616832, #590048, #642580,
    #647018, #557050, #559640, #631863
* CMake build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#
3
 
# Copyright 2004,2005,2007 Free Software Foundation, Inc.
4
 
5
 
# This file is part of GNU Radio
6
 
7
 
# GNU Radio is free software; you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License as published by
9
 
# the Free Software Foundation; either version 3, or (at your option)
10
 
# any later version.
11
 
12
 
# GNU Radio is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
# GNU General Public License for more details.
16
 
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with GNU Radio; see the file COPYING.  If not, write to
19
 
# the Free Software Foundation, Inc., 51 Franklin Street,
20
 
# Boston, MA 02110-1301, USA.
21
 
22
 
 
23
 
from gnuradio import gr, gru, audio
24
 
from gnuradio import eng_notation
25
 
from gnuradio.eng_option import eng_option
26
 
from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider
27
 
from optparse import OptionParser
28
 
import wx
29
 
import sys
30
 
 
31
 
class app_top_block(stdgui2.std_top_block):
32
 
    def __init__(self, frame, panel, vbox, argv):
33
 
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
34
 
 
35
 
        self.frame = frame
36
 
        self.panel = panel
37
 
        
38
 
        parser = OptionParser(option_class=eng_option)
39
 
        parser.add_option("-W", "--waterfall", action="store_true", default=False,
40
 
                          help="Enable waterfall display")
41
 
        parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
42
 
                          help="Enable oscilloscope display")
43
 
        parser.add_option("-I", "--audio-input", type="string", default="",
44
 
                          help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
45
 
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
46
 
                          help="set sample rate to RATE (48000)")
47
 
 
48
 
        (options, args) = parser.parse_args()   
49
 
        sample_rate = int(options.sample_rate)
50
 
        
51
 
        if len(args) != 0:
52
 
            parser.print_help()
53
 
            sys.exit(1)
54
 
 
55
 
        self.show_debug_info = True
56
 
        
57
 
        # build the graph
58
 
        if options.waterfall:
59
 
            self.scope = \
60
 
              waterfallsink2.waterfall_sink_f (panel, fft_size=1024, sample_rate=sample_rate)
61
 
        elif options.oscilloscope:
62
 
            self.scope = scopesink2.scope_sink_f(panel, sample_rate=sample_rate)
63
 
        else:
64
 
            self.scope = fftsink2.fft_sink_f (panel, fft_size=1024, sample_rate=sample_rate, fft_rate=30,
65
 
                                              ref_scale=1.0, ref_level=0, y_divs=12)
66
 
 
67
 
        self.src = audio.source (sample_rate, options.audio_input)
68
 
 
69
 
        self.connect(self.src, self.scope)
70
 
 
71
 
        self._build_gui(vbox)
72
 
 
73
 
        # set initial values
74
 
 
75
 
    def _set_status_msg(self, msg):
76
 
        self.frame.GetStatusBar().SetStatusText(msg, 0)
77
 
 
78
 
    def _build_gui(self, vbox):
79
 
 
80
 
        def _form_set_freq(kv):
81
 
            return self.set_freq(kv['freq'])
82
 
            
83
 
        vbox.Add(self.scope.win, 10, wx.EXPAND)
84
 
        
85
 
        #self._build_subpanel(vbox)
86
 
 
87
 
    def _build_subpanel(self, vbox_arg):
88
 
        # build a secondary information panel (sometimes hidden)
89
 
 
90
 
        # FIXME figure out how to have this be a subpanel that is always
91
 
        # created, but has its visibility controlled by foo.Show(True/False)
92
 
        
93
 
        def _form_set_decim(kv):
94
 
            return self.set_decim(kv['decim'])
95
 
 
96
 
        if not(self.show_debug_info):
97
 
            return
98
 
 
99
 
        panel = self.panel
100
 
        vbox = vbox_arg
101
 
        myform = self.myform
102
 
 
103
 
        #panel = wx.Panel(self.panel, -1)
104
 
        #vbox = wx.BoxSizer(wx.VERTICAL)
105
 
 
106
 
        hbox = wx.BoxSizer(wx.HORIZONTAL)
107
 
        hbox.Add((5,0), 0)
108
 
 
109
 
        myform['decim'] = form.int_field(
110
 
            parent=panel, sizer=hbox, label="Decim",
111
 
            callback=myform.check_input_and_call(_form_set_decim, self._set_status_msg))
112
 
 
113
 
        hbox.Add((5,0), 1)
114
 
        myform['fs@usb'] = form.static_float_field(
115
 
            parent=panel, sizer=hbox, label="Fs@USB")
116
 
 
117
 
        hbox.Add((5,0), 1)
118
 
        myform['dbname'] = form.static_text_field(
119
 
            parent=panel, sizer=hbox)
120
 
 
121
 
        hbox.Add((5,0), 1)
122
 
        myform['baseband'] = form.static_float_field(
123
 
            parent=panel, sizer=hbox, label="Analog BB")
124
 
 
125
 
        hbox.Add((5,0), 1)
126
 
        myform['ddc'] = form.static_float_field(
127
 
            parent=panel, sizer=hbox, label="DDC")
128
 
 
129
 
        hbox.Add((5,0), 0)
130
 
        vbox.Add(hbox, 0, wx.EXPAND)
131
 
 
132
 
        
133
 
def main ():
134
 
    app = stdgui2.stdapp(app_top_block, "Audio FFT", nstatus=1)
135
 
    app.MainLoop()
136
 
 
137
 
if __name__ == '__main__':
138
 
    main ()