def Snare():
     noteThreshold = 0.6
     unitSize = 0.5
     print("\nObtaining Snare...")
     # Step, Peaks, 4 by 4, unit 0.5
     x_all, y_energy, z_freq  = [],[],[]
     freqBands = [120,300] 
     barBlock = 4
     for i in range(maxBars//barBlock):
         barNum = i*barBlock
         x,y,z = ez.GetNotesPeaks3D_Step(freqBands, song, bpm, barNum, barNum+barBlock, measure, unitSize, noteThreshold)
         offset = i*barBlock*measure*(1/unitSize)
         for j in range(len(y)):
             x_all.append(x[j] + offset)
             y_energy.append(y[j])
             z_freq.append(z[j])
         
     peaks = []
     for i in x_all:
         peaks.append(i * (60/bpm)*unitSize * song.sampfreq)
         
     onset.SavePeaks(peaks, song.sampfreq, 1, song.peakAlphaIndex, directory + "peaksSnare" + "_" + songName.split(".")[0] + ".csv")
     
     pc_e,pc_f = parsons.GetPCode(x_all, y_energy),parsons.GetPCode(x_all, z_freq)
     x = [i*unitSize for i in x_all]
     ez.PlotComplete(x, pc_e, pc_f, bpm, maxBars, measure, unitSize, freqBands, directory, "plotSnare_" + songName, noteThreshold, song.GetRMS(), alphaPeak)
     parsons.SaveCSV3D(x, pc_e,pc_f, directory, "dataSnare_" + songName)
     print("Done.")
 def Hats():
     noteThreshold = 0.7
     unitSize = 0.25
     print("\nObtaining HiHats...")
     # Continuous, Peaks, all bars, unit 0.25
     x_all, y_energy, z_freq  = [],[],[]
     freqBands = [9000,16000] 
     barBlock = maxBars
     for i in range(maxBars//barBlock):
         barNum = i*barBlock
         x,y,z = ez.GetNotesPeaks3D_Continuous_Sum(freqBands, song, bpm, barNum, barNum+barBlock, measure, unitSize, noteThreshold)
         offset = i*barBlock*measure*(1/unitSize)
         for j in range(len(y)):
             x_all.append(x[j] + offset)
             y_energy.append(y[j])
             z_freq.append(z[j])
         
     peaks = []
     for i in x_all:
         peaks.append(i * (60/bpm)*unitSize * song.sampfreq)
         
     onset.SavePeaks(peaks, song.sampfreq, 1, song.peakAlphaIndex, directory + "peaksHats" + "_" + songName.split(".")[0] + ".csv")
     
     pc_e,pc_f = parsons.GetPCode(x_all, y_energy),parsons.GetPCode(x_all, z_freq)
     x = [i*unitSize for i in x_all]
     ez.PlotComplete(x, pc_e, pc_f, bpm, maxBars, measure, unitSize, freqBands, directory, "plotHats_" + songName, noteThreshold, song.GetRMS(), alphaPeak)
     parsons.SaveCSV3D(x, pc_e,pc_f, directory, "dataHats_" + songName)
     print("Done.")
 def Bass():
     noteThreshold = 0.5
     unitSize = 0.25
     # Continuous, Peaks, all bars, unit 0.25
     x_all, y_energy, z_freq  = [],[],[]
     freqBands = [0,120] 
     barBlock = maxBars
     for i in range(maxBars//barBlock):
         barNum = i*barBlock
         x,y,z = ez.GetNotesPeaks3D_Continuous(freqBands, song, bpm, barNum, barNum+barBlock, measure, unitSize, noteThreshold)
         offset = i*barBlock*measure*(1/unitSize)
         for j in range(len(y)):
             x_all.append(x[j] + offset)
             y_energy.append(y[j])
             z_freq.append(z[j])
         
     peaks = []
     for i in x_all:
         peaks.append(i * (60/bpm)*unitSize * song.sampfreq)
         
     onset.SavePeaks(peaks, song.sampfreq, 1, song.peakAlphaIndex, directory + "peaksBass.csv")
     
     pc_e,pc_f = parsons.GetPCode(x_all, y_energy),parsons.GetPCode(x_all, z_freq)
     x = [i*unitSize for i in x_all]
     ez.PlotComplete(x, pc_e, pc_f, bpm, maxBars, measure, unitSize, freqBands, directory, "plotBass.png", noteThreshold, song.GetRMS(), alphaPeak)
     parsons.SaveCSV5D(x, pc_e,pc_f,y_energy,z_freq,directory, "dataBass.csv")
     print("Done.")
    barNum = i * barBlock
    x, y, z = ez.GetNotesPeaks3D_Continuous(freqBands, song, bpm, barNum,
                                            barNum + barBlock, measure,
                                            unitSize, noteTR)
    offset = i * barBlock * measure * (1 / unitSize)
    #print(x,y,z)
    for j in range(len(y)):
        x_all.append(x[j] + offset)
        y_energy.append(y[j])
        z_freq.append(z[j])

peaks = []
for i in x_all:
    peaks.append(i * (60 / bpm) * unitSize * song.sampfreq)

onset.SavePeaks(peaks, song.sampfreq, 1, 0, "reaper/Files/peaks.csv")

pc_e, pc_f = parsons.GetPCode(x_all, y_energy), parsons.GetPCode(x_all, z_freq)
x = [i * unitSize for i in x_all]

ez.PlotComplete(x, pc_e, pc_f, bpm, maxBars, measure, unitSize, freqBands,
                plotPath, songName, noteTR, song.GetRMS(), alphaPeak)
parsons.SaveCSV3D(x, pc_e, pc_f, csvPath, songName)
'''
ez.PlotPart(x,y_freq, maxBars, measure, unitSize, plotPath + "zRefs/" + str(songName.split(".")[0]) + "_freq.png")
ez.PlotPart(x,y_energy, maxBars, measure, unitSize, plotPath + "zRefs/" + str(songName.split(".")[0]) + "_energy.png")
parsons.SaveCSV(x,y_freq, csvPath + "zRefs/" + str(songName.split(".")[0]) + "_freq.csv")
parsons.SaveCSV(x,y_energy, csvPath + "zRefs/" + str(songName.split(".")[0]) + "_energy.csv")

BAR BY BAR PLOTS
Exemple #5
0
# -*- coding: utf-8 -*-
"""
@author: albertovaldez
"""
import onset
from scipy.io import wavfile

songName = "cut.wav"
song = onset.Song(wavfile.read("songs/" + songName))
tr = onset.CalculateThreshold_RMS(song.data)

song.FindAlphaPeak(0,tr)
song.GetNoteOnset(unit = 4096, chunk_size = 4096, threshold_ratio = tr, HPF = 960, LPF = 1080, base = 10)
song.GetPeaks(x = 4096)
    
onset.SavePeaks(song.pks, song.sampfreq, 1, 0, "peaks.csv") 

song.PlotPeaks()

def GetSimpleSpectrogram_FromNotes(limits):
    multiband = []
    for i in range(len(song.notes)):
        start, end = song.notes[i][0], song.notes[i][0] + 4096
        chunk = song.data[start:end]
        
        freqs, fft = onset.CalculateFFT_dB(chunk, song.sampfreq, limits[0], limits[len(limits)-1])
        #x, y = onset.GetSpectrumPeaks(freqs, fft)
        x, y = freqs, fft
        
        freqBandsAmp = onset.FrequencyBands(x,y,limits)
        onset.PlotPeaks2(limits, freqBandsAmp, limits, (0,300), "plots/" + str(i+1) + ".png")
Exemple #6
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jul  1 18:30:55 2020

@author: albertovaldez
"""

import onset

song = onset.Song("songs/axtasia_closer.wav")

song.FindAlphaPeak(0, 0.5)
tr = onset.CalculateThreshold_RMS(song.data)

tr = 0.8
song.GetNoteOnset(unit=2048,
                  chunk_size=2048,
                  threshold_ratio=tr,
                  HPF=0,
                  LPF=120,
                  base=10)

song.GetPeaks(x=0)

bpm1, bpm2 = song.GetBPM(), song.GetBPM_PKS()

print(bpm1, bpm2)

onset.SavePeaks(song.pks, song.sampfreq, 1, -song.peakAlpha,
                "reaper/Files/peaks.csv")
print("done")