...
 
Commits (2)
......@@ -6,8 +6,9 @@ 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
......@@ -15,12 +16,12 @@ 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):
for i in range(0, 10):
curr_freq = 440 + (i * 1000)
samples[(i * fs):((i + 1) * fs)] = signal.square(2*np.pi*np.arange(fs*duration)*curr_freq/fs).astype(np.float32)
......@@ -29,19 +30,30 @@ 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()
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
......@@ -50,7 +62,7 @@ while t - origin < len(wav_data) / rate:
second = wav_data[math.floor((t - origin) * rate) : math.floor((t - origin + timestep) * rate)]
print(second)
# print(second)
fft_plot.clear()
fft_plot.plot(np.abs(np.fft.fftshift(np.fft.fft(second[:,0]))))
......