Microphone controller

The microphone controller handles the low-level details of receiving sound samples from the DE2-115's microphone input. The microphone controller is implemented in microphone.v. You will also need i2c_config.v, which configures the DE2-115's audio codec chip, the Wolfson WM8731 codec (codec stands for encoder/decoder).

microphone_command and microphone_response implement the standard I/O protocol. There are no command parameters. The response parameter is microphone_sample, which contains the most recent 32-bit sound sample received by the microphone.

The microphone controller takes input from the microphone at an 8 KHz sampling rate. A new sample overwrites the current sample, even if the E100 has not yet read the current sample. After the E100 reads the current sample via the I/O protocol, the microphone controller will not respond again until there is a new sample from the microphone.

You may use any microphone that has a 3.5mm plug. If your smartphone has a 3.5mm headphone jack (or adapter to such a jack), we recommend using the microphone device from your smartphone. Connect the headphone jack of your smartphone to the pink MIC connector on the DE2-115 board (or your computer, if you're using ase100) via a 3.5mm male-to-male audio cable, then use an app (e.g., Megaphone Free for iOS or Megaphone for Android) that sends the smartphone's microphone input to its speaker.

If you'd rather not use your smartphone, another option is to use the microphone that is included on a Sony DCR-TRV22 camcorder. Insert the right-angle 3.5mm jack of an AV cable into the camcorder's AUDIO/VIDEO connector, and insert the gold 3.5mm plug (which is attached to the red or white RCA plug of the AV cable) into the pink MIC connector on the DE2-115 board. Set the camcorder's mode dial to memory. You'll usually need to connect the power adapter, since the batteries don't hold much charge. See the camcorder manual for more details.

You can also use a computer headset, but these microphones tend to have very poor sensitivity.

ase100 simulates the microphone controller accurately enough for you to test your device driver and to run assembly-language programs. If ase100 can access your computer's audio device, it reads microphone samples from the computer's microphone.

Many computers run ase100 too slowly to read sound in real time. In this case, you can direct ase100 to read microphone samples from a WAV file. The WAV file must be in PCM format, with 32-bit, mono samples at an 8 KHz sampling rate (such as the concert A file given in the handout on digital audio). You can use the sox program on Linux to convert a file to the right format. For example, run the following command to convert file1.wav to file2.wav:

sox file1.wav -4 -s -c 1 -r 8000 file2.wav

Lab 7 task

Write a device driver for the microphone controller that a program can call to read a sound sample from the microphone controller. Then, write a test program that continuously reads the samples from the microphone and displays the minimum and maximum values for the sound samples it has received from the microphone onto the hexdigits.

Optional: If one of your teammates has written a driver for the speaker, try sending the values you read from the microphone to the speaker.