Skip to content

Commit

Permalink
Add python scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jun 11, 2022
1 parent a6e2a81 commit 299ebe4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/resources/samples
/build
/cmake-build-*
/venv

.DS_Store
*.pdf
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
librosa
matplotlib

autopep8
pylint
28 changes: 28 additions & 0 deletions src/Scripts/bpm_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import matplotlib.pyplot as plt
import numpy as np

import librosa
import librosa.display

y, sr = librosa.load('/home/tobante/Music/Loops/Bass.wav', sr=None, mono=True)
onset_env = librosa.onset.onset_strength(y=y, sr=sr, aggregate=np.median)
tempo, beats = librosa.beat.beat_track(onset_envelope=onset_env, sr=sr)


hop_length = 512
fig, ax = plt.subplots(nrows=2, sharex=True)
times = librosa.times_like(onset_env, sr=sr, hop_length=hop_length)

M = librosa.feature.melspectrogram(y=y, sr=sr, hop_length=hop_length)
librosa.display.specshow(librosa.power_to_db(M, ref=np.max), y_axis='mel',
x_axis='time', hop_length=hop_length, ax=ax[0])

ax[0].label_outer()
ax[0].set(title='Mel spectrogram')

ax[1].plot(times, librosa.util.normalize(onset_env), label='Onset strength')
ax[1].vlines(times[beats], 0, 2, alpha=0.5,
color='r', linestyle='--', label='Beats')
ax[1].legend()

plt.show()

0 comments on commit 299ebe4

Please sign in to comment.