New version

This commit is contained in:
Fabio Manganiello 2020-06-11 12:06:12 +02:00
parent 1ab65ddb7f
commit 2e3cc58948
3 changed files with 25 additions and 22 deletions

View file

@ -17,34 +17,36 @@ def parse_args(args):
formatter_class=argparse.RawTextHelpFormatter) formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--list-audio-outputs', '-l', dest='list_audio_outputs', required=False, parser.add_argument('--list-audio-outputs', '-l', dest='list_audio_outputs', required=False,
action='store_true', help='List the available audio output devices') action='store_true', help='List the available audio output devices')
parser.add_argument('--list-leap-motions', '-L', dest='list_leap_motions', required=False, parser.add_argument('--list-leap-motions', '-L', dest='list_leap_motions', required=False,
action='store_true', help='List the available Leap Motion devices') action='store_true', help='List the available Leap Motion devices')
parser.add_argument('--audio-output', '-o', dest='audio_output', required=False, parser.add_argument('--audio-output', '-o', dest='audio_output', required=False,
type=int, help='Select an output audio device by index (see -l)') type=int, help='Select an output audio device by index (see -l)')
parser.add_argument('--audio-backend', '-b', dest='audio_backend', required=False, default='portaudio', parser.add_argument('--audio-backend', '-b', dest='audio_backend', required=False, default='portaudio',
help='Select the audio backend (default: portaudio). Supported: ' + help='Select the audio backend (default: portaudio). Supported: ' +
'{"portaudio", "jack", "coreaudio"}') '{"portaudio", "jack", "coreaudio"}')
parser.add_argument('--channels', '-c', dest='channels', required=False, type=int, default=2, parser.add_argument('--channels', '-c', dest='channels', required=False, type=int, default=2,
help='Number of audio channels (default: 2)') help='Number of audio channels (default: 2)')
parser.add_argument('--rate', '-r', dest='sampling_rate', required=False, type=int, default=44100,
help='Sampling rate (default: 44100 Hz)')
parser.add_argument('--discrete', '-d', dest='discrete', required=False, action='store_true', parser.add_argument('--discrete', '-d', dest='discrete', required=False, action='store_true',
help='If set then discrete notes will be generated instead of samples over a continuous ' + help='If set then discrete notes will be generated instead of samples over a continuous ' +
'frequency space (default: false)') 'frequency space (default: false)')
parser.add_argument('--left-handed', dest='left_handed', required=False, action='store_true', parser.add_argument('--left-handed', dest='left_handed', required=False, action='store_true',
help='If set then the pitch control will be on the left hand and the volume control on the' + help='If set then the pitch control will be on the left hand and the volume control on the' +
'right hand. Otherwise, the controls are inverted (default: false)') 'right hand. Otherwise, the controls are inverted (default: false)')
parser.add_argument('--generator', '-g', dest='generator', required=False, parser.add_argument('--generator', '-g', dest='generator', required=False,
default='SineLoop', help='Wave generator to be used. See ' + default='SineLoop', help='Wave generator to be used. See ' +
'http://ajaxsoundstudio.com/pyodoc/api/classes/generators.html. ' + 'http://ajaxsoundstudio.com/pyodoc/api/classes/generators.html. ' +
'Default: SineLoop') 'Default: SineLoop')
parser.add_argument('--min-frequency', dest='min_frequency', required=False, type=int, default=55, parser.add_argument('--min-frequency', dest='min_frequency', required=False, type=int, default=55,
help='Minimum audio frequency (default: 55 Hz)') help='Minimum audio frequency (default: 55 Hz)')
parser.add_argument('--max-frequency', dest='max_frequency', required=False, type=int, default=10000, parser.add_argument('--max-frequency', dest='max_frequency', required=False, type=int, default=10000,
help='Maximum audio frequency (default: 10 kHz)') help='Maximum audio frequency (default: 10 kHz)')
parser.add_argument('--min-note', dest='min_note', required=False, type=str, default=None, parser.add_argument('--min-note', dest='min_note', required=False, type=str, default=None,
help='Minimum MIDI note, as a string (e.g. A4)') help='Minimum MIDI note, as a string (e.g. A4)')
parser.add_argument('--max-note', dest='max_note', required=False, type=str, default=None, parser.add_argument('--max-note', dest='max_note', required=False, type=str, default=None,
help='Maximum MIDI note, as a string (e.g. A4)') help='Maximum MIDI note, as a string (e.g. A4)')
opts, args = parser.parse_known_args(args) opts, args = parser.parse_known_args(args)
return opts, args return opts, args
@ -71,4 +73,4 @@ def main(args=None):
theremin(wave=opts.generator, audio_backend=opts.audio_backend, discrete=opts.discrete, theremin(wave=opts.generator, audio_backend=opts.audio_backend, discrete=opts.discrete,
min_frequency=opts.min_frequency, max_frequency=opts.max_frequency, left_handed=opts.left_handed, min_frequency=opts.min_frequency, max_frequency=opts.max_frequency, left_handed=opts.left_handed,
audio_output=opts.audio_output, channels=opts.channels) audio_output=opts.audio_output, channels=opts.channels, sampling_rate=opts.sampling_rate)

View file

@ -26,10 +26,11 @@ class Track:
class SoundProcessor: class SoundProcessor:
def __init__(self, backend='portaudio', output=None, channels=2, discrete=False): def __init__(self, sampling_rate=44100, backend='portaudio', output=None, channels=2, discrete=False):
self.backend = backend self.backend = backend
self.discrete = discrete self.discrete = discrete
self.server = Server(audio=self.backend, jackname='theremin', winhost='theremin', nchnls=channels) self.sampling_rate = sampling_rate
self.server = Server(audio=self.backend, sr=sampling_rate, jackname='theremin', winhost='theremin', nchnls=channels)
self.audio_output = output or pa_get_default_output() self.audio_output = output or pa_get_default_output()
self.server.setOutputDevice(self.audio_output) self.server.setOutputDevice(self.audio_output)
self.tracks = [] self.tracks = []

View file

@ -6,8 +6,8 @@ from .sound import SoundProcessor
def theremin(wave='SineLoop', audio_output=None, audio_backend='portaudio', channels=2, min_frequency=55, def theremin(wave='SineLoop', audio_output=None, audio_backend='portaudio', channels=2, min_frequency=55,
max_frequency=10000, discrete=False, left_handed=False): max_frequency=10000, sampling_rate=44100, discrete=False, left_handed=False):
dsp = SoundProcessor(output=audio_output, backend=audio_backend, channels=channels, discrete=discrete) dsp = SoundProcessor(output=audio_output, backend=audio_backend, channels=channels, sampling_rate=sampling_rate, discrete=discrete)
dsp.start() dsp.start()
assert hasattr(pyo, wave) assert hasattr(pyo, wave)