AcousticLaptop
From CSL Wiki
Contents |
Introduction
This page describes how to prepare and install the acoustic ensbox software on a laptop, and then get started recording/localizing/experimenting.
If this scares you at all, you can use the live cd we have created, which runs like a normal ubuntu live cd, but has emstar and the relevant libraries already installed. The live cd is available here.
Full Acoustic Laptop Prerequisites
You'll need several things to be able to get one acoustic laptop up and running, and you'll need three nodes (either acoustic laptops or ensboxes) in order to get timesync working (and thus localize the three nodes). At present, the only distribution supported is Ubuntu 6.06 LTS, due to its (almost comprehensive) alsa support, but the advantages are great - you don't need to recompile and install a new kernel to make the ensbox software work, so you'll have a completely functioning laptop that you can convert into an acoustic box when you need to.
For each laptop, you'll need:
- 2 free pcmcia slots on the laptop (this is a deal breaker, because not that many new models have 2 pcmcia slots)
- 1 VXpocket440 pcmcia sound card like this
- 1 SMC 802.11 wireless pcmcia card like this
- 1 VXP dongle (this connects the sound card to everything)
- A sensor board, either V1 or V2 (microphone array + speakers)
- A copy of Dapper Drake (Ubuntu 6.06 LTS) live install CD
Standalone Record-only Laptop
It is possible to create a stand-alone, record only laptop which is just used to record four channel audio from one source.
If you are making this laptop, then you don't need to perform any of the network card steps.
You need to run a special .run file before running the record_from executable (mentioned in the troubleshooting section).
This script is located at:
emstar/sensors/audiod/testtabs/standalone-vxp-laptop.run
You must run this before you start using the record_from executable.
Creating the Acoustic Laptop
This installation assumes you are starting from scratch, in that you don't have Ubuntu 6.06 and an old Emstar checkout on your machine. If you do, then most of the instructions will still apply, but you may need to make sure your Emstar checkout is up to date.
There are several steps involved in installing the acoustic laptop port:
- Install Dapper Drake (Ubuntu 6.06)]
- Install all the required packages to compile Emstar
- Checkout Emstar
- Patch and install the VXPocket440 drivers (for the sound card)
- Patch and install the hostap drivers (for the wireless card)
- Compile Emstar
Install Dapper Drake
You need to download the Dapper Drake ISO, burn it, and install it on your machine. It should be noted if you're using a laptop which has less than 192MB RAM, then you should use the text installer available on the Ubuntu 6.06 Alternate CD (not the live install CD, which is the standard). This is because with less than 192MB the live will not work correctly or at all.
Once it is installed, you need to use a package manager to get a whole bunch of packages, each of which is needed to allow emstar to compile correctly. These are listed below (as well as a line or two you can cut and paste into your terminal instead). Please note that you need to enable the multiverse and universe repositories before you do this (for later steps).
In order to enable the correct repositories, replace the sources.list file in /etc/apt/ with the one linked to here, or make sure that your /etc/apt/sources.list file contains (at least) the same text.
when you make a change to the sources.list file, you need to run
apt-get update
to refresh the repository cache on your system with the new repositories you have added.
To install the required libraries, here is a list of apt-get install commands you can cut and paste:
sudo apt-get install libc6-dev libglib2.0-dev pkg-config bison flex libgsl0 libgtk2.0-dev libcurl3-dev sudo apt-get install libreadline5-dev libflac-dev libsndfile1-dev sudo apt-get install libgsl0-dev g++ libasound2-dev libstdc++2.10-glibc2.2 cvs sudo apt-get install audacity sox openssh-server nfs-kernel-server
Required packages (for reference):
libc6-dev libglib2.0-dev pkg-config bison flex libgsl0 libgtk2.0-dev libcurl3-dev libreadline5-dev libflac-dev libsndfile1-dev libgsl0-dev g++ libasound2-dev libstdc++2.10-glibc2.2 cvs
Also desirable:
audacity sox openssh-server nfs-kernel-server
checkout emstar
At your home directory, type:
cvs -d :pserver:anoncvs@cvs.cens.ucla.edu:/home/cvs/cvsroot login
When asked for a password, just press enter.
cvs -z9 -d :pserver:anoncvs@cvs.cens.ucla.edu:/home/cvs/cvsroot co emstar
This will checkout the current Emstar head revision to your home directory (~/emstar).
TinyOS with Emstar
(If you need to install TinyOS as part of Emstar, you must perform the following steps)
The next thing to do is create a /lecs directory in /usr/local/ (this is used to put nesc and avr into during the following stage)
cd /usr/local sudo mkdir lecs
Next, as per the original Emstar installation instructions, you need nesc and the avr compiler installed.
Download these files to your home directory, and then untar both of them, using the commands:
tar zxvf nesc-1.1-platform.tgz tar zxvf avr-3.3-platform.tgz
This will create a usr/local/lecs tree in your root directory.
Move these files into the /usr/local/lecs directory you created earlier, by typing:
sudo mv usr/local/lecs/avr3.3/ /usr/local/lecs/ sudo mv usr/local/lecs/nesc-1.1/ /usr/local/lecs/
next, add a symlink in emstar/bin/ to make sure the right version of uisp is being used:
cd ~/emstar/bin sudo ln -s uisp-ucb-20031126 uisp
you might also want to add a similar link in /usr/local/lecs/avr3.3/bin/ for if you need to program motes whilst using the laptop
cd /usr/local/lecs/avr3.3/bin/ sudo mv ./uisp ./usip-old sudo ln -s ~/emstar/bin/uisp-ucb-20031126 uisp
after this, you need to add the following lines to your ~/.bashrc file (at the bottom, making sure to leave a newline):
export PATH=$PATH:~/emstar/bin export EMSTAR_ROOT=~/emstar export PATH=/usr/local/lecs/nesc-1.1/bin:/usr/local/lecs/avr3.3/bin:$PATH
To make sure these settings are loaded, restart any open terminal sessions.
Edit the Make.conf file in ~/emstar and set to BUILD_EMTOS variable to 1. This will download TinyOS for you during the Emstar compilation process (later in this document) and compile relevant TinyOS applications in the tos-contrib directory.
patch/install vx drivers (for sound card)
The vxpocket drivers need to be patched and new firmware installed before they can be used properly with the ensbox localization. The most convenient way to do this is with the help of Ubuntu's apt-get/synaptic package manager. What we will do will follow closely the instructions given here and here.
- Use apt-get (or synaptic) to install the following packages (which should be at version 1.0.10 or similar) if they are not already, e.g.:
sudo apt-get install alsa-base alsa-firmware-loaders alsa-utils alsa-source build-essential linux-headers-$(uname -r)
- Make a symbolic link to the linux-headers you just downloaded, by:
sudo ln -s /usr/src/linux-headers-$(uname -r)/ /usr/src/linux
wget http://www.math.tu-clausthal.de/~matsa/linux/vxpocket/alsa-firmware_1.0.9-5_all.deb wget http://www.math.tu-clausthal.de/~matsa/linux/vxpocket/alsa-vxpocket.tgz
- Next, install the firmware package using dpkg
sudo dpkg -i alsa-firmware_1.0.9-5_all.deb
- Then un-tar the alsa-vxpocket config files and put them in the right places (from your home directory), and run update-modules:
tar -xf alsa-vxpocket.tgz sudo cp etc/pcmcia/vxpocket.conf /etc/pcmcia/vxpocket.conf sudo cp etc/asound.conf /etc/asound.conf sudo cp etc/modutils/alsa-base /etc/modutils/alsa-base update-modules
You can then remove the etc directory from your home directory (i.e. ~/etc)
At this point, the vxpocket card should be working, and will be recognised by the system. However, it is not patched for use with the localization, which is the next step:
- Reconfigure the alsa-source (we're going to recompile it with patches), using dpkg-reconfigure
sudo dpkg-reconfigure alsa-source
Answer YES for both ISA PnP and Debug messages, and choose to install *all* of the drivers (should be the default option). You can be picky if you like here, but this is the path of least-resistance.
- Unpack the alsa-source that was installed in /usr/src so that it can be patched:
cd /usr/src sudo tar xjvf alsa-driver.tar.bz2
- Apply the 2.6.15 patch to the drivers
cd modules/alsa-driver sudo patch -p0 < ~/emstar/sensors/audiod/vxpc_server/kernel/linux-2.6.15.patch
where patch_name is the name and location of the patch, i.e. /emstar/sensors/audiod/vxpc_server/kernel/<patch_name>. If you're worried, you can run the patch program with the flag --dry-run to see what 'would' happen if you applied the patch ( so you can check if the patch is good or not :-) ).
- Recompile the alsa-source and install it:
sudo ./configure --with-kernel=/usr/src/linux-headers-$(uname -r) --with-oss=yes sudo make sudo make install
- Put the new firmware in /lib/firmware/vx
sudo cp ~/emstar/sensors/audiod/vxpc_server/kernel/l_1_vp4.d56 /lib/firmware/vx
- OPTIONAL STEP!
To clean up, we need to delete the old modules, as they were placed in a different location (NOTE: you may not need to perform this step if the directory does not exist):
cd /lib/modules/$(uname -r)/updates/
Then
sudo mv alsa ~/ (to move it to your home directory, as a back up)
OR
sudo rm -rf alsa (to completely delete it)
- END OF OPTIONAL STEP!
Next,
- Run depmod, and then you should be done
sudo depmod -ae
You should now have a patched, firmware upgraded, version of the vx drivers. You can check if it's worked by inserting the vxpocket440 card, and examining /var/log/messages, or by typing:
dmesg
And looking at the most recent piece of output. If you see output along the lines of like 'creating proc devs', you know it's worked. If you don't see the output, it may be because alsa needs restarting - the easiest way to do this is by restarting the machine.
patch/install the hostap drivers (for network card)
The next step involves making the SMC wireless card 'Acoustic Laptop useable'. To do this you need to download, patch and install the relevant hostap drivers, by doing the following:
- download the 0.4.5 hostap drivers (from here) and 0.4.7 hostap utils (from here) to your home directory, then untar them:
tar -xf hostap-utils-0.4.7.tar.gz tar -xf hostap-driver-0.4.5.tar.gz cd hostap-driver-0.4.5
- patch the drivers using the patches in the Emstar directory (these need to be applied one after the other for the 2.6.15 kernel):
patch -p1 < ~/emstar/link/macinfo/patches/hostap-macinfo-patch.diff patch -p1 < ~/emstar/link/macinfo/patches/hostap-macinfo-patch-2.6.15.diff
- then set up the symlinks in the correct directory (make sure you have set EMSTAR_ROOT, or you will not be able to do this properly..):
cd driver/modules ln -s $EMSTAR_ROOT/link/macinfo/kernel/*.[ch] . ln -s $EMSTAR_ROOT/link/macinfo/patches/*.[ch] . ln -s $EMSTAR_ROOT/link/udp/udpd_i.h .
- now you can start compiling the drivers
cd ../.. sudo make
- then you can install the drivers
cd /lib/modules/$(uname -r)/kernel/drivers/net/wireless/hostap sudo rm * (or you can move these if you like - we no longer need them) sudo cp ~/hostap-driver-0.4.5/driver/modules/*.ko ./
- then you need to copy the prism2_param script from the hostap-utils directory and put it in /usr/sbin
sudo cp ~/hostap-utils-0.4.7/prism2_param /usr/sbin/
- then run depmod - it is important you do not miss this step out:
sudo depmod -ae
- OPTIONAL STEP!
Finally, you may need to stop the computer from trying to use dhclient with the wlan interface you've just created. To do this, edit the /etc/network/interfaces file, and remove/comment out ALL lines referring to wlan0 (you may need to restart first, or you may not need to perform this step AT ALL)
- END OF OPTIONAL STEP!
set up and compile emstar
All you need to do now is compile Emstar - in the ~/emstar directory, type:
make
And the whole thing should compile. If you spot any errors along the way (about missing libraries), the chances are that you've missed some important package out. All you need to do is go back and reinstall it and start the make process again.
When you've finished the compilation, type
sudo make install-fusd
This will copy the kernel module to the relevant directory and put the fusdd binary in /usr/sbin. When you need to get fusd working, simply type:
sudo fusdd
And this will install the module for you.
To test:
cat /dev/fusd/status
Testing
Setting up the platform
In order to set up your laptop to communicate with other boxes, you need to make sure your SMC card is set up correctly, and also that the sound card has the correct mixer levels set. You also need to make sure that /etc/box_version and /etc/id have suitable values - box_version will depend on the microphone array you are using (1 == v1 box, 2 == v2 box), and id is the node's id - you need to set this to identify the node. Any value will do, but we've been using numbers >= 150.
For example, here's what I typed when making an acoustic laptop with id 151 and box_version 1 (i.e. the old 8cm mic array):
sudo bash echo 151 > /etc/id echo 1 > /etc/box_version echo 1 > /etc/groupid
Then ctrl+d (to get out of the root login), and you're good to go.
Determining the ALSA card index
Usually, laptops have onboard sound that identifies as ALSA card 0. Thus, the default setup for the acoustic laptop assumes that your VXP is installed as card 1. To be sure, you should check which card is which using this command:
cat /proc/asound/cards
If VXP is not card 1, you will need to:
- Edit the devel/loc/testtabs/ar-floodonly-laptop.run file, changing --card_index to reference the VXP card. See the section below, [1]
- Whenever you use amixer or alsamixer, set the -c flag to the card number of the VXP card.
- When specifying hw:X,Y to aplay and other ALSA software, X should be the card index of the VXP, and Y the codec number (channels 0,1 are codec 0, channels 2,3 are codec 1).
The directions below all assume the VXP card index is 1.
Configuring the vxp440 using alsamixer
The VXP card will default to low input levels. In order to record audio you will need to set the levels properly.
echo Configuring mixer amixer -c 1 sset PCM,0 100%,100% unmute amixer -c 1 sset PCM,1 100%,100% mute amixer -c 1 sset Master,0 86%,86% amixer -c 1 sset Master,1 0%,0%
# set input gains (settings below repeated 2x due to a bug in ALSA/VXP) amixer -c 1 cset numid=11 10,10 amixer -c 1 cset numid=12 10,10 amixer -c 1 cset numid=11 450,450 amixer -c 1 cset numid=12 450,450
You may also want to enable mic_boost:
# microphote boost amixer -c 1 cset numid=27 ON
You can also use the alsamixer program directly, with the -c 1 option to specify the VXP. This is a curses program, with online help.
Once you get the right settings for your setup, you may want to make a startup script that configures things on boot.
Starting Emrun
The Emstar system is started by running the emrun program with a config file (.run file) that specifies which daemons to start up. Depending on which hardware you have working in your system you may want to choose different config files. If you are using the VXP hardware, be sure to edit the config file to set the card index before starting; it only reads the config file on startup. (If you edit the config file later, you will need to kill and restart emrun).
To start emrun inthe background, from the emstar/obj.i686-linux directory:
sudo emrun/emrun FILE --daemon
Replace FILE with one of the following paths:
- if you have both network and VXP card: ../devel/loc/testtabs/ar-floodonly-laptop.run
- if you have only VXP: ../sensors/audiod/testtabs/standalone-vxp-laptop.run
- if you have only network: ../devel/loc/testtabs/ar-floodonly-laptop-novxp.run
After starting emrun, you can check to see if it worked by checking /dev/emrun/status, which should list out all current processes and whether they are running. If that device does not exist, probably something went wrong.. try running emrun without the --daemon option to see if you are getting any error messages.
Some additional tips on emrun:
- You can see log messages for each process in /dev/emlog/<procname>/all. Use the all-f version to get a 'tail -f' effect.
- You can see if any processed have recently died and restarted in /dev/emrun/last_msg
- ls /dev/emrun to see what other files exist there, and explore.
Playing and recording sounds (for fun)
In order to get aplay to output sound, it is necessary to do the following:
aplay -D hw:1,0 <filename>.
This is because the pcm devices aren't set up properly in the asound.conf file.
In order to get arecord to record sound, it is necessary to reference the device in the same way:
arecord -D hw:1,1 -d <duration in seconds> -t dat -t wav <filename>.wav
Recording with the sensor board
In order to get ar-floodonly.run working correctly, it is necessary to set up the network card properly, so make sure you do that (woodpckr).
Once emrun is running, you can see status of the VXP server from /dev/sensors/vxp/status. This will show levels information and also can indicate if things are going wrong with the system. /dev/sensors/vxp/levels also reports levels data.
The VXP server will maintain a consistent, monotonically increasing sample counter. You can discover the current value of this counter via the timesync system, using the utility program gettime (in obj.i686-linux/bin):
gettime --clock /dev/sensors/vxp/all
This will get the current time of day, convert it to samples, and report the result. This can be useful when you want to specify a particular segment of time to record. Note that since this is running an executable, the conversion will not be too accurate. You can get conversions accurate to a sample or better from the library interface.
You can record data using the record_from command, i.e.:
./record_from --dur <time in seconds> --path <file prefix to record to> --sensor vxp/all
The --sensor vxp/all means that all of the mics will be used, rather than just a single mic. The output file will be named:
<file prefix>vxp.all_8_151_1178836312.698254_0.raw
where: vxp.all = the sensor recorded from 8 = number of bytes per frame of interleaved samples 151 = node id 1178836312.698254 = time of day of beginning of recording in seconds since 1970 (accurate to a sample) 0 = sequence number of this record_from instance (in case of a glitch it will reopen [with appropriate command line flag])
There will also be a matching .sync file. This file contains information relating samples in the file to time of day. Corrseponding sample/time pairs are recorded every 10 seconds during the recording, so that offline processing can correct for clock drift among different nodes over time. (Note you would need to have timesync among the nodes, or else have your clock trained to gps, etc, for this to be useful.)
Once you have a .raw file, you can then use sox (apt-get install sox!) to convert the raw file into a wave file:
sox -r 48000 -s -w -c 4 <name of raw file> <output file>.wav
And then you can play it. A nice way to play multichannel sound files is audacity (apt-get install audacity!). Audacity has a convenient interface, handles multichannel files, and supports a wide range of filters and spectrogram visualization.
Troubleshooting
VXP drivers didn't patch properly
Make sure that you patched the correct version of the drivers for the kernel you are using. If you patch the drivers with one kernel version, then upgrade to a new kernel, you will have problems, because the patched drivers WILL NOT be loaded.
Therefore, as a rule, if you install a new kernel, re-patch the vxp drivers as per the instructions in this tutorial.
kfusd and kernel-headers
Newer kernels (after 2.6.19) don't have a linux/config.h that kfusd needs to compile. It is basically just a pointer to autoconf.h anyway, so just add it in yourself.
Make /usr/src/linux/include/linux/config.h read:
#ifndef _LINUX_CONFIG_H #define _LINUX_CONFIG_H /* This file is no longer in use and kept only for backward compatibility. * autoconf.h is now included via -imacros on the commandline */ #include <linux/autoconf.h> #endif
Soundcards and Emstar
When you're running the 'demo' ../devel/loc/testtabs/ar-floodonly.run, you need to modify the acoustic sensor part of the run file to make sure its pointed at the right card (as it defaults to 0, which is not right for most laptops that have an integrated soundcard).
You can take advantage of the --card_index flag to do this.
EXAMPLE (from line 51 of ar-floodonly.run), change:
&sensor_vxp(args="--enable-remote");
to
&sensor_vxp(args="--enable-remote --card-index 1");
You will also have to make this change in ar-floodonly.run for the ar daemon:
cmd = "devel/loc/ard --platform=slauson --log-raw /mnt/sd_card/ar_data/ar-raw-%04d-%s-%d --array 12cm";
to
cmd = "devel/loc/ard --platform=slauson --log-raw /mnt/sd_card/ar_data/ar-raw-%04d-%s-%d --array 8cm --card_index 1";
The first change is obvious - we're changing the card index, the second one is to change the mic array size (we're using the old arrays). Note, if you are constructing your own array, set this to indicate which array geometry you use. You can configure a custom geometry by modifying devel/loc/ar/ar_dsp.c and changing the C arrays that define the array geometry.
It is important here that the correct directories are created on the laptop for recording data, etc. You can make a directory for the ar_data to go anywhere you want, just make sure they go somewhere that exists. Some hard coded ar problems might require you to either make a symlink from /mnt/sd_card to somewhere, or create a directory here directly, the choice is yours. My personal preference for this is to create an sd_card directory in my home directory, and link from the mnt directory to there, as follows:
cd ~ mkdir sd_card cd sd_card mkdir ar_data mkdir events cd /mnt sudo ln -s ~/sd_card sd_card
And then all the data should be saved into your home directory.
AML server
If the gnuplot script doesn't seem to be working on the web interface, you need to make sure you have installed:
libpng (probably libpng-dev as well) gnuplot
Also, if you can't start the event detector, it's because rbsh is trying to use a symlink which doesn't exist in your filesystem. To remedy this, you need to do the following:
cd /home sudo ln -s /home/<account where emstar is installed>/emstar/obj.i686-linux /home/emstar
This is because rbsh expects to be able to get to /home/emstar
