mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
audio volumes are now changable
This commit is contained in:
@@ -126,7 +126,7 @@ except OSError as e:
|
||||
raise
|
||||
|
||||
class AudioEngine:
|
||||
def __init__(self, device_type: int, sample_rate: float, buffer_size: int):
|
||||
def __init__(self, device_type: int, sample_rate: float, buffer_size: int, volume_presets: dict[str, float]):
|
||||
self.device_type = device_type
|
||||
if sample_rate == -1:
|
||||
sample_rate = 44100
|
||||
@@ -135,6 +135,7 @@ class AudioEngine:
|
||||
self.sounds = {}
|
||||
self.music_streams = {}
|
||||
self.audio_device_ready = False
|
||||
self.volume_presets = volume_presets
|
||||
|
||||
self.sounds_path = Path("Sounds")
|
||||
|
||||
@@ -236,14 +237,20 @@ class AudioEngine:
|
||||
for name in list(self.sounds.keys()):
|
||||
self.unload_sound(name)
|
||||
|
||||
def play_sound(self, name: str) -> None:
|
||||
def play_sound(self, name: str, volume_preset: str) -> None:
|
||||
"""Play a sound"""
|
||||
if name == 'don':
|
||||
if volume_preset:
|
||||
lib.set_sound_volume(self.don, self.volume_presets[volume_preset]) # type: ignore
|
||||
lib.play_sound(self.don) # type: ignore
|
||||
elif name == 'kat':
|
||||
if volume_preset:
|
||||
lib.set_sound_volume(self.kat, self.volume_presets[volume_preset]) # type: ignore
|
||||
lib.play_sound(self.kat) # type: ignore
|
||||
elif name in self.sounds:
|
||||
sound = self.sounds[name]
|
||||
if volume_preset:
|
||||
lib.set_sound_volume(sound, self.volume_presets[volume_preset]) # type: ignore
|
||||
lib.play_sound(sound) # type: ignore
|
||||
else:
|
||||
print(f"Sound {name} not found")
|
||||
@@ -297,11 +304,13 @@ class AudioEngine:
|
||||
print(f"Failed to load music: {file_path}")
|
||||
return ""
|
||||
|
||||
def play_music_stream(self, name: str) -> None:
|
||||
def play_music_stream(self, name: str, volume_preset: str = '') -> None:
|
||||
"""Play a music stream"""
|
||||
if name in self.music_streams:
|
||||
music = self.music_streams[name]
|
||||
lib.seek_music_stream(music, 0) # type: ignore
|
||||
if volume_preset:
|
||||
lib.set_music_volume(music, self.volume_presets[volume_preset]) # type: ignore
|
||||
lib.play_music_stream(music) # type: ignore
|
||||
else:
|
||||
print(f"Music stream {name} not found")
|
||||
@@ -380,5 +389,5 @@ class AudioEngine:
|
||||
print(f"Music stream {name} not found")
|
||||
|
||||
# Create the global audio instance
|
||||
audio = AudioEngine(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"], get_config()["audio"]["buffer_size"])
|
||||
audio = AudioEngine(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"], get_config()["audio"]["buffer_size"], get_config()["volume"])
|
||||
audio.set_master_volume(0.75)
|
||||
|
||||
@@ -137,16 +137,16 @@ class Timer:
|
||||
self.last_time = current_time_ms
|
||||
self.counter = str(self.time)
|
||||
if self.time < 10:
|
||||
audio.play_sound('timer_blip')
|
||||
audio.play_sound('timer_blip', 'sound')
|
||||
self.num_resize.start()
|
||||
self.highlight_fade.start()
|
||||
self.highlight_resize.start()
|
||||
if self.time == 10:
|
||||
audio.play_sound('voice_timer_10')
|
||||
audio.play_sound('voice_timer_10', 'voice')
|
||||
elif self.time == 5:
|
||||
audio.play_sound('voice_timer_5')
|
||||
audio.play_sound('voice_timer_5', 'voice')
|
||||
elif self.time == 0:
|
||||
audio.play_sound('voice_timer_0')
|
||||
audio.play_sound('voice_timer_0', 'voice')
|
||||
def draw(self, x: int = 0, y: int = 0):
|
||||
tex = global_tex
|
||||
if self.time < 10:
|
||||
|
||||
@@ -33,7 +33,7 @@ class VideoPlayer:
|
||||
if self.is_finished_list[1]:
|
||||
return
|
||||
if not self.audio_played:
|
||||
audio.play_music_stream(self.audio)
|
||||
audio.play_music_stream(self.audio, 'music')
|
||||
self.audio_played = True
|
||||
audio.update_music_stream(self.audio)
|
||||
self.is_finished_list[1] = audio.get_music_time_length(self.audio) <= audio.get_music_time_played(self.audio)
|
||||
|
||||
Reference in New Issue
Block a user