diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-20 21:39:07 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-20 21:39:07 +0300 |
commit | b9b64aa313a45ab53f856242b4ce5ddb151533fb (patch) | |
tree | 43bd21e0a3381af5524ad2045d09c8c603610eb6 /src/sliceitoff/sfx/sfx.py | |
parent | 72f91db6e553b797dd879c4ed40360bfd54fd923 (diff) |
sfx subpackage
Diffstat (limited to 'src/sliceitoff/sfx/sfx.py')
-rw-r--r-- | src/sliceitoff/sfx/sfx.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/sliceitoff/sfx/sfx.py b/src/sliceitoff/sfx/sfx.py new file mode 100644 index 0000000..f9347df --- /dev/null +++ b/src/sliceitoff/sfx/sfx.py @@ -0,0 +1,28 @@ +""" sfx.sfx - pygame.mixer initialization and sound effects handling """ +import pygame + +class Sfx: + """ Sound Effects and Music? """ + def __init__(self): + self.initialized = False + try: + pygame.mixer.pre_init(channels=2, buffer=512, frequency=48000) + except pygame.error: + pass + + def init(self, base_path): + """ To be called after pygame is initialized. Actual mixer init and + sample loading happens here """ + try: + pygame.mixer.init() + self.initialized = True + except pygame.error: + pass + +# Initialize only one time +try: + # pylint: disable = used-before-assignment + # This is intented behaviour + sfx +except NameError: + sfx = Sfx() |