-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.py
41 lines (32 loc) · 915 Bytes
/
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
import os
import random
def get_os_type():
return os.name
def clear_cmd_terminal(os_name):
if os_name == "nt":
os.system("cls")
else:
os.system("clear")
os_name = get_os_type()
from pygame import mixer
clear_cmd_terminal(os_name) # __|__
def init_sound():
mixer.init()
def play_sfx(track, loops=0, channel=1, volume=1):
chn = mixer.Channel(channel)
track_full = "data/sfx/" + str(track) + ".wav"
snd = mixer.Sound(track_full)
chn.set_volume(volume)
chn.play(snd, loops)
def get_channel_busy(channel):
chn = mixer.Channel(channel)
return chn.get_busy()
def set_channel_volume(channel, volume):
channel = mixer.Channel(channel)
channel.set_volume(volume)
def stop_channel(channel):
channel = mixer.Channel(channel)
channel.stop()
def fade_out_channel(channel_num):
channel = mixer.Channel(channel_num)
channel.fadeout(2000)