Example #1
0
def Easygram(limits, song, bpm, barIn, barEnd, measure, unitSize, save=False):
    '''
    Easy spectrogram that uses Frequency Peaks and Frequency Bands to simplify the waveform information.

    Parameters
    ----------
    limits : TYPE
        Receive a list of frequency bands of same length.
    song : TYPE
        Song object from onset, used to localize the chunk.
    bpm : TYPE
        Bpm of the song.
    barIn : TYPE
        Bar Number for chunk start.
    barEnd : TYPE
         Bar Number for chunk end.
    measure : TYPE
        Number of beats in bar.
    unitSize : TYPE
        Grid division by beat size, 1/16 of 1/4 is 0.25.
    save : TYPE, optional
        Save .csv file for multiband array.

    Returns
    -------
    multiband : TYPE
        An array of energy by frequency bands.
    energy : TYPE
        Total amount of energy in the chunk.
    topFrequencies : TYPE
        The frequency band(s) with highest energy.

    TO DO: Add number of top frequencies > 1, add option to enable PlotPeaks2
    '''
    multiband, energy, topFrequencies = [], [], []
    unitStar = int(barIn * measure * (1 / unitSize))
    amountOfUnits = int(barEnd * measure * (1 / unitSize))

    unit = (60 / bpm) * song.sampfreq * unitSize
    unitRange = 4096
    pai = song.peakAlphaIndex

    for i in range(unitStar, amountOfUnits):
        start, end = pai + int(i * unit), pai + int(i * unit) + unitRange
        chunk = song.data[start:end]
        freqs, fft = onset.CalculateFFT_dB(chunk, song.sampfreq, limits[0],
                                           limits[len(limits) - 1])

        x, y = onset.GetFrequencyPeaks(freqs, fft)
        freqBandsAmp = onset.FrequencyBands(x, y, limits)
        #onset.PlotPeaks2(limits, freqBandsAmp, limits, (0,250), "plotUnits/" + str(i+1) + ".png")

        multiband.append(freqBandsAmp)  # energy in bands
        energy.append(np.sum(freqBandsAmp))  # total energy in spectrum
        topFrequencies.append(onset.GetTopFrequencies(limits, freqBandsAmp, 1))

    if save == True:
        SaveSimpleSpectrogram(limits, multiband)

    return multiband, energy, topFrequencies
def NewOnset(song, limits, chunkSize):
    energy, topFrequencies = [], []
    unitStart = song.peakAlphaIndex
    amountOfUnits = song.length // chunkSize
    for i in range(amountOfUnits):
        start = unitStart + int(i * chunkSize)
        end = start + chunkSize
        chunk = song.data[start:end]
        freqs, fft = onset.CalculateFFT_dB(chunk, song.sampfreq, limits[0],
                                           limits[len(limits) - 1])
        energy.append(np.max(fft))
        topFrequencies.append(onset.GetTopFrequencies(freqs, fft, start, 1))
    return energy, topFrequencies
Example #3
0
def Easygram_4096(limits, song, bpm, barIn, barEnd, measure, unitSize):
    energy, topFrequencies = [], []
    unitStar = int(barIn * measure * (1 / unitSize))
    amountOfUnits = int(barEnd * measure * (1 / unitSize))
    unit = (60 / bpm) * song.sampfreq * unitSize
    chunkSize, pai = 4096, song.peakAlphaIndex

    for i in range(unitStar, amountOfUnits):
        start, end = pai + int(i * unit), pai + int(i * unit) + chunkSize
        chunk = song.data[start:end]
        freqs, fft = onset.CalculateFFT_dB(chunk, song.sampfreq, limits[0],
                                           limits[len(limits) - 1])
        energy.append(np.max(fft))  # max energy point
        topFrequencies.append(onset.GetTopFrequencies(freqs, fft, start, 1))
    return energy, topFrequencies
Example #4
0
def Easygram(limits, song, bpm, barIn, barEnd, measure, unitSize):
    '''
    Easy spectrogram that uses Frequency Peaks and Frequency Bands to simplify the waveform information.

    Parameters
    ----------
    limits : TYPE
        Receive a list of frequency bands of same length.
    song : TYPE
        Song object from onset, used to localize the chunk.
    bpm : TYPE
        Bpm of the song.
    barIn : TYPE
        Bar Number for chunk start.
    barEnd : TYPE
         Bar Number for chunk end.
    measure : TYPE
        Number of beats in bar.
    unitSize : TYPE
        Grid division by beat size, 1/16 of 1/4 is 0.25.

    Returns
    -------
    energy : TYPE
        Total amount of energy in the chunk.
    topFrequencies : TYPE
        The frequency band(s) with highest energy.

    TO DO: Add number of top frequencies > 1, add option to enable PlotPeaks2
    '''
    energy, topFrequencies = [], []
    unitStar = int(barIn * measure * (1 / unitSize))
    amountOfUnits = int(barEnd * measure * (1 / unitSize))

    unit = (60 / bpm) * song.sampfreq * unitSize
    unitRange = 2048
    pai = song.peakAlphaIndex

    for i in range(unitStar, amountOfUnits):
        start, end = pai + int(i * unit), pai + int(i * unit) + unitRange
        chunk = song.data[start:end]
        freqs, fft = onset.CalculateFFT_dB(chunk, song.sampfreq, limits[0],
                                           limits[len(limits) - 1])
        energy.append(np.max(fft))  # max energy point
        topFrequencies.append(onset.GetTopFrequencies(freqs, fft, start, 1))

    return energy, topFrequencies
Example #5
0
def SampleProfile(file, resolution):
    audio = onset.Song(wavfile.read("songs/samples/" + file))
    
    limits = [240,1680]
    note = audio.data[0:resolution]
    onset.PlotNote(note, audio.sampfreq, limits[0], limits[len(limits)-1], file.split(".")[0] + ".png")
    
    freqs, fft = onset.CalculateFFT_dB(note, audio.sampfreq, limits[0], limits[len(limits)-1])
    x, y = onset.GetSpectrumPeaks(freqs, fft)
    print(x,y)
    freq, amp = onset.GetTopFrequencies(x,y,8)
    plt.figure(figsize = (20,10))
    plt.xticks(freq)
    plt.scatter(freq,amp)
    plt.xlim(limits[0],limits[1])
    plt.ylim(10,30)

    plt.savefig("sp_" + file.split(".")[0] + ".png")
    plt.show()