aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src/solo_tool/metronome.py
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/src/solo_tool/metronome.py')
-rw-r--r--solo-tool-project/src/solo_tool/metronome.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/solo-tool-project/src/solo_tool/metronome.py b/solo-tool-project/src/solo_tool/metronome.py
index 9c65357..3ffc6bc 100644
--- a/solo-tool-project/src/solo_tool/metronome.py
+++ b/solo-tool-project/src/solo_tool/metronome.py
@@ -1,6 +1,8 @@
import pyaudio as pa
from array import array
+from solo_tool.utils import getAudioDeviceIndex
+
def _createClickSample(clickFrequency: int, samplingRate: int) -> array:
clickDuration = 0.03 # seconds
@@ -22,9 +24,10 @@ def _createOutputBuffer(bpm: int, clickFrequency: int, samplingRate: int) -> arr
return clickSample + array('h', [0] * (samplesPerBeat - len(clickSample)))
class Metronome:
- def __init__(self, bufferSize: int, samplingRate: int):
+ def __init__(self, bufferSize: int, samplingRate: int, deviceName: str):
self._bufferSize = bufferSize
self._samplingRate = samplingRate
+ self._deviceName = deviceName
self._sampleFormat = pa.paInt16
self._channels = 1
self._pa = pa.PyAudio()
@@ -58,6 +61,7 @@ class Metronome:
rate=self._samplingRate,
frames_per_buffer=self._bufferSize,
output=True,
+ output_device_index=getAudioDeviceIndex(self._deviceName, self._pa),
stream_callback=self._callback)
def stop(self) -> None: