This commit is contained in:
Jakob 2019-08-20 12:11:41 +02:00
commit 3a3ccb13c8
11 changed files with 73 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.wav

72
campatmo.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python3
import time
import sys
import random
from glob import glob
from pygame import mixer
tracks_per_type = 2
single_track_types = ["lines"]
def load_files():
files = glob("samples/*.wav")
type_names = glob("samples/*/")
type_files = {c.split("/")[1]: glob(c + "/*.wav") for c in type_names}
return type_files
def main():
type_files = load_files()
mixer.init(frequency=22050 * 2)
types = {}
i = 0
mixer.set_num_channels(
sum(
[
1 if name in single_track_types else tracks_per_type
for name in type_files
]
)
)
print(f"{mixer.get_num_channels()} channels set")
for name in type_files:
types[name] = []
for k in range(1 if name in single_track_types else tracks_per_type):
types[name].append(mixer.Channel(i))
i += 1
sounds = {}
for name, files in type_files.items():
sounds[name] = []
for f in files:
sounds[name].append(mixer.Sound(f))
random.shuffle(sounds[name])
try:
while True:
for name, type_ in types.items():
if len(sounds[name]) == 0:
continue
try:
next_sound_index = max(
[sounds[name].index(tt.get_queue() or tt.get_sound()) for tt in type_]
)
except ValueError:
next_sound_index = 0
if next_sound_index >= len(sounds[name]):
random.shuffle(sounds[name])
next_sound_index = 0
for c in type_:
if c.get_queue() is not None and len(sounds[name]) > 1:
continue
c.queue(sounds[name][next_sound_index])
if c.get_queue() is None and len(sounds[name]) > 1:
c.queue(sounds[name][next_sound_index + 1])
time.sleep(1)
except KeyboardInterrupt:
print("exit")
sys.exit(0)
if __name__ == "__main__":
main()

View File

BIN
samples/background/1.mp3 Normal file

Binary file not shown.

BIN
samples/background/1.wav Normal file

Binary file not shown.

BIN
samples/background/2.mp3 Normal file

Binary file not shown.

BIN
samples/background/2.wav Normal file

Binary file not shown.

View File

0
samples/laughter/.exists Normal file
View File

0
samples/lines/.exists Normal file
View File

0
samples/other/.exists Normal file
View File