Commit e72d50ef authored by Federico Meloda's avatar Federico Meloda

updated sound.py with .ogg and minor bugfixes

parent 1d2370e5
#!/usr/bin/env python3
import pygame as pg
import time
from threading import Timer
import zmq
import sys
pg.init(44100, size=-16, channels=1, buffer=4096)
pg.mixer.init()
pg.mixer.set_num_channels(3)
#carico i file audio
lancio = pg.mixer.Sound('sounds/lancio.ogg')
stageOne = pg.mixer.Sound('sounds/stageOne.ogg')
stageTwo = pg.mixer.Sound('sounds/stageTwo.ogg')
#tempo di fine suono dopo secondo modulo
t = Timer(30.0, endMission)
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
while True:
string = socket.recv()
topic, messagedata = string.split()
if messagedata == "pre_launch":
pg.mixer.Channel(0).play(lancio)
elif messagedata == "stage_1_separation":
pg.mixer.Channel(1).play(stageOne)
elif messagedata == "stage_2_separation":
pg.mixer.Channel(2).play(stageTwo)
t.start()
else:
print("Unhandled message")
print(topic, messagedata)
while pg.mixer.get_busy() :
pg.time.delay(10)
#fade out
def endMission():
pg.mixer.Channel(0).fadeout(5)
pass
......@@ -19,14 +19,14 @@ def main():
port = config['port']
host = config['host']
pg.init(44100, size=-16, channels=1, buffer=4096)
pg.mixer.init()
pg.init(44100, size=-16, channels=2, buffer=4096)
pg.mixer.set_num_channels(3) # default is 8
pg.mixer.set_num_channels(3)
# carico i file audio
lancio = pg.mixer.Sound('sounds/lancio.wav')
stageOne = pg.mixer.Sound('sounds/stageOne.wav')
stageTwo = pg.mixer.Sound('sounds/stageTwo.wav')
lancio = pg.mixer.Sound('sounds/lancio.ogg')
stageOne = pg.mixer.Sound('sounds/stageOne.ogg')
stageTwo = pg.mixer.Sound('sounds/stageTwo.ogg')
# tempo di fine suono dopo secondo modulo
t = Timer(30.0, endMission)
......@@ -56,7 +56,8 @@ def main():
print("Unhandled message")
print(topic, messagedata)
while pg.mixer.get_busy() :
pg.time.delay(10)
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment