Ejemplo n.º 1
0
    def __init__(self, num_channels, listen_func = None, input_func = None):
        super(Audio, self).__init__()

        assert(num_channels == 1 or num_channels == 2)
        self.num_channels = num_channels
        self.listen_func = listen_func
        self.input_func = input_func
        self.audio = pyaudio.PyAudio()

        out_dev, in_dev, buffer_size, sr = self._get_parameters()
        Audio.sample_rate = sr

        # create stream
        self.stream = self.audio.open(format = pyaudio.paFloat32,
                                      channels = num_channels,
                                      frames_per_buffer = buffer_size,
                                      rate = Audio.sample_rate,
                                      output = True,
                                      input = input_func != None,
                                      output_device_index = out_dev,
                                      input_device_index = in_dev)

        self.generator = None
        self.cpu_time = 0
        core.register_terminate_func(self.close)
Ejemplo n.º 2
0
    def __init__(self, num_channels, listen_func=None, input_func=None):
        super(Audio, self).__init__()

        assert (num_channels == 1 or num_channels == 2)
        self.num_channels = num_channels
        self.listen_func = listen_func
        self.input_func = input_func
        self.audio = pyaudio.PyAudio()

        # on windows, if '-asio' found in command-line-args, use ASIO drivers
        if '-asio' in sys.argv:
            Audio.out_dev, Audio.in_dev = self._find_asio_devices()

        print('using audio params:')
        print(
            '  samplerate: {}\n  buffersize: {}\n  outputdevice: {}\n  inputdevice: {}'
            .format(Audio.sample_rate, Audio.buffer_size, Audio.out_dev,
                    Audio.in_dev))

        # create stream
        self.stream = self.audio.open(format=pyaudio.paFloat32,
                                      channels=num_channels,
                                      frames_per_buffer=Audio.buffer_size,
                                      rate=Audio.sample_rate,
                                      output=True,
                                      input=input_func != None,
                                      output_device_index=Audio.out_dev,
                                      input_device_index=Audio.in_dev)

        self.generator = None
        self.cpu_time = 0
        core.register_terminate_func(self.close)
Ejemplo n.º 3
0
    def __init__(
        self, num_channels, listen_func=None, input_func=None, num_input_channels=1
    ):
        super(Audio, self).__init__()

        assert num_channels == 1 or num_channels == 2
        self.num_channels = num_channels
        self.listen_func = listen_func
        self.input_func = input_func
        self.audio = pyaudio.PyAudio()

        self.num_input_channels = num_input_channels

        # on windows, if '-asio' found in command-line-args, use ASIO drivers
        if "-asio" in sys.argv:
            Audio.out_dev, Audio.in_dev = self._find_asio_devices()

        # print("using audio params:")
        # print(
        #     f"  samplerate: {Audio.sample_rate}\n"
        #     + f"  buffersize: {Audio.buffer_size}\n"
        #     + f"  outputdevice: {Audio.out_dev}\n"
        #     + f"  inputdevice: {Audio.in_dev}"
        # )
        print("Creating audio object")

        # create output stream
        self.stream = self.audio.open(
            format=pyaudio.paFloat32,
            channels=num_channels,
            frames_per_buffer=Audio.buffer_size,
            rate=Audio.sample_rate,
            output=True,
            input=False,
            output_device_index=Audio.out_dev,
        )

        # create input stream
        self.input_stream = None
        if input_func:
            self.input_stream = self.audio.open(
                format=pyaudio.paFloat32,
                channels=self.num_input_channels,
                frames_per_buffer=Audio.buffer_size,
                rate=Audio.sample_rate,
                output=False,
                input=True,
                input_device_index=Audio.in_dev,
            )

        self.generator = None
        self.cpu_time = 0
        core.register_terminate_func(self.close)
Ejemplo n.º 4
0
    def __init__(self, remote_ip=None, pos_type=kBody):
        super(Kinect, self).__init__()

        self.pos_type = pos_type

        # Synapse is running on a remote machine:
        if remote_ip:
            listen_ip = socket.gethostbyname(socket.gethostname())
            listen_port = 12345

            send_ip = remote_ip
            send_port = 12321

        # Synapse is running locally on this machine, using localhost
        else:
            listen_ip = 'localhost'
            listen_port = 12345

            send_ip = 'localhost'
            send_port = 12346

        # create a dispatcher and server, which handles incoming messages from Synapse
        self.dispatcher = dispatcher.Dispatcher()
        self.dispatcher.map('/tracking_skeleton',
                            self.callback_tracking_skeleton)
        self.server = osc_server.ThreadingOSCUDPServer(
            (listen_ip, listen_port), self.dispatcher)

        # create the client, which sends control messages to Synapse
        self.client = udp_client.SimpleUDPClient(send_ip, send_port)

        # member vars
        self.active_joints = {}
        self.last_heartbeat_time = 0

        # start the server listening for messages
        self.start()

        core.register_terminate_func(self.close)
Ejemplo n.º 5
0
from common.writer import AudioWriter
from kivy.core.image import Image
from kivy.core.window import Window
from kivy.graphics import Color, Ellipse, Rectangle, Line
from kivy.graphics.instructions import InstructionGroup
from kivy.uix.button import Button

from modules.bubble import PhysicsBubble, PhysicsBubbleHandler
from modules.block import SoundBlock, SoundBlockHandler
from modules.cursor import TempoCursor, TempoCursorHandler

server_url = 'http://interval-app.herokuapp.com/'

client = socketio.Client()
client.connect(server_url)
register_terminate_func(client.disconnect)

# each client gets a unique client id upon connecting. we use this client id in many
# functions, especially module handler functions, to make sure all users are synced.
client_id = client.sid


class Normalizer(object):
    def __init__(self, mode):
        self.mode = mode  # either 'mac' or 'pc'

    def nt(self, tup):
        return (tup[0] / 2, tup[1] / 2) if self.mode == 'pc' else tup

    def nv(self, val):
        return val / 2 if self.mode == 'pc' else val