mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
many optimizations and bug fixes
This commit is contained in:
@@ -44,7 +44,7 @@ ffi.cdef("""
|
||||
|
||||
// Device management
|
||||
void list_host_apis(void);
|
||||
void init_audio_device(PaHostApiIndex host_api, double sample_rate);
|
||||
void init_audio_device(PaHostApiIndex host_api, double sample_rate, unsigned long buffer_size);
|
||||
void close_audio_device(void);
|
||||
bool is_audio_device_ready(void);
|
||||
void set_master_volume(float volume);
|
||||
@@ -128,11 +128,12 @@ except OSError as e:
|
||||
raise
|
||||
|
||||
class AudioEngine:
|
||||
def __init__(self, device_type: int, sample_rate: float):
|
||||
def __init__(self, device_type: int, sample_rate: float, buffer_size: int):
|
||||
self.device_type = device_type
|
||||
if sample_rate == -1:
|
||||
sample_rate = 44100
|
||||
self.target_sample_rate = sample_rate
|
||||
self.buffer_size = buffer_size
|
||||
self.sounds = {} # sound_id -> sound struct
|
||||
self.music_streams = {} # music_id -> music struct
|
||||
self.sound_counter = 0
|
||||
@@ -145,7 +146,7 @@ class AudioEngine:
|
||||
def init_audio_device(self) -> bool:
|
||||
"""Initialize the audio device"""
|
||||
try:
|
||||
lib.init_audio_device(self.device_type, self.target_sample_rate) # type: ignore
|
||||
lib.init_audio_device(self.device_type, self.target_sample_rate, self.buffer_size) # type: ignore
|
||||
self.audio_device_ready = lib.is_audio_device_ready() # type: ignore
|
||||
if self.audio_device_ready:
|
||||
print("Audio device initialized successfully")
|
||||
@@ -361,5 +362,5 @@ class AudioEngine:
|
||||
return 0.0
|
||||
|
||||
# Create the global audio instance
|
||||
audio = AudioEngine(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"])
|
||||
audio = AudioEngine(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"], get_config()["audio"]["buffer_size"])
|
||||
audio.set_master_volume(0.75)
|
||||
|
||||
Reference in New Issue
Block a user