Esempio n. 1
0
def test_writeMono():
    
    synth = Synth(44100)
    
    synth.noteOn(60)

    out = []
        
    for _ in range(4410):
        out.append(synth.getSample())
        
    synth.noteOff(60)
    
    writeMono("test_writeMono.wav", out, 44100)
def test_performance():

    ### python 
    
    
    s = Synth(44100, 32)
    s.noteOn(60)
    s.noteOn(64)
    s.noteOn(67)
    
    out = []

    """
    start = time.time()
    for _ in range(1 * 44100):
        out.append(s.getSample())
    end = time.time()
    """    

    s.noteOff(60)
    s.noteOff(64)
    s.noteOff(67)
    
    # inout.writeMono("/tmp/asdf_python.wav", out, 44100)
    
    # print "python synth: " + str(end - start)

    ### c

    s = CSynth(44100)
    s.noteOn(60)
    s.noteOn(64)
    s.noteOn(67)
    
    
    out = []
    
    start = time.time()
    for _ in range(1 * 44100):
        out.append(s.getSample())
    end = time.time()
    
    s.noteOff(60)
    s.noteOff(64)
    s.noteOff(67)
    
    inout.writeMono("/tmp/asdf_c.wav", out, 44100)
    
    print "csynth: " + str(end - start)
    
    ### c buffered

    s = CSynth(44100)
    s.noteOn(60)
    s.noteOn(64)
    s.noteOn(67)
    
    
    out = []
    
    start = time.time()
    buffer_size = 4410
    for _ in range(1 * 44100 / buffer_size):
        out.extend(s.getSamplesBuffered(buffer_size))
    end = time.time()
    
    inout.writeMono("/tmp/asdf_c_buffered.wav", out, 44100)
    
    s.noteOff(60)
    s.noteOff(64)
    s.noteOff(67)
    
    # inout.writeMono("/tmp/asdf_c.wav", out, 44100)
    
    print "csynth buffered: " + str(end - start)