concept musical note in category python

appears as: musical notes, musical note
Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11.

Interesting sounds like musical notes have sound waves with repeating patterns, like the one shown in figure 13.2. The rate at which the function repeats itself is called the frequency and tells how high or low the musical note sounds. The quality, or timbre, of the sound is controlled by the shape of the repeating pattern; for instance, whether it sounds more like a violin, a trumpet, or a human voice.

Before we do that, however, we need to cover the basic building blocks: sound waves and musical notes. I start by showing you how to use Python to turn a sequence of numbers, representing a sound wave, into a real sound coming out of your speakers. To make a sound corresponding to a function, we extract some y values from the graph of the function and pass these to the audio library as an array. This is a process called sampling (figure 13.3).

Figure 13.3: Starting with the graph of a function f(t) (left) and sampling some of the y values (right) to send to an audio library

The main sound wave functions we’ll use are periodic functions, whose graphs are built from the same repeating shape. Specifically, we’ll use sinusoidal functions, a family of periodic functions including sine and cosine that produce natural-sounding musical notes. After sampling them to turn them into sequences of numbers, we’ll build Python functions to play musical notes.

Once we can produce individual notes, we’ll write Python code to help us combine different notes to create chords and other complex sounds. We’ll do this by adding the functions defining each of the sound waves together. We’ll see that combining a few musical notes can make a chord, and combining dozens of musical notes together can produce some quite interesting and qualitatively dissimilar sounds.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest