-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdataset.py
51 lines (38 loc) · 1.71 KB
/
dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# To read our final list of songs and preprocesing them
# To read our final list of songs and preprocesing them
import numpy as np
import pandas as pd
from song import *
import os
# input is in shape ()
def read_data(diretory_name):
# This function reads the mixtures, bass, drums, vocals and others
mixtures_path = '/mixtures/'
bass_path = '/bass/'
drums_path = '/drums/'
vocals_path = '/vocals/'
others_path = '/others/'
mixture_data = read_folder(diretory_name, mixtures_path)
bass_data = read_folder(diretory_name, bass_path)
drums_data = read_folder(diretory_name, drums_path)
vocals_data = read_folder(diretory_name, vocals_path)
others_data = read_folder(diretory_name, others_path)
if len(mixture_data[0])!=len(bass_data[0]) or len(mixture_data[0])!=len(drums_data[0]) or len(mixture_data[0])!=len(vocals_data[0]) or len(mixture_data[0])!=len(others_data[0]):
print("directory sizes me ghapla, plzz check")
return mixture_data, bass_data, drums_data, vocals_data, others_data
#common function to read all instruments
def read_folder(diretory_name, folder):
instrument = [[], []]
#2 lists, 1 for magnitude 1 for phase
for file in os.listdir(folder_name):
file_stft, sr = load_file(str(diretory_name) + str(folder_name) + str(file))
augmented_file_stft = data_augmenttion(file_stft)
mag_channel, phase_channel = get_mag_phase(file_stft)
augmented_mag_channel, augmented_phase_channel = get_mag_phase(augmented_file_stft)
mag_channel = padding(mag_channel)
augmented_mag_channel = padding(augmented_mag_channel)
instrument[0].append(mag_channel)
instrument[0].append(augmented_mag_channel)
instrument[1].append(phase_channel)
instrument[1].append(augmented_phase_channel)
return instrument