Exemplo n.º 1
0
    def __init__(self, playbackchannels=1, recordchannels=1):
        """
        @param playbackchannels: the number of channels for playback (can not be changed later)
        @param recordchannels: the number of channels for recording (can not be changed later)
        """
        self.__deleted = True
        # set up jack
        self.__prefix = "SuMPF"
        self.__inputs = []
        self.__outputs = []
        jack.attach(self.__prefix)
        self.__deleted = False
        for i in range(recordchannels):
            portname = "in_" + str(i + 1)
            self.__inputs.append(self.__prefix + ":" + portname)
            jack.register_port(portname, jack.IsInput)
        for i in range(playbackchannels):
            portname = "out_" + str(i + 1)
            self.__outputs.append(self.__prefix + ":" + portname)
            jack.register_port(portname, jack.IsOutput)
        jack.activate()
        # other stuff
        BaseIO.__init__(self, playbackchannels, recordchannels)
#       self.__periods = self.__GetNumberOfPeriods()
        self.__periods = 2
        self.__buffer_size = 0 # This will be set when the interaction with the sound card starts
Exemplo n.º 2
0
	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()
Exemplo n.º 3
0
Arquivo: ted.py Projeto: behrat/ted
    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))
Exemplo n.º 4
0
        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')
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
	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()
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    def __init__(self, nscopes, subsamp_factor, length, zoom):
        self.scopes = range(nscopes)
        jack.attach("jscope")
        print(jack.get_ports())
        for i in self.scopes:
            jack.register_port("in_%d" %(i), jack.IsInput)
        jack.activate()
        print jack.get_ports()
        #jack.connect(jack.get_ports()[-2], "jscope:in_1")

        # CONSTANTS
        self.N = jack.get_buffer_size()
        self.Sr = float(jack.get_sample_rate())
        self.plotlength = length #  plot length in seconds
        self.abscissa = -np.arange(self.Sr*self.plotlength) / self.Sr
        
        self.input_slice = np.zeros((nscopes, self.N), dtype='f')
        self.output_slice = self.input_slice.copy()

        self.fig = Figure()
        self.subsamp_factor = subsamp_factor
        self.ax = []
        self.plot_data = []
        self.l_plot_data = []
        self.input_ring = []
        self.output_ring = []
        for i in self.scopes:
            self.ax.append(self.fig.add_subplot(nscopes, 1, i+1))
            self.ax[i].set_ylim(-zoom, zoom)
            self.plot_data.append([])
            foo, = self.ax[i].plot([], self.plot_data[i])
            self.l_plot_data.append(foo)
            self.input_ring.append(RingBuffer(self.abscissa.size))
            self.output_ring.append(RingBuffer(self.abscissa.size))
            self.ax[i].set_xlim(self.abscissa[0], self.abscissa[-1])
            self.ax[i].grid()

        FigureCanvas.__init__(self, self.fig)
        self.fig.canvas.draw()

        self.timerEvent(None)
        self.timer = self.startTimer(0)
Exemplo n.º 9
0
    def __init__(self, nscopes, subsamp_factor, length, zoom):
        self.scopes = range(nscopes)
        jack.attach("jscope")
        print(jack.get_ports())
        for i in self.scopes:
            jack.register_port("in_%d" % (i), jack.IsInput)
        jack.activate()
        print jack.get_ports()
        #jack.connect(jack.get_ports()[-2], "jscope:in_1")

        # CONSTANTS
        self.N = jack.get_buffer_size()
        self.Sr = float(jack.get_sample_rate())
        self.plotlength = length  #  plot length in seconds
        self.abscissa = -np.arange(self.Sr * self.plotlength) / self.Sr

        self.input_slice = np.zeros((nscopes, self.N), dtype='f')
        self.output_slice = self.input_slice.copy()

        self.fig = Figure()
        self.subsamp_factor = subsamp_factor
        self.ax = []
        self.plot_data = []
        self.l_plot_data = []
        self.input_ring = []
        self.output_ring = []
        for i in self.scopes:
            self.ax.append(self.fig.add_subplot(nscopes, 1, i + 1))
            self.ax[i].set_ylim(-zoom, zoom)
            self.plot_data.append([])
            foo, = self.ax[i].plot([], self.plot_data[i])
            self.l_plot_data.append(foo)
            self.input_ring.append(RingBuffer(self.abscissa.size))
            self.output_ring.append(RingBuffer(self.abscissa.size))
            self.ax[i].set_xlim(self.abscissa[0], self.abscissa[-1])
            self.ax[i].grid()

        FigureCanvas.__init__(self, self.fig)
        self.fig.canvas.draw()

        self.timerEvent(None)
        self.timer = self.startTimer(0)
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
 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()
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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")
Exemplo n.º 14
0
 def add_ports(self, widget=None):
     if (self.output_n == 10 and channels == 2) or (self.output_n == 20):
         return
     self.output_n += 1
     item = gtk.CheckButton(label='output {}'.format(self.output_n))
     self.outport_box.pack_start(item, False, False, 0)
     item.show()
     self.group.append(item)
     self.output_ports.append(False)
     if channels == 2:
         jack.register_port('output {} L'.format(self.output_n), jack.IsOutput)
         jack.register_port('output {} R'.format(self.output_n), jack.IsOutput)
     else:
         jack.register_port('output {}'.format(self.output_n), jack.IsOutput)
     item.connect('toggled', self.selector, self.output_n-1)
     self.bind(self.output_n)
Exemplo n.º 15
0
        elif opc.startswith("name="):
            ownname = str(opc.split("=")[-1])

        elif opc == "-d":
            disconnect = True

        elif "-h" in opc:
            print __doc__
            sys.exit()

    # Nos atachamos a jackd
    jack.attach(ownname)

    # Creamos los puertos de esta instancia
    for i in range(1, 1 + nchannels):
        jack.register_port('out_' + str(i), jack.IsOutput)
        jack.register_port("in_"  + str(i), jack.IsInput)

    # Activamos los puertos
    jack.activate()

    # Conectamos los puertos de captura y playback deseados:
    if source:
        if disconnect:
            conecta(source, sink, mode='disconnect')
        conecta(source, ownname, mode='connect')
    if sink:
        if disconnect:
            conecta(source, sink, mode='disconnect')
        conecta(ownname, sink, mode='connect')
Exemplo n.º 16
0
output_ports = [True] + [False]*(output_n-1) if output_n>0 else []
active = 0

jack.attach(client_name)
buf_size = jack.get_buffer_size()
#sam_size = float(jack.get_sample_rate())
#capture = numpy.zeros((2,int(sam_size)), 'f')

input_stream = numpy.zeros((channels, buf_size), 'f')
empty_stream = numpy.zeros((channels, buf_size), 'f')
#output_stream = numpy.zeros((4, buf_size), 'f')
#input_buffer = numpy.zeros((2, buf_size), 'f')

input_ports = []
if channels == 2:
    jack.register_port('input L', jack.IsInput)
    input_ports.append(client_name + ':' + 'input L')
    jack.register_port('input R', jack.IsInput)
    input_ports.append(client_name + ':' + 'input R')
else:
    input_ports.append(jack.register_port('input', jack.IsInput))


for i in range(output_n):
    if channels == 2:
        jack.register_port('output {} L'.format(i+1), jack.IsOutput)
        jack.register_port('output {} R'.format(i+1), jack.IsOutput)
    else:
        jack.register_port('output {}'.format(i+1), jack.IsOutput)

jack.activate()
Exemplo n.º 17
0
    # Parse LED specification, create multiclient
    leds = arguments["<leds>"].split(",")
    client = clients[0]
    ledtuples = []
    for led in leds:
        led = led.split(":", 1)
        if len(led) >= 2:
            client = clients[int(led.pop(0)) - 1]
        ledtuples.append((client, int(led[0])))

    client = ledp.MultiClient(ledtuples)
    leds = range(len(ledtuples))

    # Setup JACK interface
    jack.attach(arguments["--name"])
    jack.register_port("input",
                       jack.IsInput | jack.IsTerminal | jack.IsPhysical)
    buffer_size = jack.get_buffer_size()
    sample_rate = jack.get_sample_rate()

    def buffer_size_callback():
        raise Exception("buffer size changed and I can't take that")
        exit(2)

    #jack.set_buffer_size_callback(buffer_size_callback) #FIXME
    def sample_rate_callback():
        raise Exception("sample rate changed and I can't take that")
        exit(2)

    #jack.set_sample_rate_callback(sample_rate_callback) #FIXME

    jack_input = np.zeros((1, buffer_size), 'f')
Exemplo n.º 18
0
	telephones.append(telephone.telephone(12, phonemap[12], ringerpinnum=(0,4),onhookpinnum=[0,'12'],channelnum=12, conversations=conversations, telephones=telephones,barqueue=barqueue))
	telephones.append(telephone.telephone(13, phonemap[13], ringerpinnum=(0,5),onhookpinnum=[0,'a0'],channelnum=13, conversations=conversations, telephones=telephones,barqueue=barqueue))
	telephones.append(telephone.telephone(14, phonemap[14], ringerpinnum=(0,6),onhookpinnum=[0,'a1'],channelnum=14, conversations=conversations, telephones=telephones,barqueue=barqueue))
	#telephones.append(telephone.telephone(15, phonemap[15], ringerpinnum=(0,7),onhookpinnum=[0,'a2'],channelnum=15, conversations=conversations, telephones=telephones,barqueue=barqueue))

else:
	channels = 2
	telephones.append(telephone.telephone(0, "Phone 52", ringerpinnum=None,onhookpinnum=None,channelnum=0,conversations= conversations, telephones=telephones))
	telephones.append(telephone.telephone(1, "Phone 53", ringerpinnum=None,onhookpinnum=None,channelnum=1,conversations= conversations, telephones=telephones))


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)
Exemplo n.º 19
0
        r, g, b = 1, scaler, 0
    elif hue < 2 / 6.0:
        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()
Exemplo n.º 20
0
    # Parse LED specification, create multiclient
    leds = arguments["<leds>"].split(",")
    client = clients[0]
    ledtuples = []
    for led in leds:
        led = led.split(":", 1)
        if len(led) >= 2:
            client = clients[int(led.pop(0)) - 1]
        ledtuples.append((client, int(led[0])))

    client = ledp.MultiClient(ledtuples)
    leds = range(len(ledtuples))

    # Setup JACK interface
    jack.attach(arguments["--name"])
    jack.register_port("input", jack.IsInput | jack.IsTerminal | jack.IsPhysical)
    buffer_size = jack.get_buffer_size()
    sample_rate = jack.get_sample_rate()

    def buffer_size_callback():
        raise Exception("buffer size changed and I can't take that")
        exit(2)
    #jack.set_buffer_size_callback(buffer_size_callback) #FIXME
    def sample_rate_callback():
        raise Exception("sample rate changed and I can't take that")
        exit(2)
    #jack.set_sample_rate_callback(sample_rate_callback) #FIXME

    jack_input = np.zeros((1, buffer_size), 'f')
    jack_output = np.zeros((0, buffer_size), 'f')
    output_buffer = range(buffer_size)
Exemplo n.º 21
0
        pass
    except jack.OutputSyncError:
        print "Output Sync Error"
        pass


def reset_view():
    [p.setYRange(-1, 1) for p in plots]
    [p.enableAutoRange(axis=pg.ViewBox.XAxis, enable=True)]


# initialize jack connections
nscopes = 1
jack.attach("jscope")
for i in range(nscopes):
    jack.register_port("in_%d" % (i), jack.IsInput)
jack.activate()
N = jack.get_buffer_size()
Sr = float(jack.get_sample_rate())
print (Sr)
plotlength = 0.3
abscissa = np.flipud(-np.arange(Sr * plotlength) / Sr)
print (len(abscissa))
resample_factor = int(abscissa.size / 1000)

rings = [RingBuffer(len(abscissa)) for i in range(nscopes)]

input_slice = np.zeros((nscopes, N), dtype="f")
output_slice = input_slice.copy()

Exemplo n.º 22
0
#!/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:
Exemplo n.º 23
0
vu_value = TARGET_CHANNELS * [0]
random_gain = TARGET_CHANNELS * [1.0]

net = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
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: