This assignment has two parts: in Part 1, you need to generate a specific (simple) signal to be output through your discoboards headphone jack. In Part 2, you get to be creative and program your discoboard to make a more interesting sound. Your discoboard has a standard 3.5mm headphone jack, which means that any 3.5mm headphones will work.
To complete this assignment you will need to have a solid understanding of the course material provided in the week 1, week 2 and week 3 labs. If you have not completed these or do not understand the content then it is strongly recommended that you go and complete these labs before starting on the assignment.
Background
A synthesizer (or synth for short) is an electronic device which produces a musical sound. Its called a synthesizer because while an acoustic instrument uses a resonating cavity or string to produce natural sound waves, the synth uses digital logic to calculate and produce a synthetic signal which is amplified electronically and turned into a soundwave through a loudspeaker.
Although computers have been used for making music since they were first invented, it was in the 70s that improvements in technology led to an explosion of digital devices like synths in popular musiccheck out Kraftwerks The Robots.
In this assignment, youre going to turn your discoboard into a synthesizer. The maths and physics behind this arent rocket science, its just generating values in simple patterns and writing them to a special register one-after-the-other. The key part is that it involves controlling the execution of your program in time. This might be a fairly new ideayou might not be used to worrying about exactly how fast your program runs, and if you do care about it you only care about making it run faster, not about making sure that the instructions run at specific times.
Getting started
The initialisation sequence for the discoboards audio hardware (i.e. the headphone jack) is a little bit fiddly, so for this assignment weve provided some setup code to get you up and running (optionally, check out the lib/audio.S
and lib/clock.S
files if youre curious).
Fork & clone the assignment 1 template repo and open it up in VSCode as usual. There are two things you need to know about the setup code:
- The template repo contains two git branches:
part-1
andpart-2
(initially, they both point to the same commit). Both of these branches have all the setup code you needthe only difference between them will be the commits you make in doing your assignment. So, you should write your Part 1 code on thepart-1
branch, and your Part 2 code on thepart-2
branch. - Although your code still goes in
main.S
, the template includes a couple of functions for you to call from your code:init
andBSP_AUDIO_OUT_Play_Sample
.- When you
bl
(branch with link) to theinit
function your program will execute the setup code to turn on your discoboards headphone jack. Your code should call this function once at the start. - When you
bl
to theBSP_AUDIO_OUT_Play_Sample
function, whatever is in the lowest (least-significant) 16 bits ofr0
will be played through the headphone jack (treated as a signed 16-bit number as shown in the picture). Your code should call this function repeatedly to generate the audio signal. Calculating exactly what that data inr0
should be to generate the right signal is up to you!
- When you
If this is a bit confusing, head down to the FAQ section on this pagetheres a lot of answers which should help you understand. Furthermore, check out the sitewide FAQ for answers that apply more generally to all assignments.
Part 1
In the first part of the assignment you need to write a program which produces an audible constant-amplitude square wave with a frequency of 440Hz (440 cycles per second) and a duty cycle out of the headphone jack.
All of these properties are shown in the this picture:
Using the init
function provided, the audio output is configured to use signed 16-bit values for the signal, so a value of 0x8000
represents the bottom of the signal range, 0x0
represents the middle and 0x7FFF
is the top. The output sample rate (the rate at which these 16-bit values come out of the headphone jack as sound) is 48kHz. This is all the info you need to put the right sequence of values in r0
and branch to BSP_AUDIO_OUT_Play_Sample
to make the music come out of the headphones.
You can see the sample-by-sample nature of digital audio in the picturethe square wave signal is actually just a sequence of dotsthese are the values which youll output through your r0
register and BSP_AUDIO_OUT_Play_Sample
function. Remember that the value in r0
immediately before this branch will be the one that comes out the headphone jack.
How will you know if youre doing it right? Youll need to plug your headphones in and listen! Your square wave should sound like a constant-pitch, slightly buzzy sound. Like below:
You can hear a normal square wave (without a 20% duty cycle, and of whatever pitch you want) at onlinetonegenerator.com.
Square waves (and similar waveforms) are quite popular in music as lead sounds, since they cut through the accompaniment so welljust listen to the opening square wave synth line in Van Halens Jump.
You might be asking yourself: What is a duty cycle?. Duty cycle refers to the percentage of the time the signal is on in one cycle (the period) of the wave. This leads to (as shown in the diagram above), a much shorter peak than the troughas opposed to a normal square wave, when the peak and trough are of equal length (a duty cycle of 50%!).
For Part 1, marks will be awarded for:
- making a sound
- whether the sound has the correct frequency
- whether the sound has a peak-to-peak amplitude of at least half the full
0x8000
0x7FFF
dynamic range (as depicted in the picture) - how clean the square wave signal is (i.e. how close is it to the picture above)
- how close the frequency of the wave is to 440Hz (to achieve the closest frequency, and possibility of full marks for this part, you will need to average over many periods)
- whether or not it has a duty cycle of 20% (to achieve the possibility of full marks for this part, you should have a value somewhere in your code we can tweak to change the duty cycle to some other value)
- code structure & readability (including comments)
If you would like to view a plot of your output, then you can follow the instructions on the resources page to use the sample plotter.
Be careful generating signals with your earphones in your earsthe discoboard can make a pretty loud signal. Its a good idea to hit run on your program with your headphones out of your ears, and then carefully put them in your ears afterwards.
Part 2
In the second part, you need to generate a different signal (i.e. not a constant-frequency square wave). You can pick any periodic signal you like as long as it is audible, but here are a few ideas, in approximate order of increasing difficulty:
- a different base waveform from the square wave you made in Part 1 (e.g. sawtooth, triangle)
- a simple signal with some aspect (e.g. frequency, amplitude, waveform) which changes over time
- the weighted sum of multiple simpler waveforms (this is called additive synthesis)
- the n-sample moving-average filter of a simple signal
- FM synthesis
- wavetable synthesis
Marks for Part 2 will be awarded for a design document describing what signal youre generating and how you implemented it in ARM assembly language. You need to explain the what, how and why (design, implementation, and analysis) of what you have done. Although its ok if you dont do something super-complex, we do take the sophistication of what you have done into account.Using images/diagrams in this document to help explain what youve done is encouraged. Your design document must be in pdf format (2 pages of content + appendix + references) with the filename design-document.pdf
in the top-level folder on the part-2
branch.
Rate this product
Reviews
There are no reviews yet.