Skip to content
This repository has been archived by the owner on Feb 11, 2018. It is now read-only.

Commit

Permalink
docs update and pep8ing all files
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-balke committed Feb 15, 2017
1 parent fd69fbf commit 7e2659c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 89 deletions.
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

A collection of code examples demonstrating some of librosa's functionality.

## Examples
The rendered output of all examples can be found at:

https://librosa.github.io/librosa_gallery/

## Notebooks
## Contribute

You can explore our Jupyter Notebooks to find out what functionality `librosa` offers you.
As some example contain audio examples, you can use the `nbviewer` to see the notebooks.
If you want to contribute a cool application or educational example, you need
to take care of a few steps:

Use these links to get directly to the notebooks:
* Intro: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/01-Intro_demo.ipynb
* Audio Effects: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/02-Audio_effects.ipynb
* HPRSS: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/02-HPRSS.ipynb
* Vocal Separation: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/03-Vocal_separation.ipynb
* Music Segmentation: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/04-Laplacian segmentation.ipynb
* Superflux Onsets: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/05-Superflux_Onsets.ipynb
* Rhythm Analysis: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/06-Rhythm_Analysis_Mellin_Transform.ipynb
* Enhanced Chroma: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/07-Enhanced_Chroma.ipynb
* Overriding Presets: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/08-Overriding_Defaults_with_Presets.ipynb
* Music Synchronization: https://nbviewer.jupyter.org/github/librosa/librosa_gallery/blob/master/notebooks/09-Music_Synchronization.ipynb
* Meet all dependencies (listed in `requirements.txt`).
* It's easy to start with a Jupyter Notebook (optional).
* We use `sphinx_gallery` to create the output.
* Create a new python file in `examples`.
* Go to `docs/` and run `make html`.
35 changes: 15 additions & 20 deletions examples/plot_chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Code source: Brian McFee
# License: ISC
#sphinx_gallery_thumbnail_number = 6
# sphinx_gallery_thumbnail_number = 6

from __future__ import print_function
import numpy as np
Expand All @@ -35,8 +35,6 @@
y, sr = librosa.load('audio/Karissa_Hobbs_-_09_-_Lets_Go_Fishin.mp3')




#######################################
# First, let's plot the original chroma
chroma_orig = librosa.feature.chroma_cqt(y=y, sr=sr)
Expand All @@ -45,15 +43,15 @@
idx = [slice(None), slice(*list(librosa.time_to_frames([45, 60])))]

# And for comparison, we'll show the CQT matrix as well.
C = np.abs(librosa.cqt(y=y, sr=sr, bins_per_octave=12*3, n_bins=7*12*3, real=False))
C = np.abs(librosa.cqt(y=y, sr=sr, bins_per_octave=12*3, n_bins=7*12*3))


plt.figure(figsize=(12, 4))
plt.subplot(2,1,1)
plt.subplot(2, 1, 1)
librosa.display.specshow(librosa.amplitude_to_db(C, ref=np.max)[idx],
y_axis='cqt_note', bins_per_octave=12*3)
plt.colorbar()
plt.subplot(2,1,2)
plt.subplot(2, 1, 2)
librosa.display.specshow(chroma_orig[idx], y_axis='chroma')
plt.colorbar()
plt.ylabel('Original')
Expand All @@ -68,13 +66,13 @@

plt.figure(figsize=(12, 4))

plt.subplot(2,1,1)
plt.subplot(2, 1, 1)
librosa.display.specshow(chroma_orig[idx], y_axis='chroma')
plt.colorbar()
plt.ylabel('Original')


plt.subplot(2,1,2)
plt.subplot(2, 1, 2)
librosa.display.specshow(chroma_os[idx], y_axis='chroma', x_axis='time')
plt.colorbar()
plt.ylabel('3x-over')
Expand All @@ -91,12 +89,12 @@

plt.figure(figsize=(12, 4))

plt.subplot(2,1,1)
plt.subplot(2, 1, 1)
librosa.display.specshow(chroma_os[idx], y_axis='chroma')
plt.colorbar()
plt.ylabel('3x-over')

plt.subplot(2,1,2)
plt.subplot(2, 1, 2)
librosa.display.specshow(chroma_os_harm[idx], y_axis='chroma', x_axis='time')
plt.colorbar()
plt.ylabel('Harmonic')
Expand All @@ -115,12 +113,12 @@

plt.figure(figsize=(12, 4))

plt.subplot(2,1,1)
plt.subplot(2, 1, 1)
librosa.display.specshow(chroma_os_harm[idx], y_axis='chroma')
plt.colorbar()
plt.ylabel('Harmonic')

plt.subplot(2,1,2)
plt.subplot(2, 1, 2)
librosa.display.specshow(chroma_filter[idx], y_axis='chroma', x_axis='time')
plt.colorbar()
plt.ylabel('Non-local')
Expand All @@ -135,12 +133,12 @@

plt.figure(figsize=(12, 4))

plt.subplot(2,1,1)
plt.subplot(2, 1, 1)
librosa.display.specshow(chroma_filter[idx], y_axis='chroma')
plt.colorbar()
plt.ylabel('Non-local')

plt.subplot(2,1,2)
plt.subplot(2, 1, 2)
librosa.display.specshow(chroma_smooth[idx], y_axis='chroma', x_axis='time')
plt.colorbar()
plt.ylabel('Median-filtered')
Expand All @@ -151,21 +149,18 @@
# A final comparison between the CQT, original chromagram
# and the result of our filtering.
plt.figure(figsize=(12, 8))
plt.subplot(3,1,1)
plt.subplot(3, 1, 1)
librosa.display.specshow(librosa.amplitude_to_db(C, ref=np.max)[idx],
y_axis='cqt_note', bins_per_octave=12*3)
plt.colorbar()
plt.ylabel('CQT')
plt.subplot(3,1,2)
plt.subplot(3, 1, 2)
librosa.display.specshow(chroma_orig[idx], y_axis='chroma')
plt.ylabel('Original')
plt.colorbar()
plt.subplot(3,1,3)
plt.subplot(3, 1, 3)
librosa.display.specshow(chroma_smooth[idx], y_axis='chroma', x_axis='time')
plt.ylabel('Processed')
plt.colorbar()
plt.tight_layout()
plt.show()



39 changes: 20 additions & 19 deletions examples/plot_hprss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
This notebook illustrates how to separate an audio signal into
its harmonic and percussive components.
We'll compare the original median-filtering based approach of `Fitzgerald, 2010 <http://arrow.dit.ie/cgi/viewcontent.cgi?article=1078&context=argcon>`_
We'll compare the original median-filtering based approach of
`Fitzgerald, 2010 <http://arrow.dit.ie/cgi/viewcontent.cgi?article=1078&context=argcon>`_
and its margin-based extension due to `Dreidger, Mueller and Disch, 2014
<http://www.terasoft.com.tw/conf/ismir2014/proceedings/T110_127_Paper.pdf>`_.
Expand Down Expand Up @@ -45,25 +46,25 @@

plt.figure(figsize=(12, 8))

plt.subplot(3,1,1)
plt.subplot(3, 1, 1)
librosa.display.specshow(librosa.amplitude_to_db(D, ref=rp), y_axis='log')
plt.colorbar()
plt.title('Full spectrogram')

plt.subplot(3,1,2)
plt.subplot(3, 1, 2)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic, ref=rp), y_axis='log')
plt.colorbar()
plt.title('Harmonic spectrogram')

plt.subplot(3,1,3)
plt.subplot(3, 1, 3)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive, ref=rp), y_axis='log', x_axis='time')
plt.colorbar()
plt.title('Percussive spectrogram')
plt.tight_layout()


#################################################################################
# The default HPSS above assigns energy to each time-frequency bin according to
# The default HPSS above assigns energy to each time-frequency bin according to
# whether a horizontal (harmonic) or vertical (percussive) filter responds higher
# at that position.
#
Expand All @@ -89,52 +90,52 @@
# components, and vocals have been suppressed in the percussive components.
plt.figure(figsize=(10, 10))

plt.subplot(5,2,1)
plt.subplot(5, 2, 1)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic, ref=rp), y_axis='log')
plt.title('Harmonic')
plt.yticks([])
plt.ylabel('margin=1')

plt.subplot(5,2,2)
plt.subplot(5, 2, 2)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive, ref=rp), y_axis='log')
plt.title('Percussive')
plt.yticks([]) ,plt.ylabel('')
plt.yticks([]), plt.ylabel('')

plt.subplot(5,2,3)
plt.subplot(5, 2, 3)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic2, ref=rp), y_axis='log')
plt.yticks([])
plt.ylabel('margin=2')

plt.subplot(5,2,4)
plt.subplot(5, 2, 4)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive2, ref=rp), y_axis='log')
plt.yticks([]) ,plt.ylabel('')

plt.subplot(5,2,5)
plt.subplot(5, 2, 5)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic4, ref=rp), y_axis='log')
plt.yticks([])
plt.ylabel('margin=4')

plt.subplot(5,2,6)
plt.subplot(5, 2, 6)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive4, ref=rp), y_axis='log')
plt.yticks([]) ,plt.ylabel('')
plt.yticks([]), plt.ylabel('')

plt.subplot(5,2,7)
plt.subplot(5, 2, 7)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic8, ref=rp), y_axis='log')
plt.yticks([])
plt.ylabel('margin=8')

plt.subplot(5,2,8)
plt.subplot(5, 2, 8)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive8, ref=rp), y_axis='log')
plt.yticks([]) ,plt.ylabel('')
plt.yticks([]), plt.ylabel('')

plt.subplot(5,2,9)
plt.subplot(5, 2, 9)
librosa.display.specshow(librosa.amplitude_to_db(D_harmonic16, ref=rp), y_axis='log')
plt.yticks([])
plt.ylabel('margin=16')

plt.subplot(5,2,10)
plt.subplot(5, 2, 10)
librosa.display.specshow(librosa.amplitude_to_db(D_percussive16, ref=rp), y_axis='log')
plt.yticks([]) ,plt.ylabel('')
plt.yticks([]), plt.ylabel('')

plt.tight_layout()
plt.show()
27 changes: 12 additions & 15 deletions examples/plot_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Laplacian segmentation
======================
This notebook implements the laplacian segmentation method of
`McFee and Ellis, 2014 <http://bmcfee.github.io/papers/ismir2014_spectral.pdf>`_,
This notebook implements the laplacian segmentation method of
`McFee and Ellis, 2014 <http://bmcfee.github.io/papers/ismir2014_spectral.pdf>`_,
with a couple of minor stability improvements.
Throughout the example, we will refer to equations in the paper by number, so it will be
Expand Down Expand Up @@ -106,13 +106,13 @@
###########################################################
# Plot the resulting graphs (Figure 1, left and center)
plt.figure(figsize=(8, 4))
plt.subplot(1,3,1)
plt.subplot(1, 3, 1)
librosa.display.specshow(Rf, cmap='inferno_r')
plt.title('Recurrence similarity')
plt.subplot(1,3,2)
plt.subplot(1, 3, 2)
librosa.display.specshow(R_path, cmap='inferno_r')
plt.title('Path similarity')
plt.subplot(1,3,3)
plt.subplot(1, 3, 3)
librosa.display.specshow(A, cmap='inferno_r')
plt.title('Combined graph')
plt.tight_layout()
Expand All @@ -123,7 +123,7 @@
L = scipy.sparse.csgraph.laplacian(A, normed=True)


# and its spectral decomposition
# and its spectral decomposition
evals, evecs = scipy.linalg.eigh(L)


Expand All @@ -146,18 +146,17 @@
# Plot the resulting representation (Figure 1, center and right)

plt.figure(figsize=(8, 4))
plt.subplot(1,2,2)
plt.subplot(1, 2, 2)
librosa.display.specshow(Rf, cmap='inferno_r')
plt.title('Recurrence matrix')

plt.subplot(1,2,1)
plt.subplot(1, 2, 1)
librosa.display.specshow(X)
plt.title('Structure components')
plt.ylabel('Time')
plt.tight_layout()



#############################################################
# Let's use these k components to cluster beats into segments
# (Algorithm 1)
Expand All @@ -170,21 +169,20 @@
plt.figure(figsize=(12, 4))
colors = plt.get_cmap('Paired', k)

plt.subplot(1,3,2)
plt.subplot(1, 3, 2)
librosa.display.specshow(Rf, cmap='inferno_r')
plt.title('Recurrence matrix')
plt.subplot(1,3,1)
plt.subplot(1, 3, 1)
librosa.display.specshow(X)
plt.title('Structure components')
plt.ylabel('Time')
plt.subplot(1,3,3)
plt.subplot(1, 3, 3)
librosa.display.specshow(np.atleast_2d(seg_ids).T, cmap=colors)
plt.title('Estimated segments')
plt.colorbar(ticks=range(k))
plt.tight_layout()



###############################################################
# Locate segment boundaries from the label sequence
bound_beats = 1 + np.flatnonzero(seg_ids[:-1] != seg_ids[1:])
Expand All @@ -207,7 +205,7 @@
# And plot the final segmentation over original CQT


#sphinx_gallery_thumbnail_number = 5
# sphinx_gallery_thumbnail_number = 5

import matplotlib.patches as patches
plt.figure(figsize=(12, 4))
Expand All @@ -231,4 +229,3 @@

plt.tight_layout()
plt.show()

Loading

0 comments on commit 7e2659c

Please sign in to comment.