Commit 34feac57 authored by Jackson Garner's avatar Jackson Garner

Cache the beat and boundry values after one run

parent d4c1a404
......@@ -9,6 +9,8 @@ import math
import msaf
import librosa
import sys
from functools import lru_cache
import pickle
import librosaToWave
import generate_waves
......@@ -18,12 +20,39 @@ file_name = None
wave_type = 0
fs=44100
def mkBounds(name):
try:
f = open(name + ".cache", "rb")
return pickle.load(f)
except:
of = open(name + ".cache", "wb")
result = msaf.process(name)
pickle.dump(result, of)
return result
def mkBeat(name):
try:
f = open(name + ".beat", "rb")
return pickle.load(f)
except:
of = open(name + ".beat", "wb")
audio = librosa.load(name, sr=None)[0]
audio_harmonic, audio_percussive = librosa.effects.hpss(audio)
tempo, frames = librosa.beat.beat_track(y=audio_harmonic,
sr=fs, hop_length=1024)
result = librosa.frames_to_time(frames, sr=fs,
hop_length=1024)
pickle.dump(result, of)
return result
if len(sys.argv) == 1:
print("Provide a file name or an integer as an argument")
exit()
else:
try:
wave_type = int(sys.argv[1])
wave_type = int(sys.argv[1])
except:
load_from_file = True
file_name = sys.argv[1]
......@@ -34,13 +63,8 @@ elif load_from_file == True:
#rate, wav_data = wavfile.read(sys.argv[1], mmap=True)
# wav_data = samples
wav_data, rate = librosaToWave.getWave(fileName=sys.argv[1])
boundaries, labels = msaf.process(sys.argv[1])
audio = librosa.load(sys.argv[1], sr=None)[0]
audio_harmonic, audio_percussive = librosa.effects.hpss(audio)
tempo, frames = librosa.beat.beat_track(y=audio_harmonic,
sr=fs, hop_length=1024)
beat_times = librosa.frames_to_time(frames, sr=fs,
hop_length=1024)
boundaries, labels = mkBounds(sys.argv[1])
beat_times = mkBeat(sys.argv[1])
plt.ion()
fig = plt.figure()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment