diff options
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 = [] |