def on_rename_button_click(self):
    e1 = self.builder.get_object('Entry_1')
    e2 = self.builder.get_object('Entry_2')
    e3 = self.builder.get_object('Entry_3')
    e4 = self.builder.get_object('Entry_4')
    e5 = self.builder.get_object('Entry_5')
    p = e1.get()
    ext = e2.get()
    s = e3.get()
    num_vel = e4.get()
    num_seq = e5.get()
    listFiles = glob.glob(p + '*' + ext)
    listFiles.sort(key=natural_keys)
    print(p)

    for k, file in enumerate(listFiles):
        wv = wvrd(file)
        wv_left = wv[1][:, 0]
        wv_right = wv[1][:, 1]

        f_1harmonic = freq_wav(wv_left)

        current_pitch = pitch(f_1harmonic)
        if k % int(num_seq) == 0:
            i = 1
            cfrm2 = input(file[-12:] + " was identified as " + current_pitch +
                          " seq " + str(i) + ". Proceed? [y/n]")
            if cfrm2 == 'y':
                nt = current_pitch
            else:
                nt = input("So, which note should it be? ")
        os.rename(file, p + str(nt) + s.replace('#', '') + str(i) + ext)
        print(file + ' -> ' + p + str(nt) + s.replace('#', '') + str(i) + ext)
        i += 1
Пример #2
0
def on_convolve_button_click(entries):
    e = []
    field = []
    for k, entry in enumerate(entries):
        field.append(entry[0])
        e.append(entry[1].get())
    path1 = e[0]
    path2 = e[1]
    path_out = e[2]
    
    wv1 = wvrd(path1)
    wv2 = wvrd(path2)
    srate = wv1[0]
    
    wv_conv = stereoConvolution(wv1, wv2)
    wvwr(path_out, srate, wv_conv.astype('float32'))
Пример #3
0
def on_convolve_button_click(entries):
    e = []
    field = []
    for k, entry in enumerate(entries):
        field.append(entry[0])
        e.append(entry[1].get())
    path1 = e[0]
    path2 = e[1]
    path3 = e[2]
    path_out = e[3]

    wv1 = wvrd(path1)
    wv2 = wvrd(path2)
    srate = wv1[0]

    if path3 == '':  # empty
        wv_conv = stereoConvolution(wv1, wv2)
    else:
        wv3 = wvrd(path3)
        wv_conv = doubleStereoConvolution(wv1, wv2, wv3)
    wvwr(path_out, srate, wv_conv.astype('float32'))
def on_loop_button_click(
    entries
):  # this will only affect samples which already have the tag loop_start
    e = []
    field = []
    for k, entry in enumerate(entries):
        field.append(entry[0])
        e.append(entry[1].get())
    path_sfz = e[5]
    #sfz_file = open(path_sfz)
    with open(path_sfz, 'r') as sfz_file:
        text = sfz_file.read()
    remaining_text = text  # start to iterate through the text
    pos_l = 0
    #while pos_l != -1: # when str.find() doesn't find anything, it returns -1
    loop_starts = np.array([])
    loop_ends = np.array([])
    while True:  #for k in range(4):
        pos_l = remaining_text.find(
            'loop_start'
        )  # pos_l is the position of the first character of the next loop_start
        #aux_text = remaining_text[pos_l:pos_l-500:-1] # search for the tag 'sample' backwards. This line is only for limitting the search to last n characters
        #pos_s = pos_l - aux_text.find('elpmas') # sample backwards
        if pos_l == -1:
            break
        aux_text = remaining_text[:pos_l]
        pos_s = aux_text.rfind(
            'sample'
        )  # position of the first char of 'sample' in the aux_text, looking backwards
        endline = aux_text[pos_s:].find('\n')
        sfz_folder = path_sfz[:path_sfz.rfind('/')]
        sample_file_path = sfz_folder + '/' + aux_text[
            pos_s + 7:pos_s +
            endline]  # adding the sample file name given in the sfz file with the rest of the folder
        sample_file_path = '/'.join(sample_file_path.split('\\'))
        #print(sample_file_path)
        remaining_text = remaining_text[pos_l + 10:]

        wv = wvrd(sample_file_path)
        loop_sample_start, loop_sample_end = find_loop_samples(wv)
        #print('Start:' + str(loop_sample_start))
        #print('End:' + str(loop_sample_end))

        loop_starts = np.append(loop_starts, loop_sample_start)
        loop_ends = np.append(loop_ends, loop_sample_end)

    rewrite_sfz_file(loop_starts, loop_ends, text, path_sfz, '_loop')
    print('Done!')
Пример #5
0
def on_rename_button_click(entries):
    e = []
    field = []
    for k, entry in enumerate(entries):
        field.append(entry[0])
        e.append(entry[1].get())
    p = e[0] + '/'
    ext = e[1]
    s = e[2]
    num_vel = e[3]
    num_seq = e[4]
    listFiles = glob.glob(p + '*' + ext)
    listFiles.sort(key=natural_keys)
    fetch(entries)

    for k, file in enumerate(listFiles):
        wv = wvrd(file)

        f_1harmonic = freq_wav(wv)

        current_pitch = pitch(f_1harmonic)
        i1 = num_vel  # for test, will be updated
        if k % int(num_seq) == 0:
            i2 = 1
            cfrm2 = simpledialog.askstring(
                "Input", file[-12:] + " was identified as " + current_pitch +
                " seq " + str(i2))
            if cfrm2 == '':
                nt = current_pitch
            else:
                nt = cfrm2
        #os.rename(file, p + str(nt) + s.replace('#', '') + str(i) + ext)
        os.rename(
            file, p +
            s.replace('$0', nt).replace('$1', str(i1)).replace('$2', str(i2)) +
            ext)
        print(
            file + ' -> ' + p +
            s.replace('$0', nt).replace('$1', str(i1)).replace('$2', str(i2)) +
            ext)
        i2 += 1
s = input("Enter the name prefix with a # where the numeration is: ")
#l = input("How long is the number string? ")
##n = input("How many files in total? ")
#print("So, your files are in the form: {",)
#for i in range(3):
#    print(s.replace('#','%.{}d'.format(l) % (i+1)) + ext + ', ',)
#print("}")
#cfrm = input("Confirm? [y/n]: ")

listFiles.sort(key=natural_keys)

if cfrm == 'y':
    i = 1
    last_pitch = ''
    for file in listFiles:
        wv = wvrd(file)
        wv_left = wv[1][:, 0]
        wv_right = wv[1][:, 1]
        srate = wv[0]
        dt = 1.0 / srate
        wv_left_f = abs(np.fft.fft(wv_left))[0:int(len(wv_left) / 2)]
        wv_left_fn = wv_left_f / np.max(wv_left_f)
        frq = wv_left_f / (len(wv_left) * dt)
        thr = 0.06  # threshold for first harmonic
        #f_1harmonic = np.argmax(wv_left_fn > 0.06)/(len(wv_left)*dt)
        f_1harmonic = (wv_left_fn[np.argmax(wv_left_fn > 0.06)] * np.argmax(
            wv_left_fn > 0.06) + wv_left_fn[np.argmax(wv_left_fn > 0.06) - 1] *
                       (np.argmax(wv_left_fn > 0.06) - 1) +
                       wv_left_fn[np.argmax(wv_left_fn > 0.06) + 1] *
                       (np.argmax(wv_left_fn > 0.06) + 1)) / (len(wv_left) * dt
                                                              )  # correction
Пример #7
0
    
    or
    
    $python converb.py audioFile.wav stereoImpulseRespForLeftChannel.wav stereoImpulseRespForRightChannel.wav output.wav

"""

import sys
from scipy.io.wavfile import read as wvrd
from scipy.io.wavfile import write as wvwr
from stereoConvolution import stereoConvolution
from doubleStereoConvolution import doubleStereoConvolution

path1 = sys.argv[1]
path2 = sys.argv[2]

wv1 = wvrd(path1)
wv2 = wvrd(path2)

if len(sys.argv) == 4:
    path_out = sys.argv[3]
    wv_conv = stereoConvolution(wv1, wv2)
elif len(sys.argv) == 5:
    path3 = sys.argv[3]
    wv3 = wvrd(path3)
    path_out = sys.argv[4]
    wv_conv = doubleStereoConvolution(wv1, wv2, wv3)

srate = wv1[0]

wvwr(path_out, srate, wv_conv.astype('float32'))