2 # Copyright 2004,2006 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
23 This is the 'generic' audio or soundcard interface.
25 The behavior of this module is controlled by the [audio] audio_module
26 configuration parameter. If it is 'auto' we attempt to import modules
27 from the known_modules list, using the first one imported successfully.
29 If [audio] audio_module is not 'auto', we assume it's the name of
30 an audio module and attempt to import it.
33 __all__ = ['source', 'sink']
35 from gnuradio import gr
43 'audio_alsa', 'audio_oss', 'audio_osx', 'audio_jack', 'audio_portaudio', 'audio_windows')
48 Build a blob of code and try to execute it.
49 If it succeeds we will have set the globals source and sink
55 full_name = "gnuradio." + name
60 """ % (full_name, full_name, full_name)
62 exec code in globals()
69 p = gr.prefs() # get preferences (config file) object
70 verbose = p.get_bool('audio', 'verbose', False)
71 module = p.get_string('audio', 'audio_module', 'auto')
73 if module == 'auto': # search our list for the first one that we can import
74 for m in known_modules:
76 if verbose: sys.stderr.write('audio: using %s\n' % (m,))
78 raise ImportError, 'Unable to locate an audio module.'
80 else: # use the one the user specified
81 if try_import(module):
82 if verbose: sys.stderr.write('audio: using %s\n' % (module,))
84 msg = 'Failed to import user-specified audio module %s' % (module,)
85 if verbose: sys.stderr.write('audio: %s\n' % (msg,))
86 raise ImportError, msg