aboutsummaryrefslogtreecommitdiff
path: root/helpers/mixer.py
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/mixer.py')
-rw-r--r--helpers/mixer.py27
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
2import audioop 2import audioop
3import time 3import time
4 4
5frame_rate = 44100 5from . import Config
6channels = 2 6
7sample_width = 2 7sample_width = Config.sample_width
8def 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
14def _latency(latency):
15 if latency == "high" or latency == "low":
16 return latency
17 else:
18 return float(latency)
8 19
9class Mixer: 20class 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 = []