示例#1
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()
示例#2
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
示例#3
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
示例#4
0
 def run(self):
     self.ALSA()
     self.GST()
     jack.attach(self.exe.handler.server.name)
     jack.activate()
     self.Jack()
     self.Play()
     self.cleanup()
     return self.statuses
示例#5
0
文件: pyjack.py 项目: minou/Awesomix
 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) 
示例#6
0
文件: inputs.py 项目: shish/mic2midi
        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')
示例#7
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)
示例#8
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()
示例#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)
示例#10
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)
示例#11
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
示例#12
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()
示例#13
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
示例#14
0
文件: testtone.py 项目: ispcf/pyjack
#!/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:
示例#15
0
文件: speaker.py 项目: minou/Awesomix
 def __init__(self, manager, **kwargs):
     super(Speaker, self).__init__(**kwargs)
     self._manager = manager
     jack.attach("sooperlooper")
     jack.activate()