def TestPyJack(self): CHANNELS=len(self.jaoutlist.curselection()) self.fs = float(jack.get_sample_rate()) print(self.jaoutlist.curselection()) for i in range(0,len(self.jaoutlist.curselection())): print(self.jaoutlist.get(self.jaoutlist.curselection()[i])) jack.activate() for i in range(0,len(self.jaoutlist.curselection())): jack.register_port('output_'+str(i), jack.IsOutput) jack.connect('measure:output_'+str(i), self.jaoutlist.get(self.jaoutlist.curselection()[i])) # Dummy Input jack.register_port('dummy_input', jack.IsInput) print(jack.get_ports()) N = jack.get_buffer_size() input = np.zeros((1,len(self.signal)),'f') output = np.array(np.tile(self.signal,(CHANNELS,1)),'f') x = 0 while x < output.shape[1] - N: try: jack.process(output[:,x:x+N], input[:,x:x+N]) x += N except jack.InputSyncError: pass except jack.OutputSyncError: pass for i in range(0,len(self.jaoutlist.curselection())): jack.unregister_port('output_'+str(i)) jack.unregister_port('dummy_input') jack.deactivate()
def conectaSW(OnOff): for puerto in mapeoSW(): if OnOff.lower() == "off": jack.disconnect(puerto[0], puerto[1]) else: jack.connect(puerto[0], puerto[1])
def conect2ebumeter((L_ports,R_ports)): # normalmente habrĂ¡ una pareja de puertos L-R conectada a Brutefir for port in L_ports: jack.connect(port, 'ebumeter:in.L') time.sleep(.1) for port in R_ports: jack.connect(port, 'ebumeter:in.R') time.sleep(.1)
def route(source, destination): try: jack.connect(source, destination) except jack.NotConnectedError: jack.attach("studio-webapp") jack.connect(source, destination) return ''
def connect(self): try : jack.attach("sooperlooper") jack.activate() jack.connect("sooperlooper:common_out_1", "alsa_pcm:playback_1") jack.connect("sooperlooper:common_out_2", "alsa_pcm:playback_2") except : print("Run jack and sooperlooper") sys.exit(1)
def __init__(self, client, name, number): self.client = client self.name = name self.number = number self.port = "%s:%s%d" %(self.client, self.name, self.number) self.monitor_port = "monitor_%s_%s%d" % (self.client, self.name, self.number) jack.register_port(self.monitor_port, jack.IsInput) jack.connect(self.port, "%s:%s" % (jack.get_client_name(), self.monitor_port))
def Connect(self, playback_port, capture_port): """ Connects the given playback port to the given capture port. Use GetCapturePorts or GetInputs to get a list of possible capture ports. Use GetPlaybackPorts or GetOutputs to get a list of possible playback ports. @param playback_port: a string name of a playback port @param capture_port: a string name of a capture port """ jack.connect(playback_port, capture_port)
def open(self): self.client = jack.attach('PythonClient') myname = jack.get_client_name() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.register_port("out", jack.IsOutput) self.client.activate() print "Jack ports (before):", jack.get_ports() jack.connect("system:capture_1", myname+":in_1")
def track_playback_started(self, tl_track): print "Attaching to jack." jack.attach("default") print "Attached." print "Jack ports: %s", jack.get_ports() print "Track playback started. Time for some JACK magic." # Connect the specified JACK ports together. jack.connect("mopidy:out_jackaudiosink0_1","python:in_openob_tx_test-link_1") jack.connect("mopidy:out_jackaudiosink0_2","python:in_openob_tx_test-link_2")
def __init__(self, url): log.info("Opening JACK input") jack.attach("Noter Virtual Keyboard") self.rate = jack.get_sample_rate() jack.activate() jack.register_port("Input 1", jack.IsInput) jack.register_port("Input 2", jack.IsInput) jack.connect("system:capture_1", "Noter Virtual Keyboard:Input 1") jack.connect("system:capture_2", "Noter Virtual Keyboard:Input 2") self.buffer_size = jack.get_buffer_size() self.input = numpy.zeros((2, self.buffer_size), 'f') self.output = numpy.zeros((2, self.buffer_size), 'f')
def establish_connection(pcm, channel): myname = jack.get_client_name() capture_name = pcm + ":capture_" + channel port_name = "in_" + channel connection_name = myname + ":" + port_name print capture_name, port_name, connection_name print "Jack ports (before):", jack.get_ports() jack.register_port(port_name, jack.IsInput) jack.activate() print "Jack ports (after):", jack.get_ports() jack.connect(capture_name, connection_name) print jack.get_connections(connection_name)
def MesPyJack(self): OCHANNELS=len(self.jaoutlist.curselection()) ICHANNELS=len(self.jainplist.curselection()) print(self.jainplist.curselection()) self.fs = float(jack.get_sample_rate()) jack.activate() # Register and Connect Output Ports for i in range(0,OCHANNELS): jack.register_port('output_'+str(i), jack.IsOutput) jack.connect('measure:output_'+str(i), self.jaoutlist.get(self.jaoutlist.curselection()[i])) # Register and Connect Input Ports for i in range(0,ICHANNELS): jack.register_port('input_'+str(i), jack.IsInput) jack.connect(self.jainplist.get(self.jainplist.curselection()[i]), 'measure:input_'+str(i)) N = jack.get_buffer_size() input = np.zeros((ICHANNELS,len(self.signal)),'f') output = np.array(np.tile(self.signal,(OCHANNELS,1)),'f') x = 0 while x < output.shape[1] - N: try: jack.process(output[:,x:x+N], input[:,x:x+N]) x += N except jack.InputSyncError: pass except jack.OutputSyncError: pass for i in range(0,OCHANNELS): jack.unregister_port('output_'+str(i)) for i in range(0,ICHANNELS): jack.unregister_port('input_'+str(i)) jack.deactivate() if self.rawcheck.get(): #rawfile=self.get#self.filepath.get()+os.sep+self.prefix.get()+'_RAW_'+self.counter.get()+'_AVG_'+str(int(self.siavg.get())-self.cursiavg)+'.wav' rawfile=self.getRawFilename(int(int(self.siavg.get())-self.cursiavg))#self.filepath.get()+os.sep+self.prefix.get()+'_RAW_'+self.counter.get()+'_AVG_'+str(int(self.siavg)-self.cursiavg)+'.wav' toSave = np.array(input.transpose(),dtype=('float32')) scipy.io.wavfile.write(rawfile,int(self.fs), toSave) print(rawfile+' saved') self.cursiavg-=1 #if self.impcheck.get(): self.raw.append(input) print('PyJack: append to raw') if (self.cursiavg==0) and (self.impcheck.get()): self.generateIR()
def __init__(self): jack.attach("stream_grapher") jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.register_port("out_1", jack.IsOutput) jack.register_port("out_2", jack.IsOutput) jack.activate() try: jack.connect("system:capture_1", "stream_grapher:in_1") jack.connect("system:capture_2", "stream_grapher:in_2") jack.connect("stream_grapher:out_1", "system:playback_1") jack.connect("stream_grapher:out_2", "system:playback_2") except jack.UsageError: pass buff_size = jack.get_buffer_size() if buff_size < 1024: print >> sys.stderr, "Jack buffer size is %d. If you have sync problems try a buff size >= 1024." % (buff_size, ) self.buff_size = jack.get_buffer_size() sample_rate = jack.get_sample_rate() Backend.__init__(self, ports=2, sample_rate=sample_rate) self.capture = numpy.zeros((2, self.buff_size), 'f') self.output = numpy.zeros((2, self.buff_size), 'f') self.counter = [0] self.last_counter = 0 # Time to sleep between calls to jack.process # R should be at least 1.0 # To never get InputSyncErrors R should be like 2.0 or higher R = 1.2 self.sleep = self.buff_size / float(self.sample_rate) / R
def Jack(self): try: for i in xrange(10): selfPort = [port for port in jack.get_ports() if self.unique in port] if not selfPort: time.sleep(.01) else: break if not selfPort: raise jack.UsageError("Test port could not be registered", "Try increasing sleep time") allPorts = jack.get_ports() selfPort = [port for port in allPorts if self.unique in port][0] inPorts = [port for port in allPorts if 'playback' in port] for port in inPorts: jack.connect(selfPort, port) except Exception, e: self.statuses['Jack'] = e
def test_multiple_starts(): """Tests if the playback and the recording can be started multiple times""" _create_client() # skip this test if the JACK server is not running or the JACK client library is not available excitation = sumpf.SineWave(length=2 ** 15) xruns = _XRunHandler() jack = sumpf.Jack(input_signal=excitation, input_ports=["capture_1"]) jack.xruns.connect(xruns.xrun) jack.connect(0, 0) jack.start() response = jack.output() assert response.channels() == pytest.approx(excitation.channels()) jack.add_input_port("capture_2") jack.connect(0, 1) jack.start() response = jack.output() assert response[0].channels() == pytest.approx(excitation.channels()) assert response[1].channels() == pytest.approx(excitation.channels()) assert xruns.xruns == []
def test_multiple_starts(): """Tests if the playback and the recording can be started multiple times""" with _create_client( ): # skip this test if the JACK server is not running or the JACK client library is not available excitation = sumpf.SineWave(length=2**15) xruns = _XRunHandler() jack = sumpf.Jack(input_signal=excitation, input_ports=["capture_1"]) jack.xruns.connect(xruns.xrun) jack.connect(0, 0) jack.start() response = jack.output() assert response.channels() == pytest.approx(excitation.channels()) jack.add_input_port("capture_2") jack.connect(0, 1) jack.start() response = jack.output() assert response[0].channels() == pytest.approx(excitation.channels()) assert response[1].channels() == pytest.approx(excitation.channels()) assert xruns.xruns == []
def test_playback_and_recording(): """Tests connecting ports in JACK, playing back and recording a signal.""" with _create_client( ): # skip this test if the JACK server is not running or the JACK client library is not available excitation = sumpf.MergeSignals([ sumpf.GaussianNoise(length=2**15).shift(-5), sumpf.SineWave(length=2**15), sumpf.HannWindow(length=2**15) ]).output() assert excitation.offset( ) % 2 != 0 # check that the offset and length are odd values, that assert excitation.length( ) % 2 != 0 # do not coincide with the blocks of the JACK server xruns = _XRunHandler() jack = sumpf.Jack(input_signal=excitation, input_ports=["capture_1", "channel_2", "record_3"]) jack.xruns.connect(xruns.xrun) jack.connect("Gaussian noise", "SuMPF:capture_1") jack.connect(1, "channel_2") jack.connect("SuMPF:Hann window", 2) jack.start() response = jack.output() assert response.channels() == pytest.approx(excitation.channels()) assert response.offset() == excitation.offset() assert response.sampling_rate() == jack.sampling_rate() # pylint: disable=comparison-with-callable; pylint got confused by the connectors.MacroOutput assert response.labels() == ("capture_1", "channel_2", "record_3") assert xruns.xruns == []
def start(self): import jack jack.attach("NoteRecogniser Recorder") jack.register_port("in_1", jack.IsInput) jack.activate() try: jack.connect("system:capture_1", "NoteRecogniser Recorder:in_1") jack.connect("system:capture_2", "NoteRecogniser Recorder:in_1") except err: print("Unable to connect to system:capture") buffer_size = jack.get_buffer_size() sample_rate = float(jack.get_sample_rate()) print "Buffer Size:", buffer_size, "Sample Rate:", sample_rate output = scipy.zeros((1, buffer_size), 'f') while True: try: input = scipy.zeros((1, buffer_size), 'f') jack.process(output, input) #print len(input) fft = numpy.fft.rfft(input[0]) fft = map( lambda c: math.sqrt(c.real * c.real + c.imag * c.imag), fft) #print(len(fft)) dominant = reduce(lambda y, x: x if x[1] > y[1] else y, zip(range(len(fft)), fft), [0, 0]) print dominant except jack.InputSyncError: print "Input Sync Error" pass except jack.OutputSyncError: print "Output Sync Error" pass
def __init__(self, output='jack', numChannels = 2): self.numChannels = numChannels self.output = output if output == 'jack': # use pyjack import jack try: jack.get_client_name() except jack.NotConnectedError: jack.attach('remix') # not registering an input port makes the output sync # consistently break after processing 2 buffers # - bug in pyjack? jack.register_port("in_1", jack.IsInput) for i in range(0, self.numChannels): jack.register_port("out_" + str(i+1), jack.IsOutput) jack.activate() for i in range(0, self.numChannels): jack.connect("remix:out_" + str(i+1), "alsa_pcm:playback_" + str(i+1)) self.n = jack.get_buffer_size() self.jackSampleRate = float(jack.get_sample_rate()) # loosing a buffer, here, see below self._reset_jack()
def conecta_tarjeta(vias): jack.attach("tmp") # Disponemos de la funcion brutefir.outputsMap que contiene # el mapeo de vias tal como esta definido en brutefir_config, por ejemplo: # system:playback_3/hi_L # system:playback_4/hi_R # system:playback_7/lo_L # system:playback_8/lo_R # system:playback_5/sw1 # system:playback_6/sw2 to_disconnect=[] to_connect = [] # Ahora debemos evaluar si es una salida a activar: for bfOutMap in brutefir.outputsMap: conectar = False jackDest, bfOut = bfOutMap.split('/') jackOrig = "brutefir:" + bfOut for via in vias: if via.lower() in bfOut.lower(): conectar = True if conectar: to_connect.append( (jackOrig, jackDest) ) else: to_disconnect.append( (jackOrig, jackDest) ) for pair in to_disconnect: jack.disconnect(pair[0], pair[1]) for pair in to_connect: jack.connect(pair[0], pair[1]) jack.detach()
def conecta (a, b, mode="connect"): """ conecta puertos de captura con puertos de playback """ # Lista de puertos A Aports = [x for x in jack.get_ports() if a in x] # y filtramos los de captura Aports = [x for x in Aports if jack.get_port_flags(x) % 2 == 0 ] # Lista de puertos B Bports = [x for x in jack.get_ports() if b in x] # y filtramos los de playback Bports = [x for x in Bports if jack.get_port_flags(x) % 2 == 1 ] # Recorremos A y lo vamos (des)conectando con B while Aports: try: p1 = Aports.pop(0) p2 = Bports.pop(0) #print p1, p2 if mode == 'disconnect': jack.disconnect(p1, p2) else: jack.connect(p1, p2) except: pass
def start(self): import jack jack.attach("NoteRecogniser Recorder") jack.register_port("in_1", jack.IsInput) jack.activate() try: jack.connect("system:capture_1", "NoteRecogniser Recorder:in_1") jack.connect("system:capture_2", "NoteRecogniser Recorder:in_1") except err: print ("Unable to connect to system:capture") buffer_size = jack.get_buffer_size() sample_rate = float(jack.get_sample_rate()) print "Buffer Size:", buffer_size, "Sample Rate:", sample_rate output = scipy.zeros((1,buffer_size), 'f') while True: try: input = scipy.zeros((1,buffer_size), 'f') jack.process(output, input) #print len(input) fft = numpy.fft.rfft(input[0]) fft = map(lambda c : math.sqrt(c.real*c.real + c.imag*c.imag), fft) #print(len(fft)) dominant = reduce(lambda y,x: x if x[1] > y[1] else y, zip(range(len(fft)), fft), [0,0]) print dominant except jack.InputSyncError: print "Input Sync Error" pass except jack.OutputSyncError: print "Output Sync Error" pass
def connect_source2jacktrip(): jack.attach("tmp") # Desconectamos lo que hubiera en JackTrip c1_ports = jack.get_connections("JackTrip:send_1") c2_ports = jack.get_connections("JackTrip:send_2") for p1 in c1_ports: jack.disconnect(p1, "JackTrip:send_1") for p2 in c2_ports: jack.disconnect(p2, "JackTrip:send_2") try: # conectamos las fuente del FIRtro a jacktrip s1_ports = jack.get_connections(firtro_ports[0]) s2_ports = jack.get_connections(firtro_ports[1]) for s1 in s1_ports: jack.connect(s1, "JackTrip:send_1") for s2 in s2_ports: jack.connect(s2, "JackTrip:send_2") except: # el motivo del fallo es que los puertos de JackTrip no estĂ¡n activos: # "Cannot connect ports owned by inactive clients: "JackTrip" is not active" # porque no ha sincronizado todavĂa con un cliente. print "(jacktrip.py) (i) para conectar puertos se necesita que estĂ©n" print " activos (con una conexion cliente jacktrip en red)" jack.detach()
def test_playback_and_recording(): """Tests connecting ports in JACK, playing back and recording a signal.""" _create_client() # skip this test if the JACK server is not running or the JACK client library is not available excitation = sumpf.MergeSignals([sumpf.GaussianNoise(length=2 ** 15).shift(-5), sumpf.SineWave(length=2 ** 15), sumpf.HannWindow(length=2 ** 15)]).output() assert excitation.offset() % 2 != 0 # check that the offset and length are odd values, that assert excitation.length() % 2 != 0 # do not coincide with the blocks of the JACK server xruns = _XRunHandler() jack = sumpf.Jack(input_signal=excitation, input_ports=["capture_1", "channel_2", "record_3"]) jack.xruns.connect(xruns.xrun) jack.connect("Gaussian noise", "SuMPF:capture_1") jack.connect(1, "channel_2") jack.connect("SuMPF:Hann window", 2) jack.start() response = jack.output() assert response.channels() == pytest.approx(excitation.channels()) assert response.offset() == excitation.offset() assert response.sampling_rate() == jack.sampling_rate() # pylint: disable=comparison-with-callable; pylint got confused by the connectors.MacroOutput assert response.labels() == ("capture_1", "channel_2", "record_3") assert xruns.xruns == []
#!/usr/bin/python # -*- coding: utf-8 -*- # Plays a 440.0 Hz test tone for 3 seconds to alsa_pcm:playback_1. # # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Public License. # See LICENSE for the full text of these terms. import numpy import jack jack.attach("testtone") jack.register_port("in_1", jack.IsInput) jack.register_port("out_1", jack.IsOutput) jack.activate() jack.connect("testtone:out_1", "alsa_pcm:playback_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate()) print "Buffer Size:", N, "Sample Rate:", Sr sec = 3.0 input = numpy.zeros((1,N), 'f') output = numpy.reshape( numpy.sin( 2*numpy.pi*440.0 * (numpy.arange(0, sec, 1.0/(Sr), 'f')[0:int(Sr*sec)]) ), (1, Sr*sec)).astype('f') i = 0 while i < output.shape[1] - N: try:
def connect(self, output): jack.connect(self.port, output.port)
#out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK) #out.setchannels(1) #out.setrate(rate) #out.setformat(alsaaudio.PCM_FORMAT_S16_LE) #out.setperiodsize(slen) #inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK) jack.attach("captest") jack.register_port("in_1", jack.IsInput) #jack.register_port("in_2", jack.IsInput) jack.register_port("out_1", jack.IsOutput) #jack.register_port("out_2", jack.IsOutput) jack.activate() jack.connect("system:capture_1", "captest:in_1") jack.connect("system:capture_2", "captest:in_1") jack.connect("captest:out_1", "system:playback_1") jack.connect("captest:out_1", "system:playback_2") buffer_size = jack.get_buffer_size() sample_rate = float(jack.get_sample_rate()) print "Buffer Size:", buffer_size, "Sample Rate:", sample_rate sec = 0.1 #capture = scipy.zeros((2,int(Sr*sec)), 'f') input = scipy.zeros((1,buffer_size), 'f') output = scipy.zeros((1,buffer_size), 'f')
#out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK) #out.setchannels(1) #out.setrate(rate) #out.setformat(alsaaudio.PCM_FORMAT_S16_LE) #out.setperiodsize(slen) #inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK) jack.attach("captest") jack.register_port("in_1", jack.IsInput) #jack.register_port("in_2", jack.IsInput) jack.register_port("out_1", jack.IsOutput) #jack.register_port("out_2", jack.IsOutput) jack.activate() jack.connect("system:capture_1", "captest:in_1") jack.connect("system:capture_2", "captest:in_1") jack.connect("captest:out_1", "system:playback_1") jack.connect("captest:out_1", "system:playback_2") buffer_size = jack.get_buffer_size() sample_rate = float(jack.get_sample_rate()) print "Buffer Size:", buffer_size, "Sample Rate:", sample_rate sec = 0.1 #capture = scipy.zeros((2,int(Sr*sec)), 'f') input = scipy.zeros((1, buffer_size), 'f') output = scipy.zeros((1, buffer_size), 'f')
print("got note ", note) semitones=note-self.keynote self.note=note self.playstep=2**(semitones/12.0) self.playpos=0 def stopNote(self,note): if note==self.note: self.note=0 self.playpos=0 self.playstep=0 jack.attach("pysampl") jack.register_port("out_1", jack.IsOutput) jack.register_port("in_1", jack.IsInput) jack.activate() jack.connect("pysampl:out_1", "system:playback_1") jack.connect("pysampl:out_1", "system:playback_2") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate()) input_buf = numpy.zeros((1,N), 'f') output, samplerate = soundfile.read('Sample.wav') output = 0.225*output/numpy.max(output) mysampl = sampler(output, 60) midiOut = mido.open_input(MIDI_DEVICE) def handleMidi(msg): if msg.type=='note_on':
def jack_connect(p1, p2): jack.connect(p1, p2)
import time jack.attach("captest") myname = jack.get_client_name() print "Client:", myname print jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.activate() print jack.get_ports() jack.connect("system:capture_1", myname+":in_1") jack.connect("system:capture_2", myname+":in_2") print jack.get_connections(myname+":in_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate()) print "Buffer Size:", N, "Sample Rate:", Sr sec = 3.0 capture = numpy.zeros((2,int(Sr*sec)), 'f') dummy = numpy.zeros((2,0), 'f') #time.sleep(1) print "Capturing audio..."
#!/usr/bin/env python3 import re import jack import argparse if __name__ == "__main__": parser = argparse.ArgumentParser("Autoconnect jack ports") parser.add_argument('--sclient', default=".*") parser.add_argument('--sport', default=".*") parser.add_argument('--dclient', default=".*") parser.add_argument('--dport', default=".*") args = parser.parse_args() shre = re.compile(args.sclient) spre = re.compile(args.sport) dhre = re.compile(args.dclient) dpre = re.compile(args.dport) ports = jack.getPorts() sources = [p for p in ports if shre.match(p.client) and spre.match(p.port)] dests = [p for p in ports if dhre.match(p.client) and dpre.match(p.port)] for s in sources: if s.isOutput(): print(s) for d in dests: if d.isInput(): print("\t-> {}".format(d)) jack.connect(s, d)
if args.input: if ',' in args.input: capture_ports = args.input.split(',') else: jack_capture_ports = [p for p in jack.get_ports() if jack.get_port_flags(p) & jack.IsOutput] try: request = re.compile(args.input) capture_ports = [s.string for i in jack_capture_ports for s in [re.match(request, i)] if s] except: print 'input ports not valid' i = 0 for p in capture_ports: try: print 'connect {} to {}'.format(p, input_ports[i]) jack.connect(p, input_ports[i]) i += 1 if i >= len(input_ports): i = 0 except Exception as err: print err print 'failed to connect: (\'{}\', \'{}\')'.format(p, input_ports[i]) break startup = time() class Processor: def __init__(self): self.input_stream = input_stream self.output_ports = output_ports self.output_n = output_n
# # Copyright 2003, Andrew W. Schmeder # This source code is released under the terms of the GNU Public License. # See LICENSE for the full text of these terms. import numpy import jack import pysoundfile import time jack.attach("pymetro") jack.register_port("out_1", jack.IsOutput) jack.register_port("in_1", jack.IsInput) jack.activate() #print(jack.get_ports()) jack.connect("pymetro:out_1", "system:playback_1") jack.connect("pymetro:out_1", "system:playback_2") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate()) output_file = pysoundfile.SoundFile('MetronomeUp.wav') output = output_file.read() output = 0.225*output/numpy.max(output) print(output.shape) input = numpy.zeros((1,N), 'f') print(N) print(output.transpose().shape) output=output.transpose() output=output[0]
print "Connecting to jackd" print "Don't forget to run: jackd -d alsa -d hw:M1010LT -r 44100 " print "Or: jackd -d alsa -r 44100 " jack.attach("pleasehold") channels = 2 for x in range(channels): num = str(x+1) jack.register_port("out_"+num, jack.IsOutput) jack.register_port("in_"+num, jack.IsInput) jack.activate() for x in range(channels): num = str(x+1) jack.connect("system:capture_"+num, "pleasehold:in_"+num) jack.connect("pleasehold:out_"+num, "system:playback_"+num) bufsize = jack.get_buffer_size() samplerate = float(jack.get_sample_rate()) headphones = numpy.zeros((channels,bufsize), 'f') microphones = numpy.zeros((channels,bufsize), 'f') b = None loop = 0
def connect_left_speaker(self): try : jack.connect("sooperlooper:common_out_1", "alsa_pcm:playback_1") except : print("Run jack and sooperlooper") sys.exit(1)
print "There are %d phones." % (len(telephones)) for x in range(channels): num = str(x+1) jack.register_port("out_"+num, jack.IsOutput) jack.register_port("in_"+num, jack.IsInput) jack.activate() num_telephones = channels # Create 8 telephones for now for x in range(num_telephones): num = str(x+1) if x < 8: jack.connect("system:capture_"+num, "pleasehold:in_"+num) jack.connect("pleasehold:out_"+num, "system:playback_"+num) else: alsa_num = str(x-7) jack.connect("alsa_in:capture_"+alsa_num, "pleasehold:in_"+num) jack.connect("pleasehold:out_"+num, "alsa_out:playback_"+alsa_num) bufsize = jack.get_buffer_size() samplerate = float(jack.get_sample_rate()) print "jackd: ", channels, "buffersize", bufsize, "samplerate", samplerate headphones = numpy.zeros((channels,bufsize), 'f') microphones = numpy.zeros((channels,bufsize), 'f')
import time jack.attach("captest") myname = jack.get_client_name() print "Client:", myname print jack.get_ports() jack.register_port("in_1", jack.IsInput) jack.register_port("in_2", jack.IsInput) jack.activate() print jack.get_ports() jack.connect("system:capture_1", myname + ":in_1") jack.connect("system:capture_2", myname + ":in_2") print jack.get_connections(myname + ":in_1") N = jack.get_buffer_size() Sr = float(jack.get_sample_rate()) print "Buffer Size:", N, "Sample Rate:", Sr sec = 3.0 capture = numpy.zeros((2, int(Sr * sec)), 'f') dummy = numpy.zeros((2, 0), 'f') #time.sleep(1) print "Capturing audio..."
net.connect((CCC_HOST, CCC_PORT)) net.send('VU') time_update = time.time() time_random = time_update if AUDIO_MODE == 'alsa': framesize = 1024 rate = 22050 pipe = os.popen('arecord -N -c 1 -r %d -f S16_LE' % (rate,), 'r', 0) elif AUDIO_MODE == 'jack': jack.attach('VU-Meter') jack.register_port('in_1', jack.IsInput) jack.register_port('out_1', jack.IsOutput) jack.activate() # jack.connect('alsa_pcm:capture_1', 'VU-Meter:in_1') jack.connect('system:capture_1', 'VU-Meter:in_1') framesize = jack.get_buffer_size() rate = jack.get_sample_rate() input_array = numpy.zeros((1, framesize), 'f') output_array = numpy.zeros((1, framesize), 'f') try: while True: if AUDIO_MODE == 'alsa': rms = 0.0 frame = pipe.read(framesize * 2) # 2 bytes per sample (16-bit) if len(frame) == framesize * 2: for sample in struct.unpack('<' + framesize * 'h', frame): rms += (sample / 32768.0) ** 2 rms = math.sqrt(rms / framesize) else:
r, g, b = 1 - scaler, 1, 0 elif hue < 3 / 6.0: r, g, b = 0, 1, scaler elif hue < 4 / 6.0: r, g, b = 0, 1 - scaler, 1 elif hue < 5 / 6.0: r, g, b = scaler, 0, 1 else: r, g, b = 1, 0, 1 - scaler return r, g, b jack.attach("colours") jack.register_port("in", jack.IsInput) jack.activate() jack.connect("system:capture_1", "colours:in") buff = jack.get_buffer_size() rate = jack.get_sample_rate() freqs = np.fft.fftfreq(buff, 1.0 / rate)[: buff / 2] hues = array([(log2(F) - log2(440)) % 1 for F in freqs]) hue_order = array(sorted(enumerate(hues[1:], 1), key=lambda f: f[1]), "i").T[0] freq_rgb = array([hue_to_rgb(h) for h in hues]) capture = np.zeros((1, buff), "f") dummy = np.zeros((0, 0), "f") pygame.init() size = (1024, 32) window = pygame.display.set_mode(size)