def __init__(self, inst_num, inst_text, st, st_text): self.pitch_obj = aubio.aubiowrapper.new_aubio_pitchdetection( WINDOWSIZE, HOPSIZE, 1, 44100, aubio.aubiowrapper.aubio_pitch_yinfft, aubio.aubiowrapper.aubio_pitchm_freq, ) self.fvec = aubio.aubiowrapper.new_fvec(HOPSIZE, 1) self.vln = violin_instrument.ViolinInstrument(inst_num) self.audio_out_buf = monowav.shortArray(HOPSIZE) self.force_out_buf = monowav.shortArray(HOPSIZE/4) self.inst_text = inst_text self.st = st self.st_text = st_text # icky! self.friction = {} self.attempts = []
FS = 44100.0 hundred_ms = int(0.1 * FS) hopsize = 512 pc = violin.get_physical_constants(2) orig_tension = pc.T / 2.0 pc.T = orig_tension violin.set_physical_constants(2, pc) bp = 0.1 bf = 1.0 bv = 0.4 violin.bow(2, bp, bf, bv) out = monowav.shortArray(HOPSIZE) seconds = 0.0 def wait_pitch(): violin.wait_samples(out, hopsize) global seconds seconds += hopsize/44100.0 for i in xrange(HOPSIZE): aubio.aubiowrapper.fvec_write_sample( fvec, out[i], 0, i) pitch = aubio.aubiowrapper.aubio_pitchdetection( pitch_obj, fvec) return pitch
tuningfile = open('data-tuning.txt', 'w') FS = 44100.0 hundred_ms = int(0.1 * FS) hopsize = 512 pc = violin.get_physical_constants(2) orig_tension = pc.T / 2.0 pc.T = orig_tension violin.set_physical_constants(2, pc) bp = 0.1 bf = 1.0 bv = 0.4 violin.bow(2, bp, bf, bv) out = monowav.shortArray(HOPSIZE) seconds = 0.0 def wait_pitch(): violin.wait_samples(out, hopsize) global seconds seconds += hopsize / 44100.0 for i in xrange(HOPSIZE): aubio.aubiowrapper.fvec_write_sample(fvec, out[i], 0, i) pitch = aubio.aubiowrapper.aubio_pitchdetection(pitch_obj, fvec) return pitch for i in range(87):
def violin_process(artifastring_init, commands_pipe, audio_pipe): try: pyaudio_obj, audio_stream = make_audio_stream() except: pyaudio_obj = None audio_stream = None vivi = vivi_controller.ViviController( artifastring_init.instrument_type, artifastring_init.instrument_number) if artifastring_init.instrument_type == 0: base_midi = 55 inst = "violin" elif artifastring_init.instrument_type == 1: base_midi = 48 inst = "viola" elif artifastring_init.instrument_type == 2: base_midi = 36 inst = "cello" vivi.filesNew("test-interactive") for st in range(4): vivi.load_ears_training(st, "../final/%s/%i.mpl" % (inst, st)) for dyn in range(4): for fmi in range(3): vivi.set_stable_K(st, dyn, fmi, 1.2) audio_buf = monowav.shortArray(HOPSIZE) samples = 0 logfile = actions_file.ActionsFile("log-interactive.actions") physical = vivi_controller.PhysicalActions() params = None while commands_pipe.poll(): params = handle_command(vivi, commands_pipe, logfile, samples) if params is None: continue physical.string_number = params.violin_string physical.finger_position = params.finger_position physical.bow_force = params.force physical.dynamic = 0 physical.bow_bridge_distance = params.bow_position physical.bow_velocity = params.velocity midi_target = base_midi + (7*params.violin_string + midi_pos.pos2midi(physical.finger_position)) #pc = violin.get_physical_constants(params.violin_string) #commands_pipe.send( (TENSION, pc.T) ) while True: while commands_pipe.poll(): params = handle_command(vivi, commands_pipe, logfile, samples) #vivi.comment("st, force: %i %.3f" % # (params.violin_string, params.force)) if params is None: continue physical.string_number = params.violin_string physical.finger_position = params.finger_position physical.bow_force = params.force physical.dynamic = 0 physical.bow_bridge_distance = params.bow_position physical.bow_velocity = params.velocity midi_target = base_midi + (7*params.violin_string + round(midi_pos.pos2midi(physical.finger_position))) vivi.continuous(audio_buf.cast(), physical, midi_target, False) arr, forces = audio_pipe.recv() if arr is None: # poison pill break if physical.string_number >= 0: vivi.comment("new force: %.3f" % physical.bow_force) vivi.continuous(audio_buf.cast(), physical, midi_target, True) physical.string_number = -1 for i in xrange(HOPSIZE): arr[i] = audio_buf[i] # vivi_controller.buffer_get(audio_buf, i) #vivi.wait_samples_forces_python(arr, 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) ) samples += HOPSIZE logfile.wait(float(samples)/ARTIFASTRING_SAMPLE_RATE) logfile.close() if pyaudio_obj is not None: audio_stream.close() pyaudio_obj.terminate()