diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-17 13:00:29 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-17 13:56:27 +0200 |
commit | 75d6cdbac628b57e206cd37808c1d3c7fecbb9eb (patch) | |
tree | 2b3633489452cf0a4528fd552bf19f83943a702a /helpers/mixer.py | |
parent | 22514f3ae6d4e19537ae5ab6bdb5bc9f99a64f47 (diff) | |
download | MusicSampler-75d6cdbac628b57e206cd37808c1d3c7fecbb9eb.tar.gz MusicSampler-75d6cdbac628b57e206cd37808c1d3c7fecbb9eb.tar.zst MusicSampler-75d6cdbac628b57e206cd37808c1d3c7fecbb9eb.zip |
Add new configurations parameters
Diffstat (limited to 'helpers/mixer.py')
-rw-r--r-- | helpers/mixer.py | 27 |
1 files changed, 19 insertions, 8 deletions
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 | |||
2 | import audioop | 2 | import audioop |
3 | import time | 3 | import time |
4 | 4 | ||
5 | frame_rate = 44100 | 5 | from . import Config |
6 | channels = 2 | 6 | |
7 | sample_width = 2 | 7 | sample_width = Config.sample_width |
8 | def sample_width_to_dtype(sample_width): | ||
9 | if sample_width == 1 or sample_width == 2 or sample_width == 4: | ||
10 | return 'int' + str(8*sample_width) | ||
11 | else: | ||
12 | raise "Unknown sample width" | ||
13 | |||
14 | def _latency(latency): | ||
15 | if latency == "high" or latency == "low": | ||
16 | return latency | ||
17 | else: | ||
18 | return float(latency) | ||
8 | 19 | ||
9 | class Mixer: | 20 | class Mixer: |
10 | def __init__(self): | 21 | def __init__(self): |
11 | self.stream = sd.RawOutputStream(samplerate=frame_rate, | 22 | self.stream = sd.RawOutputStream(samplerate=Config.frame_rate, |
12 | channels=channels, | 23 | channels=Config.channels, |
13 | dtype='int' + str(8*sample_width), # FIXME: ? | 24 | dtype=sample_width_to_dtype(Config.sample_width), |
14 | latency="high", | 25 | latency=_latency(Config.latency), |
15 | blocksize=5000, | 26 | blocksize=Config.blocksize, |
16 | callback=self.play_callback, | 27 | callback=self.play_callback, |
17 | ) | 28 | ) |
18 | self.open_files = [] | 29 | self.open_files = [] |