コード例 #1
0
    def start_jack_client(self):
        self._waiting_jack_client_open = True

        # Sometimes JACK never registers the client
        # and never answers. This thread will allow to exit
        # if JACK didn't answer 5 seconds after register ask
        jack_waiter_thread = threading.Thread(
            target=self.check_jack_client_responding)
        jack_waiter_thread.start()

        #time.sleep(20)
        with suppress_stdout_stderr():
            self.jack_client = jacklib.client_open(
                "ray-patch_to_osc",
                jacklib.JackNoStartServer | jacklib.JackSessionID, None)

        self._waiting_jack_client_open = False
        jack_waiter_thread.join()

        if self.jack_client:
            self.jack_running = True
            self.set_registrations()
            self.get_all_ports_and_connections()
            self.osc_server.set_jack_client(self.jack_client)
            self.samplerate = jacklib.get_sample_rate(self.jack_client)
            self.buffer_size = jacklib.get_buffer_size(self.jack_client)
            self.osc_server.server_restarted()
        else:
            self.jack_running = False
コード例 #2
0
ファイル: cadence_aloop_daemon.py プロジェクト: rhetr/Cadence
def client_registration_callback(clientName, register, arg):
    global doRunNow
    if clientName == b"system" and register:
        print("NOTICE: Possible JACK2 master switch")
        global bufferSize, sampleRate
        doRunNow   = True
        sampleRate = jacklib.get_sample_rate(client)
        bufferSize = jacklib.get_buffer_size(client)
    elif clientName in (b"alsa2jack", b"jack2alsa") and not register:
        global doLoop, useZita
        if doLoop and not doRunNow:
            doLoop = False
            print("NOTICE: %s have been stopped, quitting now..." % ("zita-a2j/j2a" if useZita else "alsa_in/out"))
コード例 #3
0
def client_registration_callback(clientName, register, arg):
    if clientName == b"system" and register:
        print("NOTICE: Possible JACK2 master switch")
        global bufferSize, sampleRate, doRunNow
        bufferSize = jacklib.get_buffer_size(client)
        sampleRate = jacklib.get_sample_rate(client)
        doRunNow   = True

    elif clientName in (b"alsa2jack", b"jack2alsa") and not register:
        global doLoop, reactivateCounter, useZita
        if doRunNow or not doLoop:
            return

        if isKernelGood:
            if reactivateCounter == -1:
                reactivateCounter = 0
                print("NOTICE: %s has been stopped, waiting 5 secs to reactivate" % ("zita-a2j/j2a" if useZita else "alsa_in/out"))
        elif doLoop:
            doLoop = False
            print("NOTICE: %s has been stopped, quitting now..." % ("zita-a2j/j2a" if useZita else "alsa_in/out"))
コード例 #4
0
        quit()

    if jacklib.JACK2:
        jacklib.set_client_registration_callback(client, client_registration_callback, None)

    jacklib.set_buffer_size_callback(client, buffer_size_callback, None)
    jacklib.set_sample_rate_callback(client, sample_rate_callback, None)
    jacklib.on_shutdown(client, shutdown_callback, None)
    jacklib.activate(client)

    # Quit when requested
    signal(SIGINT, signal_handler)
    signal(SIGTERM, signal_handler)

    # Get initial values
    sampleRate = jacklib.get_sample_rate(client)
    bufferSize = jacklib.get_buffer_size(client)

    # Create check file
    if not os.path.exists(checkFile):
        os.mknod(checkFile)

    # Keep running until told otherwise
    firstStart = True
    while doLoop and os.path.exists(checkFile):
        if doRunNow:
            if firstStart:
                firstStart = False
                print("cadence-aloop-daemon started, using %s and %i channels" % ("zita-a2j/j2a" if useZita else "alsa_in/out", channels))

            run_alsa_bridge()
コード例 #5
0
ファイル: VNA.py プロジェクト: docprofsky/pysdrvna
  def __init__(self,configd=None):
    """Create a VNA object"""

    if configd is None: configd = config.__dict__

    self.printlevel = configd['printlevel']
    self.fftn = configd['fftn']
    self.amp = configd['amp']
    self.warmuptime = configd['warmuptime']
    self.cooldowntime = configd['cooldowntime']
   
    self.docapture = threading.Event()
    self.docapture.set()

    self.xrun = threading.Event()
    self.xrun.clear()

    self.startframe = 0

    #self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackNoStartServer | jacklib.JackSessionID, None)
    self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackSessionID, None)
    
    try:
      self.jackclient.contents
    except:
      print("Problems with Jack")
      return
      #raise

    self.iI = jacklib.port_register(self.jackclient,"iI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0)
    self.iQ = jacklib.port_register(self.jackclient,"iQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0)    

    self.oI = jacklib.port_register(self.jackclient,"oI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0)
    self.oQ = jacklib.port_register(self.jackclient,"oQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0)
   
    jacklib.set_process_callback(self.jackclient, self.JackProcess, 0)
    jacklib.set_xrun_callback(self.jackclient, self.JackXrun, 0)

    jacklib.activate(self.jackclient)
   
    jacklib.connect(self.jackclient,"pysdrvna:oQ", configd['outQ'])
    jacklib.connect(self.jackclient,"pysdrvna:oI", configd['outI'])    
    
    jacklib.connect(self.jackclient,configd['inQ'],"pysdrvna:iQ")
    jacklib.connect(self.jackclient,configd['inI'],"pysdrvna:iI") 
    
    self.Sr = float(jacklib.get_sample_rate(self.jackclient))
    self.dt = 1.0/self.Sr
      
    ## Align frequency to nearest bin
    self.fftbin = int(round((configd['freq']/self.Sr)*self.fftn))      
    self.freq = (float(self.fftbin)/self.fftn) * self.Sr
    
    ## Windowing function
    #self.fftwindow = np.blackman(self.fftn)
    self.fftwindow = np.hanning(self.fftn)
    #self.fftwindow = np.kaiser(self.fftn,14)
    #self.fftwindow = np.hamming(self.fftn)
    #self.fftwindow = np.bartlett(self.fftn)
    #self.fftwindow = None
      
    ## Latency settings
    jlr = jacklib.jack_latency_range_t()
    jacklib.port_get_latency_range(self.oI,jacklib.JackPlaybackLatency,jlr)
    self.minrtframes = jlr.min
    jacklib.port_get_latency_range(self.iI,jacklib.JackCaptureLatency,jlr)
    self.minrtframes += jlr.min
 
    # The above code does not always work
    # Reasonable estimate is 3 times the buffer size
    ## Compute initial array length
    self.buffersz = int(jacklib.get_buffer_size(self.jackclient))
    if self.minrtframes < (3*self.buffersz):
        self.minrtframes = 3 * self.buffersz


    ## rtframes is the round trip audio latency, or when the received audio signal will start    
    self.rtframes = configd['rtframes'] if configd['rtframes'] else self.minrtframes
    ## delta from rtframes to phase shift sync in frames
    self.rtframes2sync = configd['rtframes2sync']
    ## delta from phase shift sync to fft start in frames
    self.sync2fft = configd['sync2fft']
    ## delta from end of fft to end of audio
    self.fft2end = configd['fft2end']


    if configd['rtframes'] is None:
        ## Loose fit if estimating based on minrtframes
        buffers, remainder = divmod((2*self.rtframes) + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz)
    else:
        ## Tight fit if rtframes is defined
        buffers, remainder = divmod(self.rtframes + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz)
  
    if remainder > 0: buffers = buffers + 1
    self.synci = self.rtframes
    self.InitJackArrays(self.freq,buffers*self.buffersz)
    
    self.fftia = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128')
    self.fftoa = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128')
    ## Create FFT Plan
    self.fft = pyfftw.FFTW(self.fftia,self.fftoa)

    self.OpenSoftRock()
    self.Info()
コード例 #6
0
    if jacklib.JACK2:
        jacklib.set_client_registration_callback(client,
                                                 client_registration_callback,
                                                 None)

    jacklib.set_buffer_size_callback(client, buffer_size_callback, None)
    jacklib.set_sample_rate_callback(client, sample_rate_callback, None)
    jacklib.on_shutdown(client, shutdown_callback, None)
    jacklib.activate(client)

    # Quit when requested
    signal(SIGINT, signal_handler)
    signal(SIGTERM, signal_handler)

    # Get initial values
    sampleRate = jacklib.get_sample_rate(client)
    bufferSize = jacklib.get_buffer_size(client)

    # Create check file
    if not os.path.exists(checkFile):
        os.mknod(checkFile)

    # Keep running until told otherwise
    firstStart = True
    while doLoop and os.path.exists(checkFile):
        if doRunNow:
            if firstStart:
                firstStart = False
                print(
                    "cadence-aloop-daemon started, using %s and %i channels" %
                    ("zita-a2j/j2a" if useZita else "alsa_in/out", channels))
コード例 #7
0
 def get_sample_rate(self):
     return int(jacklib.get_sample_rate(self.client))