Lab 6: Tremolo/Beats Effects 2#
Last updated 8/12/2024
00. Content #
Mathematics#
Laws of sines/cosines
Programming Skills#
Type here
Embedded Systems#
N/A
0. Required Hardware #
headphones
Write your name and email below:
Name: me
Email: me @purdue.edu
1. Building a Voice Recorder #
Before we begin, we need to install a library which will help us in manipulating audio with python. We will be using PyAudio for this purpose as it is easy to use and works on a variety of different environments.
Installation instructions for PyAudio can be found from here.
To explore more in detail about PyAudio and its features, you could refer the API docementation for PyAudio
For Recording Audio with Python, we have to do the following:
Open a data stream to get audio data frame from microphone
Iterate over the stream and append each frame to a list of frames.
Stop and close the data stream.
Save the data frames as a .wave file.
voice_recorder.py is implemented following the above pseudo code. It records 5s of mono channel audio and saves it as my_recording.wave
Exercise 1#
Run voice_recorder.py and report your observations.
Exercise 2#
Modify the voice_recorder.py to record a 10s audio recording of yourself and save it as <yourname>_voice_clip.wave
Exercise 3#
Write a Python code to play the recorded audio using PyAudio.
Hint: This script should:
Open the wave file recorded by voice_recorder.py.
Retrieve the audio settings from the wave file (format, channels, rate). wave.open
Opens an audio stream for playback. API docementation for PyAudio
Play the audio data back in chunks
Close the stream
Exercise 4 #
In your script, modulate your recording with the triangular wave and play the modulated sound. Change the triagular wave frequency and play the resulting modulated sound. Compare what happens when the frequency is very low (<20Hz) and when it is very high (20-20kHZ). Paste in your modified code.
Exercise 5 #
In your script, modulate your recording with a square wave and play the modulated sound. Paste in your modified code.
Create your own modulation effect#
Exercise 6 #
Create the signal \(x(t)\) a recording of you saying “B’Euler up!”.
Exercise 7 #
Create an original periodic signal \(c_1(t)\). Use it to modulate \(x(t)\) and play the resulting modulated signal.
Exercise 8 #
Create another original periodic signal \(c_2(t)\) with the same frequency as \(c_1(t)\). Use it to modulate \(x(t)\) and play the resulting modulated signal.
Exercise 9 #
Play the signal \(x(t) c_1(t) c_2(t)\). Describe that signal.
Exercise 10 #
Play the signal \(x(t) (c_1(t) + c_2(t)) \). Describe that signal.
2. Instrument Tuning with “beats” #
Orchestra players are well familiar with the tremolo effect, which they call “beats”, as they use it to tune their instruments.
The idea is the following: if two instruments play the same note, then the sound produced corresponds to the addition of two periodic signals. For simplicity, let’s assume that the first instrument plays a cosine wave at a frequency \(f_a\):
and let’s assume that the second instrument plays another cosine wave at a similar (but not equal) frequency \(f_b\):
Then the combined sound is
Exercise 11 #
Assume \(f_a=400 Hz\) and \(f_b=410 Hz\). Write \(x(t)\) as a product of two sine waves.
To understand what happens in general, we replace \(f_1\) by \(\frac{f_a+f_b}{2}\) and \(f_2\) by \( \frac{f_b-f_a}{2}\) in the equation above. This gives us
In other words, two cosine waves with a similar frequency added together correspond to modulating a sine wave at the average frequency with a (carrier) sine wave at half the frequency difference. If \(f_1\) and \(f_2\) are close frequencies in the audible range, then their difference is small. Therefore, one expects a tremolo effect to occur when the instruments are not in tune.
Exercise 12#
Suppose the signals \( \sin \left( 2 \pi 440 t \right) \) (a middle A) and the signal \(\sin \left( 2\pi 442 t\right)\) are added together. What would be the frequency of the carrier (i.e., the beat/tremolo frequency)? Play the added signals: do you hear the beats? Plot the modulated signal: is it the same? Plot a few cycles of each signal (added and modulated) and compare.
Exercise 13 #
Can two musicians listening to the added sounds determine the difference between the frequencies of their instruments? If so, how? If not, why not.
Exercise 14#
Explain how two musicians can use the beat effect to tune an out-of-tune instrument, assuming one musician has in-tune instrument at an 440 Hz A.
Reflection #
Do not skip this section! Lab will be graded only on completion of this section.
1. What parts of the lab, if any, do you feel you did well?
2. What are some things you learned today?
3. Are there any topics that could use more clarification?
4. Do you have any suggestions on parts of the lab to improve?