Ejemplo n.º 1
0
def note(st, fp, bp, force, bv, basename):
    #print bp, force, bv

    violin = artifastring_instrument.ArtifastringInstrument(INSTRUMENT)
    #violin.reset()
    violin.finger(st, fp)
    violin.bow(st, bp, force, bv)

    samples = 1.0 * ARTIFASTRING_SAMPLE_RATE
    ### let string settle
    if True:
        buf = numpy.empty(samples, dtype=numpy.int16)
        forces = numpy.empty(samples /
                             artifastring_instrument.HAPTIC_DOWNSAMPLE_FACTOR,
                             dtype=numpy.int16)
        violin.wait_samples_forces_python(buf, forces)
    samples = 1.0 * ARTIFASTRING_SAMPLE_RATE
    ### part we care about
    #violin.set_string_logfile(st, str("%s-%i.log" % (basename, st)))
    if True:
        buf = numpy.empty(samples, dtype=numpy.int16)
        forces = numpy.empty(samples /
                             artifastring_instrument.HAPTIC_DOWNSAMPLE_FACTOR,
                             dtype=numpy.int16)
        violin.wait_samples_forces_python(buf, forces)

    scipy.io.wavfile.write(basename + ".wav", ARTIFASTRING_SAMPLE_RATE, buf)
Ejemplo n.º 2
0
    def __init__(self, inst_type, inst_num):
        self.inst = artifastring_instrument.ArtifastringInstrument(
            inst_type, inst_num)
        self.Fb = [0.0,0.0,0.0,0.0]
        self.xb = [0.125,0.125,0.125,0.125]
        self.vb = [0.4,0.4,0.4,0.4]
        self.fp = [0.0,0.0,0.0,0.0]
        #self.active = [False, False, False, False]

        try:
            self.server = liblo.Server(3123)
        except liblo.ServerError, err:
            print str(err)
            exit()
Ejemplo n.º 3
0
def violin_process(artifastring_init, commands_pipe, audio_pipe):
    try:
        pyaudio_obj, audio_stream = make_audio_stream()
    except:
        pyaudio_obj = None
        audio_stream = None

    violin = artifastring_instrument.ArtifastringInstrument(
        artifastring_init.instrument_type, artifastring_init.instrument_number)
    samples = 0

    logfile = actions_file.ActionsFile("log-interactive.actions")
    while commands_pipe.poll():
        handle_command(violin, commands_pipe, logfile, samples)

    #pc = violin.get_physical_constants(params.violin_string)
    #commands_pipe.send( (TENSION, pc.T) )

    st = 0
    while True:
        while commands_pipe.poll():
            st_next = handle_command(violin, commands_pipe, logfile, samples)
            if st_next is not None:
                st = st_next
        arr, forces, bowed_arr, bowed_forces = audio_pipe.recv()
        if arr is None:
            # poison pill
            break
        violin.wait_samples_forces_python(arr, forces)
        violin.get_string_buffer_int(st, bowed_arr, bowed_forces)
        #unsafe = violin.wait_samples_forces_python(arr, forces)
        #params_log.write("unsafe: %i" % unsafe)
        #commands_pipe.send( (COMMANDS.UNSAFE, unsafe) )
        if audio_stream is not None:
            audio_stream.write(arr.tostring(), HOPSIZE)
        audio_pipe.send((arr, forces, bowed_arr, bowed_forces))
        samples += HOPSIZE
    logfile.wait(float(samples) / ARTIFASTRING_SAMPLE_RATE)
    logfile.close()

    if pyaudio_obj is not None:
        audio_stream.close()
        pyaudio_obj.terminate()
Ejemplo n.º 4
0
    def __init__(self, inst_num, inst_text, inst_num_text):
        self.pitch_obj = aubio.aubiowrapper.new_aubio_pitchdetection(
            WINDOWSIZE,
            HOPSIZE,
            1,
            artifastring_instrument.ARTIFASTRING_INSTRUMENT_SAMPLE_RATE,
            #aubio.aubiowrapper.aubio_pitch_yin,
            aubio.aubiowrapper.aubio_pitch_yinfft,
            aubio.aubiowrapper.aubio_pitchm_freq,
        )
        self.fvec = aubio.aubiowrapper.new_fvec(HOPSIZE, 1)
        self.vln = artifastring_instrument.ArtifastringInstrument(inst_num)
        self.audio_out_buf = numpy.empty(HOPSIZE, dtype=numpy.int16)
        self.force_out_buf = numpy.empty(HOPSIZE / 4, dtype=numpy.int16)

        self.inst_text = inst_text
        self.inst_num_text = inst_num_text

        # icky!
        self.friction = {}

        self.pick_new_friction()
        self.pick_new_length()
Ejemplo n.º 5
0
def parseFile(lines, wavfile):
    violin = artifastring_instrument.ArtifastringInstrument()
    total_samples = 0

    for i, line in enumerate(lines):
        # is a comment
        if (line[0] == '#'):
            continue
        splitline = line.split()

        # advance time
        action_time = float(splitline[1])
        delta_samples = artifastring_instrument.ARTIFASTRING_INSTRUMENT_SAMPLE_RATE * action_time - total_samples
        delta_samples = int(delta_samples)
        if delta_samples > 0:
            #            print "advancing", delta_samples, "samples"
            buf = wavfile.request_fill(delta_samples)
            artifastring_instrument.wait_samples_c(violin, buf, delta_samples)
            total_samples += delta_samples
        elif delta_samples == 0:
            pass
        else:
            print "ERROR: move backwards in time? line", i
        actions(violin, splitline)
Ejemplo n.º 6
0
    POS = [ midi_pos.midi2pos(float(m)) for m in MIDI]
    vals = []
    #dbs = []
    for finger in POS:
        val = pluck_force(violin=violin,
            st=st, force=force, finger=finger,
            plot=plot, write=write,
            )
        vals.append(val)
        #dbs.append(db)
    val = min(vals)
    #db = max(dbs)
    return val


#for inst, instnum in STRINGS:
#    forces = INST_FORCES[inst]
#    for st, force in enumerate(forces):
#            val, db = do_string(inst=inst, instnum=instnum,
#                st=st, force=force,
#                #plot=True
#            )
#            print inst, instnum, st, val


if __name__ == "__main__":
    violin = artifastring_instrument.ArtifastringInstrument(0, 0)
    do_string(violin, 0, 3, plot=False, write=True)


Ejemplo n.º 7
0
def make_shared(inst_type, inst_num, expected_f0):
    inst = artifastring_instrument.ArtifastringInstrument(
            inst_type, inst_num)
    net, notempty = make_net(expected_f0)
    return inst, net, notempty
Ejemplo n.º 8
0
def do_inst(inst):
    violin = artifastring_instrument.ArtifastringInstrument(inst)
    for st in range(4):
        do_string(violin, inst, st)