-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathsound.py
53 lines (40 loc) · 1.47 KB
/
sound.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Helper classes and functions needed to globally enable/disable sound"""
import pygame
from pygame.mixer import Sound as OldSound
import config
# Cannot use inheritance or decorator because pygame.mixer.Sound is a C-extension.
class Sound:
"""Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally
Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent.
"""
def __init__(self, source):
if config.SOUND:
self.sound = OldSound(source)
def play(self, loops=0, maxtime=0, fade_ms=0):
if config.SOUND:
self.sound.play(loops, maxtime, fade_ms)
def stop(self):
if config.SOUND:
self.sound.stop()
def fadeout(self, time):
if config.SOUND:
self.sound.fadeout(time)
def set_volume(self, value):
if config.SOUND:
self.sound.set_volume(value)
def get_volume(self):
if config.SOUND:
return self.sound.get_volume()
def get_num_channels(self):
if config.SOUND:
return self.sound.get_num_channels()
def get_length(self):
if config.SOUND:
return self.get_length()
def get_raw(self):
if config.SOUND:
return self.sound.get_raw()
def init(audio_params):
"""Use this instead of ``pygame.mixer.init``"""
if config.SOUND:
pygame.mixer.init(audio_params[0], audio_params[1], audio_params[2], audio_params[3])