Hooking up the HW to make and input sound

For this task, you are going to hook up your HW so that you can record and play sound.

Prepare for lift off

Reassemble your BeagleBone Black. Plug in the LAN cable. Connect the powered USB hub and plug in the microphone/speaker USB device. Also plug in your speakers and the microphone.

Plug in the power. You can execute all of the following instructions in one of the several ways.

If you are still connected to the display, keyboard, and mouse, log in to the board, use startx to start Xfce (your windowing system), and then open a terminal window.

If you are only connected via LAN, you can do all of this using an SSH terminal window, so as soon as your board flashes that it has power (look for the heartbeat LED), open up an SSH terminal window using PuTTY or some similar terminal emulator. Once the terminal window comes up, log in with your username and password. Now type in cat /proc/asound/cards. You should see the following response:

Prepare for lift off

Notice that the system thinks there are two possible audio devices. The first is the HDMI sound device, and the second is your USB audio plugin. Now you can use the USB card to both create and record sound.

Engage thrusters

First, let's play some music to test that the USB sound device is working. You'll need to configure your system to look for your USB card and use it as the default to play and record sound. To do this, you'll need to add a couple of libraries to your system. The first are some ALSA libraries. ALSA stands for Advanced Linux Sound Architecture, and it is going to enable your sound system on the BeagleBone Black.

First install the two libraries associated with ALSA by typing sudo apt-get install alsa-base alsa-utils. Then also install some files that help provide the sound library by typing sudo apt-get install libasound2-dev.

If your system already contains these libraries, Linux will simply tell you that they are already installed or that they are up-to-date. After installing both libraries, reboot your BeagleBone Black. It takes time, but the system needs a reboot after new libraries or HW are installed.

Now you'll use an application called alsamixer to control the volume of both the input and the output of your USB sound card. Type alsamixer at the prompt. You should see a screen that looks like the following:

Engage thrusters

Press F6 and select your USB sound device using the arrow keys. You should see a screen that looks like the following:

Engage thrusters

You can use the arrow keys to set the volume for both the speakers and the microphone. Use the m key to unmute the microphone. In the preceding screenshot MM is mute and is unmute. Make sure your settings look like the following:

Engage thrusters

Let's make sure your system knows about your USB sound device. At the prompt, type aplay –l. You should see the following:

Engage thrusters

If this did not work, try sudo aplay –l. Once you have added the libraries, you'll need to add a file. You are going to add a file in your home directory with the name .asoundrc. This will be read by your system and used to set your default configuration. To do this:

  1. Open the file named .asoundrc using your favorite editor.
  2. Type in pcm.!default sysdefault:Device.
  3. Save the file.

The file should look like the following:

Engage thrusters

This will tell the system to use your USB device as default. Once you have completed this, reboot your system again.

Now, you'll play some music. To do this, you need a sound file and a way to play it. I used WinScp from my Windows machine to transfer a simple .wav file to the Music subdirectory on my BeagleBone Black. You are going to use an application called aplay to play your sound. Go to the Music directory and you should see the music file by simply typing ll (list long, this will give you all the details of your files). Mine looks like the following:

Engage thrusters

Now type aplay Dance.wav to see if you can play music using the generic aplay music player. You will see, and hopefully hear, the following result:

Engage thrusters

If you aren't hearing any music, check the volume you set with alsamixer and the power to your speaker. Also, aplay can be a bit finicky with the type of files it accepts, so you may have to try different .wav files until it will play. One more thing to try, if the system doesn't seem to know about the program, is to type sudo aplay Dance.wav.

Now that you can play the sound, let's record some sound. To do this, you're going to use the arecord program. At the prompt, type arecord -d 5 -r 48000 test.wav. This will record five seconds of sound at a 48000 Hz sample rate. Once you have typed the command, either speak into the microphone or make some other recognizable sound. You should see the following in the terminal:

Engage thrusters

Once you create the file, play it with aplay. Type aplay test.wav, and you should hear the recording. If you can't hear your recording, check alsamixer to make sure your speakers and microphone are both unmuted.

Objective complete – mini debriefing

Now you can play music or other sound files using your BeagleBone Black. You can change the volume of your speaker and record your voice or other sounds on the system. You're ready for the next step.

Classified intel

Ubuntu offers a number of different music and sound recording program options that are more full-featured than aplay and arecord. If you'd like, spend some time researching them on the Internet and install them onto your system. Several work well with your Xfce installation as well, although you may need to configure your windowing system to know about and use your USB sound device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.173.238