comp2300 Assignment1 Part 1 Solved

30.00 $

Category:

Description

Rate this product

This assignment has two parts: in Part 1, you need to generate a specific (simple) signal to be output through your discoboard’s 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.

3.5mm Headphone Jack

To complete this assignment you will need to have a solid understanding of the course material provided in the week 1week 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

synthesizer (or synth for short) is an electronic device which produces a musical sound. It’s 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 music—check out Kraftwerk’s The Robots.

In this assignment, you’re going to turn your discoboard into a synthesizer. The maths and physics behind this aren’t rocket science, it’s 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 idea—you 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 discoboard’s audio hardware (i.e. the headphone jack) is a little bit fiddly, so for this assignment we’ve provided some setup code to get you up and running (optionally, check out the lib/audio.S and lib/clock.S files if you’re 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:

  1. The template repo contains two git branches: part-1 and part-2 (initially, they both point to the same commit). Both of these branches have all the setup code you need—the only difference between them will be the commits you make in doing your assignment. So, you should write your Part 1 code on the part-1 branch, and your Part 2 code on the part-2 branch.
  2. Although your code still goes in main.S, the template includes a couple of functions for you to call from your code: init and BSP_AUDIO_OUT_Play_Sample.
    • When you bl (branch with link) to the init function your program will execute the setup code to turn on your discoboard’s headphone jack. Your code should call this function once at the start.
    • When you bl to the BSP_AUDIO_OUT_Play_Sample function, whatever is in the lowest (least-significant) 16 bits of r0 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 in r0 should be to generate the right signal is up to you!

If this is a bit confusing, head down to the FAQ section on this page—there’s 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: Square wave

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 picture—the square wave signal is actually just a sequence of dots—these are the values which you’ll 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 you’re doing it right? You’ll 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 well—just listen to the opening square wave synth line in Van Halen’s 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 trough–as 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 0x80000x7FFF 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 ears—the discoboard can make a pretty loud signal. It’s 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:

Marks for Part 2 will be awarded for a design document describing what signal you’re 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 it’s ok if you don’t 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 you’ve 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.

  • comp2300-2021-assignment-1-part-1-ynjqgr.zip