示例#1
0
def test_port_rename(jack_client, porttype, flags, name):
    port = jacklib.port_register(jack_client, name, porttype, flags, 0)

    if not port:
        raise OSError(f"Could not register port {name}.")

    assert jacklib.port_short_name(port) == name
    res = jacklib.port_rename(jack_client, port, "renamed")
    assert res == 0
    assert jacklib.port_short_name(port) == "renamed"
示例#2
0
def test_port_rename_not_supported(jack_client):
    port = jacklib.port_register(jack_client, "output",
                                 jacklib.JACK_DEFAULT_AUDIO_TYPE,
                                 jacklib.JackPortIsOutput, 0)

    if not port:
        raise OSError(f"Could not register port {name}.")

    jacklib.jlib.jack_port_rename = None
    assert jacklib.port_short_name(port) == "output"

    res = jacklib.port_rename(jack_client, port, "renamed")
    assert res == -1
    assert jacklib.port_short_name(port) == "output"
示例#3
0
  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()
示例#4
0
                    elif len(data) == 3:
                        jack_midi_in_data.put_nowait((data[0], data[1], data[2]))

                    if jack_midi_in_data.full():
                        break

            del event
    except Exception as e:
        print e
    return 0


if __name__ == "__main__":
    # Start jack
    jack_client = jacklib.client_open("Floppy Drive", jacklib.NullOption, 0)
    jack_midi_in_port = jacklib.port_register(jack_client, "midi", jacklib.DEFAULT_MIDI_TYPE, jacklib.PortIsInput, 0)
    jacklib.set_process_callback(jack_client, jack_process_callback, 0)

    jacklib.activate(jack_client)

    floppy = Floppy(port=sys.argv[1], reset=True)

    noteplaying = None
    while 1:
        try:
            mode, noteid, velo = jack_midi_in_data.get(True, 1)
            note = Note(noteid)

            if (mode & MIDI_MASK) == MIDI_NOTEON:
                floppy.play(note)
                noteplaying = note