Commit 31c3b2a0 authored by Jared Lincenberg's avatar Jared Lincenberg

Merge branch 'master' of gitlab.com:ColoradoSchoolOfMines/pyvideomusicifier

parents b7670439 6968bd00
......@@ -2,44 +2,69 @@ import time
import matplotlib.pyplot as plt
import numpy as np
import scipy.io.wavfile as wavfile
from scipy import signal
import sounddevice
import time
import math
import msaf
import librosa
import numpy as np
volume = 0.5 # range [0.0, 1.0]
fs = 44100 # sampling rate, Hz, must be integer
duration = 1 # in seconds, may be float
f = 1440.0 # sine frequency, Hz, may be float
# generate samples, note conversion to float32 array
samples = np.zeros( 10 * fs)
for i in range(0, 10):
samples = np.zeros(10 * fs)
# for i in range(0, 10):
# curr_freq = 440 + (i * 1000)
# samples[(i * fs):((i + 1) * fs)] = np.sin(2*np.pi*np.arange(fs*duration)*curr_freq/fs).astype(np.float32)
for i in range(0, 10):
curr_freq = 440 + (i * 1000)
samples[(i * fs):((i + 1) * fs)] = np.sin(2*np.pi*np.arange(fs*duration)*curr_freq/fs).astype(np.float32)
samples[(i * fs):((i + 1) * fs)] = signal.square(2*np.pi*np.arange(fs*duration)*curr_freq/fs).astype(np.float32)
plt.ion()
fig = plt.figure()
fft_plot = fig.add_subplot(111)
def plot(data):
plt.plot(data, color='steelblue')
rate, wav_data = wavfile.read("violin.wav", mmap=True)
wav_data = samples
# wav_data = samples
boundaries, labels = msaf.process("violin.wav")
audio = librosa.load("violin.wav", sr=fs)[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)
print(frames)
sounddevice.play(wav_data, rate)
timestep = 1/24
t = time.time()
for i in range(0, 54):
second = wav_data[i * rate:(i + 1) * rate]
while (time.time() - t < 1):
origin = time.time()
nextBeat = 0
while t - origin < len(wav_data) / rate:
if time.time() - origin >= beat_times[nextBeat]:
nextBeat += 1
print("Beat")
while (time.time() - t < timestep):
pass
t = time.time()
second = wav_data[math.floor((t - origin) * rate) : math.floor((t - origin + timestep) * rate)]
# print(second)
fft_plot.clear()
fft_plot.plot(np.abs(np.fft.fftshift(np.fft.fft(second[:]))))
fft_plot.plot(np.abs(np.fft.fftshift(np.fft.fft(second[:,0]))))
fig.canvas.draw()
fig.canvas.flush_events()
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