mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 19:50:12 +01:00
Update audio.py
This commit is contained in:
@@ -3,6 +3,7 @@ import queue
|
|||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Lock, Thread
|
from threading import Lock, Thread
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
@@ -241,6 +242,8 @@ class Music:
|
|||||||
|
|
||||||
# Thread safety
|
# Thread safety
|
||||||
self.lock = Lock()
|
self.lock = Lock()
|
||||||
|
self.buffer_executor = ThreadPoolExecutor(max_workers=1)
|
||||||
|
self.buffer_future = None
|
||||||
|
|
||||||
# Load audio
|
# Load audio
|
||||||
self._load_audio()
|
self._load_audio()
|
||||||
@@ -326,10 +329,14 @@ class Music:
|
|||||||
|
|
||||||
def _fill_buffer(self):
|
def _fill_buffer(self):
|
||||||
"""Fill the audio buffer from appropriate source"""
|
"""Fill the audio buffer from appropriate source"""
|
||||||
|
if self.buffer_future and not self.buffer_future.done():
|
||||||
|
return True
|
||||||
if self.uses_file_streaming:
|
if self.uses_file_streaming:
|
||||||
return self._fill_buffer_from_file()
|
self.buffer_future = self.buffer_executor.submit(self._fill_buffer_from_file)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return self._fill_buffer_from_memory()
|
self.buffer_future = self.buffer_executor.submit(self._fill_buffer_from_memory)
|
||||||
|
return True
|
||||||
|
|
||||||
def _fill_buffer_from_file(self):
|
def _fill_buffer_from_file(self):
|
||||||
"""Stream buffer from file"""
|
"""Stream buffer from file"""
|
||||||
|
|||||||
Reference in New Issue
Block a user