In this laboratory exercise, you will synthesize one of the most common songs of the northern cardinal, a very pretty (and rather vocal) bird that's common in Ithaca. You can listen to this song in the first ten seconds of the recording linked here. Your goal will be to generate a synthesizer that is accurate enough to trick Cornell Ornithology's Merlin Bird ID App.
Fig. 2 shows the spectrogram for the song that we'll be synthesizing (5730 students will also synthesize an additional song, described at the bottom of this webpage). Cardinals and many other songbirds produce almost pure frequency-modulated tones (i.e., they whistle!). As can be seen in the spectrogram below, the cardinal sweeps through frequencies from ~2kHz to ~7kHz. We'll assume that the dominant tones (the darkest lines on the spectrogram) are significantly louder than all other frequencies (the lighter lines). We'll only synthesize these loudest frequencies. The generated song sounds quite realistic under this assumption, as demonstrated in the embedded video farther down the webpage. Your synthesizer will be controlled via a keypad.
There will be a number of interesting outcomes from this laboratory exercise. You'll gain familiarity with all of the key concepts listed below, but you may also notice that something strange occurs in your own brain! After gaining such an intimate understanding the cardinal's song, you may find that you notice birds singing after completing this lab! It's really nice when an engineering project changes the way that you see and appreciate the world around you, I hope that occurs for some of you.
If you'd like to take things farther, you can also synthesize songs for other, more challenging birds like the Baltimore oriole. (If you're lucky, you can spot these in Ithaca too. They're gorgeous and have a very distinctive song). If you're feeling really ambitious, do additive synthesis to generate a Bobolink (might make a good final project!).
Key concepts: Timers, timer interrupts, Direct Digital Synthesis, SPI communication, GPIO, threading/concurrency, digital-to-analog converters, fixed-point arithmetic, keypads, debouncing, curve fitting, numeric integration, code characterization
I've embedded a demo below of the system that you will build.
Experience shows that students prefer these webpages short. For that reason, please find the reading and background materials on the webpages linked below. Please note that the information in these readings will be critical for completing the lab.
- Policy page: This page describes the structure and format of the course, course expectations, and grading policies.
- Course demo code: Familiarize yourself with the layout of this repository, and the examples that it contains.
- Building demo code: This webpage describes how to download and build the course demo code on the laboratory computers. If you'd like to setup the build environment on your own machine, see here for Windows, here for Mac, and here for Linux.
- C/C++ SDK architecture for RP2040: This webpage describes the organization of the C SDK.
- Using the C SDK: This webpage provides a brief practical introduction to the C SDK by means of a simple example.
- Audio examples of incremental complexity: In this lab, as in all labs, you are provided with demo code from which to start your assignment. This repository contains a sequence of example projects which incrementally build to the demo code from which you should start your assignment. The documentation for each of these examples is meant to be read in order.
- Keypad: Your birdsong synthesizer will be cotrolled via a keypad. Please see this page for examples of and information about the keypad that we will be using, and clues about a debouncing state machine.
- SPI Communication: The digital-to-analog converter that we are using is an SPI device. This webpage describes SPI communication. Understanding these concepts will make configuring the SPI channel on the RP2040 much easier.
- RP2040 Datasheet: Sections on GPIO, SPI, Timer, and UART
- C SDK hardware API: Same sections as above
- DAC datasheet: Datasheet for the MCP4822 12-bit DAC that we'll be using in this lab.
- Direct digital synthesis (DDS): This is the algorithm that we will use for sound production. This is a powerful algorithm, a good one to understand deeply.
- Birdsong synthesis via DDS: This webpage deconstructs the Northern cardinal's song, and synthesizes it via DDS.
- How and why birds sing: A Cornell Ornithology webpage about birdsong.
- More information about Northern Cardinals: A Cornell Ornithology webpage about cardinals.
- Fast Fourier Transform: How does Merlin generate those spectrograms? It does so by computing FFT's! This webpage describes the Cooley-Tukey FFT.
Note that these checkpoints are cumulative. In week 2, for example, you must have also completed all of the requirements from week 1.
In this example code, direct digital synthesis is used to generate a pure sine wave "beep". Connect the DAC to the Pico per the #define
statements at the top of the source code and the DAC datasheet, build the code, and load it onto the Pico. Please note that different manufacturers use different names for SPI signals! Here are the correct connections:
3.3V(OUT)
-->VDD
GND
-->VSS
PIN_CS
--> $\overline{\text{CS}}$
PIN_SCK
-->SCK
PIN_MOSI
-->SDI
LDAC
--> $\overline{\text{LDAC}}$
Confirm that the waveforms are being generated by the DAC with the oscilloscope, then use a 3.5 mm audio socket so that you can plug in speakers and listen to the generated beeps.
Write a C program that meets the following requirements . . .
When you demonstrate the program to Hunter or a TA, you will be asked to play back a sequence of sounds which simulates the birdsong in Fig. 2. If you're able to trick the Merlin App, you will earn a handshake. You will also be asked to play back a random sequence of swoops/chirps/silences that Hunter or the TA uses the keypad to generate. At no time during the demo can you reset or reprogram the RP2040. Finishing a checkpoint does NOT mean you can leave lab early!
In addition to the above requirements for 4760, 5730 students should also . . .
When you demonstrate the program to Hunter or a TA, you will be asked to play back a sequence of sounds which simulates the birdsongs in Fig. 2 and Fig. 3. If you're able to trick the Merlin App, you will earn a handshake. You will also be asked to play back a random sequence of swoops/chirps/silences that Hunter or the TA uses the keypad to generate. At no time during the demo can you reset or reprogram the RP2040. Finishing a checkpoint does NOT mean you can leave lab early!
Your written lab report should include the sections mentioned in the policy page, and: