예제 #1
0
 def test_bow(self, basename, st, seconds=1.0):
     self.vln.reset()
     self.wavfile = monowav.MonoWav(basename + ".wav")
     num_samples = int(
         seconds *
         artifastring_instrument.ARTIFASTRING_INSTRUMENT_SAMPLE_RATE)
     #self.vln.bow(self.st, 0.12, 0.33, 0.25)
     self.vln.bow(st, 0.12, 0.1, 0.2)
     for i in range(int(num_samples / HOPSIZE)):
         buf = self.wavfile.request_fill(HOPSIZE)
         self.vln.wait_samples(buf, HOPSIZE)
예제 #2
0
def test_N(violin, N, inst, st):
    violin.reset()
    pc = violin.get_physical_constants(st)
    pc.N = N
    violin.set_physical_constants(st, pc)
    seconds = 5.0
    num_samples = int(seconds * 44100.0)
    violin.pluck(st, 0.47, 4.0)
    wavfile = monowav.MonoWav(
        str("out/pluck-modes-%i-%i-%i.wav" % (inst, st, N)))
    buf = wavfile.request_fill(num_samples)
    artifastring_instrument.wait_samples_c(violin, buf, num_samples)
예제 #3
0
 def test_stable(self, st, beta, bow_force, vb):
     self.vln.reset()
     wavfile = monowav.MonoWav("pc-consts/test-stable.wav")
     for i in range(
             int(TEST_SECONDS *
                 artifastring_instrument.ARTIFASTRING_INSTRUMENT_SAMPLE_RATE
                 / HOPSIZE)):
         self.vln.finger(st, 0.251, 1.0)
         self.vln.bow(st, beta, bow_force, vb)
         buf = wavfile.request_fill(HOPSIZE)
         #stable = self.vln.wait_samples(self.audio_out_buf)
         stable = artifastring_instrument.wait_samples_c(
             self.vln, buf, HOPSIZE)
         #print stable
         if stable > 0:
             print stable
             print "bail stable 1"
             print bow_force
             #exit(1)
             return False
         #self.vln.wait_samples_forces(self.audio_out_buf,
         #    self.force_out_buf, HOPSIZE)
         #if not stable:
         #    return False
     #print 'ok'
     #exit(1)
     stable = self.vln.wait_samples(self.audio_out_buf)
     #print stable
     if stable > 0:
         print "bail stable 2"
         return False
     #self.vln.wait_samples_forces(self.audio_out_buf,
     #   self.force_out_buf, HOPSIZE)
     #if not stable:
     #   return False
     #flatness = self.spectral_flatness(self.audio_out_buf)
     #force_ok = self.spectral_forces(self.force_out_buf)
     #if not flatness:
     #    print "bail flatness 1"
     #    return False
     #print flatness
     #if flatness > MAX_SPECTRAL_FLATNESS:
     #    print "bail flatness 2"
     #    return False
     return True
예제 #4
0
#!/usr/bin/env python

import math

import violin_instrument
import monowav

import scipy

violin = violin_instrument.ViolinInstrument()
wavfile = monowav.MonoWav("artifastring-test.wav")

FS = 44100
half = FS / 2
st = 0

violin.finger(0, 0.344)
violin.bow(0, 0.08, 2.5, 0.3)
out = wavfile.request_fill(half)
violin.wait_samples(out, half)
violin.bow(0, 0.08, 2.5, 0.0)

violin.bow(1, 0.08, 1.5, 0.3)
out = wavfile.request_fill(half)
violin.wait_samples(out, half)

violin.bow(0, 0.08, 2.5, 0.3)
violin.bow(1, 0.08, 1.5, 0.3)
out = wavfile.request_fill(44100)
violin.wait_samples(out, 44100)
예제 #5
0
def main():
    filename = sys.argv[1]
    lines = open(filename).readlines()
    outfilename = filename.split('.')[0] + '.wav'
    wavfile = monowav.MonoWav(outfilename)
    parseFile(lines, wavfile)
    def snapshot(self, cat_key):
        basename = quality_judgements.get_train_basename(
            self.train_info, self.artifastring_init, self.params)
        actions_out = actions_file.ActionsFile(basename+".actions")
        finger_midi = midi_pos.pos2midi(self.params.finger_position)
        actions_out.comment(
            "basic\tst %i\tdyn %i\tfinger_midi %.3f\tinst %i %i" % (
            self.params.violin_string, 0, finger_midi,
            self.artifastring_init.instrument_type,
            self.artifastring_init.instrument_number,
            ))
        actions_out.finger(0, self.params.violin_string,
            self.params.finger_position)

        complete = numpy.empty(0, dtype=numpy.int32)
        complete_forces = numpy.empty(0, dtype=numpy.int32)

        seconds = 0.4
        bow_pos_along = 0.1
        num_hops = int(math.ceil(seconds * ARTIFASTRING_SAMPLE_RATE / HOPSIZE))
        for j in xrange(num_hops):
            arr, forces, bowed_arr, bowed_forces = self.audio_pipe_master.recv()
            complete = numpy.append(complete, bowed_arr)
            complete_forces = numpy.append(complete_forces, bowed_forces)
            self.audio_pipe_master.send( (arr, forces, bowed_arr,
                bowed_forces) )
            seconds = float(j)*HOPSIZE/ARTIFASTRING_SAMPLE_RATE

            myparm = self.copy_params()
            myparm.force = random.gauss(self.params.force,
                GAUSSIAN_FORCE*self.params.force)
            myparm.velocity = random.gauss(self.params.velocity,
                GAUSSIAN_VELOCITY*self.params.velocity)
            self.commands_pipe_master.send( (COMMANDS.BOW, myparm) )
            actions_out.bow(seconds, self.params.violin_string,
                self.params.bow_position,
                #self.params.force,
                #self.params.velocity,
                myparm.force, myparm.velocity,
                bow_pos_along,
                )
            bow_pos_along += myparm.velocity/float(
                ARTIFASTRING_SAMPLE_RATE)
        # do one more action for "good luck"
        seconds = (j+1)*HOPSIZE/float(
            ARTIFASTRING_SAMPLE_RATE)
        actions_out.bow(seconds, self.params.violin_string,
            self.params.bow_position,
            self.params.force,
            self.params.velocity,
            bow_pos_along
            )
        actions_out.close()


        wavfile = monowav.MonoWav(basename+".wav",
            ARTIFASTRING_SAMPLE_RATE, ARTIFASTRING_SAMPLE_RATE,
            True)
        ### very awkward abuse of SWIG.  There has to be a better way!
        buf = wavfile.request_fill_int(len(complete))
        for i in xrange(len(complete)):
            monowav.buffer_set_int(buf, i, int(complete[i]))

        wavfile2 = monowav.MonoWav(basename+".forces.wav",
            HAPTIC_SAMPLE_RATE, HAPTIC_SAMPLE_RATE, True)
        buf2 = wavfile2.request_fill_int(len(complete_forces))
        for i in xrange(len(complete_forces)):
            monowav.buffer_set_int(buf2, i, int(complete_forces[i]))

        quality_judgements.append_to_mf(self.train_info, self.params,
            basename+".wav", cat_key)
        #self.stdscr.addstr(22, 10, str("wrote to %s" % mf_filename))
        self.snapshot_post(basename)