diff options
author | Josh Morman <jmorman@gnuradio.org> | 2021-11-24 12:02:17 -0500 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-11-24 14:41:53 -0500 |
commit | 42e58f1ca211115e9a76922c36dfbf2b1ad39978 (patch) | |
tree | 2d3df32ae49c64d399be77ec5830a0c25ff31df9 /gr-audio/examples/python | |
parent | 2ede969ec5f3f6d361814403b7375db5f15ec14d (diff) |
audio: pep8 formatting
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Diffstat (limited to 'gr-audio/examples/python')
-rw-r--r-- | gr-audio/examples/python/audio_copy.py | 22 | ||||
-rw-r--r-- | gr-audio/examples/python/audio_play.py | 6 | ||||
-rw-r--r-- | gr-audio/examples/python/audio_to_file.py | 9 | ||||
-rw-r--r-- | gr-audio/examples/python/dial_tone.py | 6 | ||||
-rw-r--r-- | gr-audio/examples/python/dial_tone_wav.py | 8 | ||||
-rw-r--r-- | gr-audio/examples/python/mono_tone.py | 11 | ||||
-rw-r--r-- | gr-audio/examples/python/multi_tone.py | 31 | ||||
-rw-r--r-- | gr-audio/examples/python/noise.py | 6 | ||||
-rw-r--r-- | gr-audio/examples/python/spectrum_inversion.py | 11 | ||||
-rw-r--r-- | gr-audio/examples/python/test_resampler.py | 8 |
10 files changed, 66 insertions, 52 deletions
diff --git a/gr-audio/examples/python/audio_copy.py b/gr-audio/examples/python/audio_copy.py index 6cdb7bfdb5..274a539aa1 100644 --- a/gr-audio/examples/python/audio_copy.py +++ b/gr-audio/examples/python/audio_copy.py @@ -13,6 +13,7 @@ from gnuradio import audio from gnuradio.eng_arg import eng_float from argparse import ArgumentParser + class my_top_block(gr.top_block): def __init__(self): @@ -20,25 +21,25 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-I", "--audio-input", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate, default=%(default)s") - args = parser.parse_args () + help="set sample rate, default=%(default)s") + args = parser.parse_args() sample_rate = int(args.sample_rate) - src = audio.source (sample_rate, args.audio_input) - dst = audio.sink (sample_rate, args.audio_output) + src = audio.source(sample_rate, args.audio_input) + dst = audio.sink(sample_rate, args.audio_output) # Determine the maximum number of outputs on the source and # maximum number of inputs on the sink, then connect together # the most channels we can without overlap - nchan = min (src.output_signature().max_streams(), - dst.input_signature().max_streams()) + nchan = min(src.output_signature().max_streams(), + dst.input_signature().max_streams()) - for i in range (nchan): - self.connect ((src, i), (dst, i)) + for i in range(nchan): + self.connect((src, i), (dst, i)) if __name__ == '__main__': @@ -46,4 +47,3 @@ if __name__ == '__main__': my_top_block().run() except KeyboardInterrupt: pass - diff --git a/gr-audio/examples/python/audio_play.py b/gr-audio/examples/python/audio_play.py index 1fc4b5128a..d93e187d68 100644 --- a/gr-audio/examples/python/audio_play.py +++ b/gr-audio/examples/python/audio_play.py @@ -22,12 +22,12 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-F", "--filename", default="audio.dat", - help="read input from FILENAME default=%(default)r") + help="read input from FILENAME default=%(default)r") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate (default=%(default)r)") + help="set sample rate (default=%(default)r)") parser.add_argument("-R", "--repeat", action="store_true") parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") args = parser.parse_args() sample_rate = int(args.sample_rate) src = blocks.file_source(gr.sizeof_float, args.filename, args.repeat) diff --git a/gr-audio/examples/python/audio_to_file.py b/gr-audio/examples/python/audio_to_file.py index 19335a8279..7221e39d1a 100644 --- a/gr-audio/examples/python/audio_to_file.py +++ b/gr-audio/examples/python/audio_to_file.py @@ -14,6 +14,7 @@ from gnuradio import blocks from gnuradio.eng_arg import eng_float from argparse import ArgumentParser + class my_top_block(gr.top_block): def __init__(self): @@ -21,13 +22,13 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-I", "--audio-input", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate to RATE (%(default)r)") + help="set sample rate to RATE (%(default)r)") parser.add_argument("-N", "--nsamples", type=eng_float, - help="number of samples to collect [default=+inf]") + help="number of samples to collect [default=+inf]") parser.add_argument('file_name', metavar='FILE-NAME', - help="Output file path") + help="Output file path") args = parser.parse_args() diff --git a/gr-audio/examples/python/dial_tone.py b/gr-audio/examples/python/dial_tone.py index a38221faca..b175f8964c 100644 --- a/gr-audio/examples/python/dial_tone.py +++ b/gr-audio/examples/python/dial_tone.py @@ -19,6 +19,7 @@ except ImportError: sys.stderr.write("Error: Program requires gr-analog.\n") sys.exit(1) + class my_top_block(gr.top_block): def __init__(self): @@ -26,9 +27,9 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate, default=%(default)s") + help="set sample rate, default=%(default)s") args = parser.parse_args() sample_rate = int(args.sample_rate) @@ -40,6 +41,7 @@ class my_top_block(gr.top_block): self.connect(src0, (dst, 0)) self.connect(src1, (dst, 1)) + if __name__ == '__main__': try: my_top_block().run() diff --git a/gr-audio/examples/python/dial_tone_wav.py b/gr-audio/examples/python/dial_tone_wav.py index 58bf412c21..db576140ea 100644 --- a/gr-audio/examples/python/dial_tone_wav.py +++ b/gr-audio/examples/python/dial_tone_wav.py @@ -21,6 +21,7 @@ except ImportError: sys.stderr.write("Error: Program requires gr-analog.\n") sys.exit(1) + class my_top_block(gr.top_block): def __init__(self): @@ -28,11 +29,11 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate to RATE (%(default)r)") + help="set sample rate to RATE (%(default)r)") parser.add_argument("-N", "--samples", type=eng_float, required=True, - help="number of samples to record") + help="number of samples to record") parser.add_argument('file_name', metavar='WAV-FILE', - help='Output WAV file name', nargs=1) + help='Output WAV file name', nargs=1) args = parser.parse_args() sample_rate = int(args.sample_rate) @@ -48,6 +49,7 @@ class my_top_block(gr.top_block): self.connect(src0, head0, (dst, 0)) self.connect(src1, head1, (dst, 1)) + if __name__ == '__main__': try: my_top_block().run() diff --git a/gr-audio/examples/python/mono_tone.py b/gr-audio/examples/python/mono_tone.py index 411af92924..3feb495c54 100644 --- a/gr-audio/examples/python/mono_tone.py +++ b/gr-audio/examples/python/mono_tone.py @@ -20,9 +20,10 @@ except ImportError: sys.exit(1) #import os -#print os.getpid() +# print os.getpid() #raw_input('Attach gdb and press Enter: ') + class my_top_block(gr.top_block): def __init__(self): @@ -30,11 +31,11 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate to RATE %(default)r)") + help="set sample rate to RATE %(default)r)") parser.add_argument("-D", "--dont-block", action="store_false", default=True, - dest="ok_to_block") + dest="ok_to_block") args = parser.parse_args() sample_rate = int(args.sample_rate) @@ -46,7 +47,7 @@ class my_top_block(gr.top_block): args.audio_output, args.ok_to_block) - self.connect (src0, (dst, 0)) + self.connect(src0, (dst, 0)) if __name__ == '__main__': diff --git a/gr-audio/examples/python/multi_tone.py b/gr-audio/examples/python/multi_tone.py index 44800b69ff..608b9a75bc 100644 --- a/gr-audio/examples/python/multi_tone.py +++ b/gr-audio/examples/python/multi_tone.py @@ -20,9 +20,10 @@ except ImportError: sys.exit(1) #import os -#print os.getpid() +# print os.getpid() #raw_input('Attach gdb and press Enter: ') + class my_top_block(gr.top_block): def __init__(self): @@ -30,13 +31,13 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate to RATE (%(default)r)") - parser.add_argument ("-m", "--max-channels", type=int, default=16, - help="set maximum channels to use") + help="set sample rate to RATE (%(default)r)") + parser.add_argument("-m", "--max-channels", type=int, default=16, + help="set maximum channels to use") parser.add_argument("-D", "--dont-block", action="store_false", - dest="ok_to_block") + dest="ok_to_block") args = parser.parse_args() sample_rate = int(args.sample_rate) limit_channels = args.max_channels @@ -46,12 +47,12 @@ class my_top_block(gr.top_block): # With a tip of the hat to Harry Partch, may he R.I.P. # See "Genesis of a Music". He was into some very wild tunings... base = 392 - ratios = { 1 : 1.0, - 3 : 3.0 / 2, - 5 : 5.0 / 4, - 7 : 7.0 / 4, - 9 : 9.0 / 8, - 11 : 11.0 / 8 } + ratios = {1: 1.0, + 3: 3.0 / 2, + 5: 5.0 / 4, + 7: 7.0 / 4, + 9: 9.0 / 8, + 11: 11.0 / 8} # progression = (1, 5, 3, 7) # progression = (1, 9, 3, 7) @@ -68,11 +69,13 @@ class my_top_block(gr.top_block): max_chan = limit_channels for i in range(max_chan): - quo, rem = divmod(i, len (progression)) + quo, rem = divmod(i, len(progression)) freq = base * ratios[progression[rem]] * (quo + 1) - src = analog.sig_source_f(sample_rate, analog.GR_SIN_WAVE, freq, ampl) + src = analog.sig_source_f( + sample_rate, analog.GR_SIN_WAVE, freq, ampl) self.connect(src, (dst, i)) + if __name__ == '__main__': try: my_top_block().run() diff --git a/gr-audio/examples/python/noise.py b/gr-audio/examples/python/noise.py index 7c8e29cdde..45f41d78b3 100644 --- a/gr-audio/examples/python/noise.py +++ b/gr-audio/examples/python/noise.py @@ -14,6 +14,7 @@ from gnuradio import digital from gnuradio.eng_arg import eng_float from argparse import ArgumentParser + class my_top_block(gr.top_block): def __init__(self): @@ -21,9 +22,9 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=48000, - help="set sample rate to RATE (48000)") + help="set sample rate to RATE (48000)") args = parser.parse_args() sample_rate = int(args.sample_rate) ampl = 0.1 @@ -33,6 +34,7 @@ class my_top_block(gr.top_block): dst = audio.sink(sample_rate, args.audio_output) self.connect(src, b2f, dst) + if __name__ == '__main__': try: my_top_block().run() diff --git a/gr-audio/examples/python/spectrum_inversion.py b/gr-audio/examples/python/spectrum_inversion.py index d9b7a2d008..8b293b9ce0 100644 --- a/gr-audio/examples/python/spectrum_inversion.py +++ b/gr-audio/examples/python/spectrum_inversion.py @@ -20,6 +20,7 @@ from gnuradio import blocks from gnuradio.eng_arg import eng_float, intx from argparse import ArgumentParser + class my_top_block(gr.top_block): def __init__(self): @@ -27,15 +28,15 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-I", "--audio-input", default="", - help="pcm input device name. E.g., hw:0,0 or /dev/dsp") + help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-r", "--sample-rate", type=eng_float, default=8000, - help="set sample rate to RATE (%(default)r)") + help="set sample rate to RATE (%(default)r)") args = parser.parse_args() sample_rate = int(args.sample_rate) - src = audio.source (sample_rate, args.audio_input) - dst = audio.sink (sample_rate, args.audio_output) + src = audio.source(sample_rate, args.audio_input) + dst = audio.sink(sample_rate, args.audio_output) vec1 = [1, -1] vsource = blocks.vector_source_f(vec1, True) diff --git a/gr-audio/examples/python/test_resampler.py b/gr-audio/examples/python/test_resampler.py index e97836c61a..3da9b20e61 100644 --- a/gr-audio/examples/python/test_resampler.py +++ b/gr-audio/examples/python/test_resampler.py @@ -27,6 +27,7 @@ except ImportError: sys.stderr.write("Error: Program requires gr-blocks.\n") sys.exit(1) + class my_top_block(gr.top_block): def __init__(self): @@ -34,11 +35,11 @@ class my_top_block(gr.top_block): parser = ArgumentParser() parser.add_argument("-O", "--audio-output", default="", - help="pcm output device name. E.g., hw:0,0 or /dev/dsp") + help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_argument("-i", "--input-rate", type=eng_float, default=8000, - help="set input sample rate to RATE %(default)r") + help="set input sample rate to RATE %(default)r") parser.add_argument("-o", "--output-rate", type=eng_float, default=48000, - help="set output sample rate to RATE %(default)r") + help="set output sample rate to RATE %(default)r") args = parser.parse_args() input_rate = int(args.input_rate) output_rate = int(args.output_rate) @@ -55,6 +56,7 @@ class my_top_block(gr.top_block): dst = audio.sink(output_rate, args.audio_output) self.connect(src0, rr, (dst, 0)) + if __name__ == '__main__': try: my_top_block().run() |