Ejemplo n.º 1
0
def add_to_database(parameters, noteNumber, data, orchestra):
    instrument = parameters[2]
    tech = parameters[3]
    dyn = parameters[4]
    #note = parameters[5]
    dyn_db = assignDynamics.assign_dynamics(
        dyn, instrument, dynamics_list
    )  # function parameters: dynamics, instrument name, dynamics list
    data = cutSample(data)
    data = normalize_sound_file.normalize_audio_file(
        data, dyn_db)  #Set sound file level according to the loaded text file
    #print("data normalized")
    #mfcc_data=librosa.feature.mfcc(y=data,sr=fs,n_mfcc=12,win_length=fs)
    M = len(data)  #Length of data (should be 44100)
    spectrum = np.fft.fft(data, axis=0)[:M // 2 + 1:-1]  #Calculate the fft
    #print("spectrum calculated")
    S = np.abs(spectrum)  #Get rid of complex numbers
    S = 20 * np.log10(S)  #dB values of data
    try:
        masking_freq, masking_threshold = maskingCurve.maskingCurve(
            S, noteNumber)  #Calculate the masking curve
    except:
        print("Masking calculation fail, using flat masking curve")
        masking_freq = constants.threshold[:, 0]
        masking_threshold = np.ones(106)
    #print("masking calculated")
    mfcc_data, centroid = MFCC.custom_mfcc(
        data)  #Calculate mfcc and spectral centroid
    #print("mfcc calculated")
    LpcLocs, LpcFreqs = lpc_coeffs.lpc_coeffs(
        data)  #calculate LPC-frequency response
    #print("lpc calculated")
    #Add everything to database (except fft spectrum):
    nested_update(
        orchestra, {
            instrument: {
                tech: {
                    dyn: {
                        noteNumber: {
                            "data": data,
                            "masking_curve": masking_threshold,
                            "masking_locs": masking_freq,
                            "lpc_curve": LpcFreqs,
                            "lpc_locs": LpcLocs,
                            "mfcc": mfcc_data,
                            "centroid": centroid
                        }
                    }
                }
            }
        })
    return orchestra
Ejemplo n.º 2
0
add_to_database(fileParts, noteN, data)
#print(data.shape)
#print(data)
#sd.play(data, fs)
inst = 'alto_flute'
orchestra = {inst: {'data': data}}

M = len(data)
spectrum = np.fft.fft(orchestra[inst]['data'], axis=0)[:M // 2 + 1:-1]
spectrum = np.abs(spectrum)
S = 20 * np.log10(spectrum)
frq = 30

#mfcc_data=librosa.feature.mfcc(y=data,sr=rate,n_mfcc=12,n_fft=int(M),hop_length=int(M+2))[:,0]
mfcc_data, centroid = MFCC.custom_mfcc(data)
LpcLocs, LpcFreqs = lpc_coeffs.lpc_coeffs(data)

# LPC=librosa.lpc(data, lpc_coeffs)
# f,h=freqz(1,LPC, worN=lpc_coeffs, fs=fs)
# h=20 * np.log10(np.abs(h))

A = np.linspace(0, len(spectrum), 101)
#print("mfccs:")
#print(mfcc_data.shape)
#print(mfcc_data)
#print(centroid)
#peaks, _ = findPeaks(S, distance=frq, prominence=20, height=-10)
idx, peaks = findPeaks.peaks(S, noteN)
frq, thr = maskingCurve.maskingCurve(S, noteN)
#peaks = find_peaks_cwt(S,np.arange(1,fs/2+1))