X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Fmixer.py;h=d08520a00cf7c3197ff63e37ec2c68d503addf58;hb=75d6cdbac628b57e206cd37808c1d3c7fecbb9eb;hp=9e8179a9a3989c692b3e97d7da1783a57c748e94;hpb=22514f3ae6d4e19537ae5ab6bdb5bc9f99a64f47;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/helpers/mixer.py b/helpers/mixer.py index 9e8179a..d08520a 100644 --- a/helpers/mixer.py +++ b/helpers/mixer.py @@ -2,17 +2,28 @@ import sounddevice as sd import audioop import time -frame_rate = 44100 -channels = 2 -sample_width = 2 +from . import Config + +sample_width = Config.sample_width +def sample_width_to_dtype(sample_width): + if sample_width == 1 or sample_width == 2 or sample_width == 4: + return 'int' + str(8*sample_width) + else: + raise "Unknown sample width" + +def _latency(latency): + if latency == "high" or latency == "low": + return latency + else: + return float(latency) class Mixer: def __init__(self): - self.stream = sd.RawOutputStream(samplerate=frame_rate, - channels=channels, - dtype='int' + str(8*sample_width), # FIXME: ? - latency="high", - blocksize=5000, + self.stream = sd.RawOutputStream(samplerate=Config.frame_rate, + channels=Config.channels, + dtype=sample_width_to_dtype(Config.sample_width), + latency=_latency(Config.latency), + blocksize=Config.blocksize, callback=self.play_callback, ) self.open_files = []