Skip to content

Commit e1c0d0a

Browse files
alexarjeclaude
andcommitted
Update tutorial notebook: fix stale API, add new audio methods
- thresh= -> threshold= in motiongrams examples - cols= -> columns= in grid examples (matches renamed parameter) - Add MFCC, tempo/beat-tracking, beat statistics, and chromagram sections to the audio analysis chapter - Refresh the audio methods overview list Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2df0373 commit e1c0d0a

1 file changed

Lines changed: 95 additions & 9 deletions

File tree

musicalgestures/MusicalGesturesToolbox.ipynb

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@
19681968
}
19691969
],
19701970
"source": [
1971-
"video_grid = video.grid(height=300, rows=1, cols=9)\n",
1971+
"video_grid = video.grid(height=300, rows=1, columns=9)\n",
19721972
"video_grid.show(mode='notebook')"
19731973
]
19741974
},
@@ -2023,7 +2023,7 @@
20232023
}
20242024
],
20252025
"source": [
2026-
"video_grid = video.grid(height=300, rows=3, cols=3)\n",
2026+
"video_grid = video.grid(height=300, rows=3, columns=3)\n",
20272027
"video_grid.show(mode='notebook')"
20282028
]
20292029
},
@@ -2344,7 +2344,7 @@
23442344
}
23452345
],
23462346
"source": [
2347-
"video_grid = history.grid(height=300, rows=3, cols=3)\n",
2347+
"video_grid = history.grid(height=300, rows=3, columns=3)\n",
23482348
"video_grid.show(mode='notebook')"
23492349
]
23502350
},
@@ -3265,7 +3265,7 @@
32653265
}
32663266
],
32673267
"source": [
3268-
"video.motiongrams(thresh=0.0)[0].show(mode='notebook')"
3268+
"video.motiongrams(threshold=0.0)[0].show(mode='notebook')"
32693269
]
32703270
},
32713271
{
@@ -3328,7 +3328,7 @@
33283328
}
33293329
],
33303330
"source": [
3331-
"video.motiongrams(thresh=0.1)[0].show(mode='notebook')"
3331+
"video.motiongrams(threshold=0.1)[0].show(mode='notebook')"
33323332
]
33333333
},
33343334
{
@@ -3391,7 +3391,7 @@
33913391
}
33923392
],
33933393
"source": [
3394-
"video.motiongrams(thresh=0.9)[0].show(mode='notebook')"
3394+
"video.motiongrams(threshold=0.9)[0].show(mode='notebook')"
33953395
]
33963396
},
33973397
{
@@ -4297,8 +4297,14 @@
42974297
"source": [
42984298
"- `waveform()`: Renders a figure showing the waveform of the video/audio file.\n",
42994299
"- `spectrogram()`: Renders a figure showing the mel-scaled spectrogram of the video/audio file.\n",
4300-
"- `descriptors()`: Renders a figure of plots showing spectral/loudness descriptors, including RMS energy, spectral flatness, centroid, bandwidth, rolloff of the video/audio file.\n",
4301-
"- `tempogram()`: Renders a figure with a plots of onset strength and tempogram of the video/audio file."
4300+
"- `tempogram()`: Renders a figure with plots of onset strength and tempogram of the video/audio file.\n",
4301+
"- `descriptors()`: Renders a figure of spectral/loudness descriptors (RMS energy, flatness, centroid, bandwidth, rolloff).\n",
4302+
"- `mfcc()`: Renders a figure of the Mel-frequency cepstral coefficients (timbre features).\n",
4303+
"- `tempo()`: Estimates tempo and beat positions, returning beat times, inter-beat intervals and beat regularity.\n",
4304+
"- `beat_statistics()`: Renders circular statistics of beat-timing consistency.\n",
4305+
"- `chromagram()`: Renders a figure mapping audio energy onto the 12 pitch classes over time.\n",
4306+
"- `hpss()`: Separates and plots the harmonic and percussive components of the audio.\n",
4307+
"- `ssm()`: Computes a self-similarity matrix on audio (or video) features.\n"
43024308
]
43034309
},
43044310
{
@@ -4580,6 +4586,86 @@
45804586
"audio.descriptors()"
45814587
]
45824588
},
4589+
{
4590+
"cell_type": "markdown",
4591+
"metadata": {},
4592+
"source": [
4593+
"### MFCCs\n",
4594+
"\n",
4595+
"[Mel-frequency cepstral coefficients](https://en.wikipedia.org/wiki/Mel-frequency_cepstrum) (MFCCs) compactly describe the spectral envelope (timbre) of a sound over time and are widely used as features for audio classification and similarity."
4596+
]
4597+
},
4598+
{
4599+
"cell_type": "code",
4600+
"execution_count": null,
4601+
"metadata": {},
4602+
"outputs": [],
4603+
"source": [
4604+
"audio = mg.MgAudio(pianist)\n",
4605+
"audio.mfcc()"
4606+
]
4607+
},
4608+
{
4609+
"cell_type": "markdown",
4610+
"metadata": {},
4611+
"source": [
4612+
"### Tempo and beat tracking\n",
4613+
"\n",
4614+
"`tempo()` estimates the tempo and beat positions and renders the waveform with beat markers. Numeric results are available in the returned figure's `.data` dictionary."
4615+
]
4616+
},
4617+
{
4618+
"cell_type": "code",
4619+
"execution_count": null,
4620+
"metadata": {},
4621+
"outputs": [],
4622+
"source": [
4623+
"audio = mg.MgAudio(pianist)\n",
4624+
"beats = audio.tempo()\n",
4625+
"\n",
4626+
"print(f\"Tempo: {beats.data['tempo']:.1f} BPM\")\n",
4627+
"print(f\"Number of beats: {len(beats.data['beat_times'])}\")\n",
4628+
"print(f\"Beat regularity: {beats.data['beat_regularity']:.1%}\")"
4629+
]
4630+
},
4631+
{
4632+
"cell_type": "markdown",
4633+
"metadata": {},
4634+
"source": [
4635+
"### Beat statistics\n",
4636+
"\n",
4637+
"`beat_statistics()` fits an ideal isochronous grid to the detected beats and visualises how each beat deviates from it — a polar phase histogram plus a millisecond-deviation time series. This reveals whether a performer rushes, drags, or keeps steady time (requires at least four beats)."
4638+
]
4639+
},
4640+
{
4641+
"cell_type": "code",
4642+
"execution_count": null,
4643+
"metadata": {},
4644+
"outputs": [],
4645+
"source": [
4646+
"audio = mg.MgAudio(pianist)\n",
4647+
"audio.beat_statistics()"
4648+
]
4649+
},
4650+
{
4651+
"cell_type": "markdown",
4652+
"metadata": {},
4653+
"source": [
4654+
"### Chromagrams\n",
4655+
"\n",
4656+
"A [chromagram](https://en.wikipedia.org/wiki/Chroma_feature) maps audio energy onto the 12 pitch classes (C, C#, D, …, B) over time, which is useful for analysing harmony and chord progressions."
4657+
]
4658+
},
4659+
{
4660+
"cell_type": "code",
4661+
"execution_count": null,
4662+
"metadata": {},
4663+
"outputs": [],
4664+
"source": [
4665+
"audio = mg.MgAudio(pianist)\n",
4666+
"audio.chromagram()"
4667+
]
4668+
},
45834669
{
45844670
"cell_type": "markdown",
45854671
"metadata": {
@@ -5543,4 +5629,4 @@
55435629
},
55445630
"nbformat": 4,
55455631
"nbformat_minor": 4
5546-
}
5632+
}

0 commit comments

Comments
 (0)