Wednesday, May 26, 2010

how to build a simple audio sound recorder with clam

Once I had the opportunity to get involved with the clam project, with the help of google summer of code. Being the lazy person I am, I didn't keep up my involvement, unfortunately, since it is a great piece of code. Being the great piece of code it is, I decided to use it for a project that required me to simply record audio to files, but also have the room to grow to a bigger better application (speech recognition). Being the lazy person I am, I searched google for a tutorial about how to do this. Since I didn't find anything, I figured that I know enough about clam to write that how-to that I was looking for. Without further ado, here goes:

(please let me know if this works/doesn't work for you)

First, fire up the network editor. I like to just use the command line so I can see the diagnostics. If you're using the command line too, remember that it is capital N NetworkEditor, unless you happened to name it something else.

Next, create the network. Drag and drop an AudioSource (under the heading "Audio I/O", and a MonoAudioFileWriter (under the heading of "Audio file I/O"). Then connect them by dragging from the little blue circle (its "output port") of the audio source box ("processing"), to the little blue circle of the mono audio file writer (its "input port"). Notice that the mono audio file writer is red. This means that it needs to be configured, so right click on it and select "configure" . Then you can set the the file name and the sampling rate. Save it (network editor has an uncanny knack for crashing probably due to it's use of a mix of compiled and run time generated components). Then click run (aka "play", the blue circle with the sideways triangle) to start recording and stop to finish recording. Then check the audio file to make sure it was created, and that it has audio content. If it doesn't have content, you'll need to fiddle with you audio recording settings. You can do this several ways: you might have audio controls in the system tray/menu bar of your desktop, it might be in some control panel, or you can set it from the command line (e.g., "alsamixer").

Most likely this doesn't merit a how-to since you could probably figure that out by dropping processings on the canvas and connecting them at random. I said a simple audio recorder, but I wanted a few frills, such as a vu meter and having it be a stand-alone compiled application. Since it is so easy with clam, let's start with the vu meter (which is used to visualize the recording level. These types of meters are called vu meters because they were made popular by the Velvet Underground in the 60's and 70's -- that's not true, I only want to keep you from getting distracted by googling "vu meter"). Pull that out of the tree side menu labeled "graphical monitors". Do not be tempted to play with other graphical monitors. They are fun and they WILL distract you. Once you put it on the canvas, you can just connect it to the audio source like you did for the connecting the audio source to the mono audio file writer. Test it out by recording yourself, and don't be self conscious because everyone sounds funny when they are recorded.

Here is a screen shot of what the network should look like:


Now, to make a gui for the standalone application. Clam makes it very easy to do this but it is not as intuitive as dragging, dropping and connecting. Here's when I need to check myself how to do it ( you can see the more in depth, serious article here). First, you have to know some basics about qt designer. It is a graphical user interface (gui) design tool for the Qt framework. It is kind of like the Network Editor, except that it helps you design guis instead of audio applications. Fire it up (from the start menu or by simply typing "designer" at the command line), and select "dialog without buttons" (we are going to add our own buttons, and it is a dialog because it will be something that will be used inside a larger application as a pop up dialog... stay tuned for another tutorial about the larger application sometime later). Let's say the buttons we want are "record", "play", and "submit". Drag 3 push buttons from the side menu, arrange them how you like (you can experiment with different "layouts", which are just boxes that will sort the buttons vertically or horizontally. Change their names to read "record", "play", and "submit". For the VU meter, check to make sure that there is a submenu for the clam widgets. In my case, there wasn't, so I had to locate shared object (a "dll" in *nix parlance) that contains the clam widget plugins for qt designer and copy it to the right place. I found the plugin shared object at /usr/lib/qt4/plugins/designer/libCLAMWidgets.so and after a little poking around, I realized that it should be at /usr/lib64/qt4/plugins/designer/ so I copied it to that location and then designer found it (see "help" -> "about plugins" ). Now I can drag out a vu meter just like I did for the buttons. Now it should look like this:



Now we have the audio network and the gui, but we need a way to connect the two. To do this we need the "signals and slots editor" mode in designer. it should be in one of the myriad of menus and tabs (you can check the view menu to make sure it's being displayed). You also need to go into the "edit" menu and change to "edit signals and slots". This will allow you to select the buttons and drag their behavior to where it needs to be connected to. For the "submit" button, the behavior we be connected to a close event, so select the submit button and click+drag to the background canvas. A dialog will pop up and you should map the clicked() signal to accept(). If you hit control-r you can preview the gui to make sure that clicking the submit button closes the application. The submit button is the only button that we can connect within designer because the other buttons will be connected within clam. Change back to "edit" -> "edit widgets" and change the names of the button objects from pushButton, pushButton01, ..., to informative names like RecordButton, PlayButton, and SubmitButton. Changing the object names will make it easy to remember the names so that we can connect the object behaviors. Some of the object names might actually be bound to the behaviors by their naming conventions... we'll soon find out. If you save the designer file as the same name as the clam network, except the the extension .ui, then you can use the clam tool "Prototyper" to run the gui. Give it a try.

It turns out that there is a problem due to naming conventions. The name "PlayButton" conflicts with the "PlayButton" of the network editor. Hence, clicking the PlayButton will start recording because it will "Play" the network. So, change the record button's name to "PlayButton", and for now, the button labeled "play" will do nothing (check back later to see if I can figure it out).

For the vu meter, we need to go back to the NetworkEditor. On the output port of the AudioSource processing, right click and select "copy connection name". What you copy should be something like OutPort__AudioSource__AudioOut. Go back to qt designer and change the object name of the vu meter to whatever you copied from the network editor (remember that you can right click on the vu meter in designer to change it's object name. Try running it with prototyper. From what I can tell, it starts recording from the get-go, so that's one defect that we will have to consider. But for now, I'm satisfied with an evening's work, so I'll leave it at that for now.

Wednesday, April 14, 2010

Messengers of God by Peter G. Wahl

One time in 2000 I was in San Diego hanging out with my high school buddy Tim O'Connell. I met a bum named Peter G. Wahl and he asked me for some money and I gave him some and he copied this poem for me. I recently dug it up and decided to google him. Since I didn't find it anywhere on the internets, I'll put it here so that other people can enjoy it. It looks cooler in handwriting b/c he wrote it in a William Blake style.

Messengers of God

I.
Beyond the realm of social fears,
An angel on a wing appears,
And sets his blessed feet on earth,
Creating in this world rebirth.

II.
His might exceeds what Jesus done
Yet, now prepares his way to come
Searching hearts and minds of man
Sending forht the spirit of "I Am".

III.
Before Heaven's Holy Throne,
A figure glows but not alone,
At His right hand, no longer scarred,
Be the Loyal Son of God.

IV.
All the angels in unison sing,
To mankind the tale the bring,
Voices of prophets of old,
The ends of earth man foretold.

V.
O' End for me this present sorrow,
I'll gladly go this day or morrow!
While Gabriel flies,
Trumpet a blaring,
Throughout the skies,
The end's declaring.

Monday, January 18, 2010

linux setup for open suse 11.2

Here's what I did to customize my computer when installing opensuse 11.2:

I like emacs, but I dislike some of the default settings, so here are the things I added to my .emacs file:

0. I changed the EDITOR env variable to /usr/bin/emacs in my ~/.bashrc file

1. enable hippie-expand. In .emacs add

(global-set-key "\M- " 'hippie-expand)

2. copy and paste was messed up. I found this link http://www.oreillynet.com/lpt/wlg/6162 and added the following to the .emacs file

(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)

3. enable copy and paste with c-ins s-ins, s-del, c-left, c-right, etc.. (for some reason c-ins was mapped to insert-file, same as c-x i, kind of wierd) as per http://www.emacswiki.org/emacs/PcSelectionMode

(if (fboundp 'pc-selection-mode)
(pc-selection-mode)
(require 'pc-select))

4. enable alt backspace to delete word backwards:

;;; I want alt-backspace to send backward-kill-word
(global-set-key [(meta backspace)] 'backward-kill-word)

5. disable splash screen:

;;; Remove splash screen
(setq inhibit-splash-screen t)

6. some tab settings for coding:

;;; use only space for tabs:
(setq-default indent-tabs-mode nil)

;;; set tab to 8 spaces
(setq tab-width 8)

7. change the color scheme, personal preference--light on dark

;;to set foreground color to white
(set-foreground-color "white")

;;to set background color to black
(set-background-color "black")


Then there were some repositories to add

*restricted formats:
http://opensuse-community.org/Restricted_Formats/11.2

* Add the required software repositories:

zypper addrepo -f http://ftp.skynet.be/pub/packman/suse/11.2 packman
zypper addrepo -f http://www.opensuse-guide.org/repo/11.2 libdvdcss

* Install the packages:

zypper install ffmpeg flash-player libdvdcss libxine1-codecs w32codec-all lame

* seems like dvd still isn't playing try installing libdvdplay and upgrade libxine1-codecs, k3b-codecs, libdvdplay0, and some others as dependencies... cool it works!

* sudo zypper ar http://download.opensuse.org/repositories/openSUSE:Factory:Contrib/openSUSE_11.2 openSUSE:Factory:Contrib:openSUSE_11.2


I forgot how much I dislike opensuse not putting /sbin and /usr/sbin on the path, so I added these to my path in ~/.bashrc b/c I'm accustomed to using sudo instead of su


my favorite firefox plugins:

1. http://del.icio.us, (install page for ff at http://delicious.com/help/installff )
2. tree structured tabs ( https://addons.mozilla.org/en-US/firefox/addon/5890 )
3. a new one that I just started liking: cooliris.com

I wish this were default
sudo zypper install -y findutils-locate
sudo updatedb
in /etc/sysconfig/locate, set RUN_UPDATEDB_AS = root, so updatedb will index everything

# Installing htk

1. when compiling I got this error:

akazemzadeh@coldfire:~/htk> make all
(cd HTKTools && make all) \
|| case "" in *k*) fail=yes;; *) exit 1;; esac;
make[1]: Entering directory `/home/akazemzadeh/htk/HTKTools'
if [ ! -d /usr/local/bin -a X_ = X_yes ] ; then mkdir -p /usr/local/bin ; fi
if [ xHSLab = xHSLab ] ; then \
gcc -o HSLab -m32 -ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH="x86_64"' -Wall -Wno-switch -g -O2 -I../HTKLib -DPHNALG HSLab.c ../HTKLib/HTKLib.a -L/usr/X11R6/lib -lm -lX11 ; \
else \
gcc -o HSLab -m32 -ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH="x86_64"' -Wall -Wno-switch -g -O2 -I../HTKLib -DPHNALG HSLab.c ../HTKLib/HTKLib.a -L/usr/X11R6/lib -lm ; fi
/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../libX11.so when searching for -lX11
/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib64/libX11.so when searching for -lX11
/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ld: cannot find -lX11
collect2: ld returned 1 exit status
make[1]: *** [HSLab] Error 1

2. I tried installing xorg-x11-libX11-devel-32bit b/c maybe htk requires 32 instead of 64...
1. Yep, that seems like it was the problem...

# Colored man pages:
1. install "termcap"
2. add the following to .bashrc:

export GROFF_NO_SGR=yes
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

# Mysql:

1. it seems like mysql is already installed, but I installed some more mysql tools from yast
2. sudo rcmysql start
3. sudo mysqladmin -u root password '*********' (same pw as root user)

# Groovy

1. first I needed to add a repo: http://download.opensuse.org/repositories/home:/robert_munteanu/openSUSE_Factory/
2. then use zypper/yast to install: groovy, groovy-doc, gant, grails, grails-doc
3. export GROOVY_HOME=/usr/share/java/groovy/
4. change the java from openjdk to sun: sudo update-alternatives * for * = java javac java_sdk_1.6.0 javaplugin jre_1.6.0
5. was getting some error about asm so I installed some java asm packages from yast.

# Real time kernel setup

1. Install kernel sources using YaST (Software/Software management then search for "kernel source," check the "kernel-source" package. You also need the compiler, linker, and make utilities: Set the YaST "Filter" to "Patterns" and select the "Development / Basis development" pattern, then "Accept" button, etc. to complete the installation)
2. cd to /usr/src/linux
3. copy the current configuration to the file ".config" in this directory: "cp /boot/config-2.6.18.2-34-default .config"
4. run "make xconfig" this is a nice graphical interface to help you edit the kernel parameters in the .config file before recompilation (or make menuconfig if it gives any warnings...)
5. select "Option/Show All Options" in menu
6. Under "Processor type and features" set "Timer frequency" to 1000 Hz
7. Save changes and close the configuration tool.
8. Run "make install" to install the newly-compiled kernel, and "make clean" to remove some intermediate files and free up some disk space in the source directories.
9. Reboot (if the new kernel is not supposed to be the default, edit the grub conf/menu.lst accordingly)
10. Preempt The Big Kernel Lock" and "Preemptible Kernel (Low-Latency Desktop)
11. Run "make" with the option "all": "make all" (run "make help" for info) to compile the kernel and its modules
12. Run "make modules_install" to install the newly-compiled modules

Sunday, August 9, 2009

setting up linux on asus nova (p20?)

One of the first things that I had a problem with is the screen resolution. After mucking around a bit in /etc/X11/xorg.conf, I realized that it was getting messed up at boot and I fixed it by adding vga=773 to the end of the kernel line of the configuration(s). I might have to reset this later on if I use a different monitor. For some reason, pcbsd/freebsd got the resolution right and I didn
t have to worry about it. Gentoo however is the distro that was giving me this problem. I picked gentoo instead b/c I was having trouble with other things in the psd distro and I'm more familiar with gentoo and linux in general compared to bsd. I guess I should be clear that I'm using the 2008 gentoo livecd as the install medium.

Another thing that wasn't working quite right was the shutdown of the audio drivers. there was a line to change in /etc/init.c/alsasound, according to http://bugs.gentoo.org/show_bug.cgi?id=232875
which involved changing a --wait flag to --force .

Thursday, April 23, 2009

acer x191w with intel GMA3000

With my new computer I was having a hard time to get my monitor, acer x191w, working at anything bigger than 1024x768. I think I solved it by running

sudo 915resolution 5a 1440 900

then restarting x (startx). Still the intel driver isn't working but at least I'm getting a good resolution. It's hard to be able to tell if this is exactly what I did to get it working, b/c I was mucking around and fixing other stuff that I did that prevented X from starting. Also it seems that rebooting will cause the changes made by 915resolution to disappear, so we'll see if it will still work when I reboot.

Monday, April 21, 2008

New Surfboard

woohoo! I just found a surfboard in the trash the other day. I was walking around my lovely neighborhood at twilight and I saw some Chinese neighbors doing yard work. I said hi and looked around and saw a surfboard in their garbage can. I asked them about it and they said that it was a former tenant's and that I could have it. It turned out that they were from Shanghai, one of the coolest places I've had the pleasure to briefly live at. So I took it and found another neighbor watering his yard and he sprayed it off for me. It's was a bit cruddy. I took it back home and fixed some dings with epoxy. It will take some more work still. I have to get a leash, and Reid Swanson recommended me to get a wax comb to get rid of some of the dirty wax (actually, I ran into Reid, my surf mentor and former co-worker the day before on campus and he didn't have the old surfboard that I used to borrow anymore, so it was a pretty cool coincidence). I'll also have to re-learn surfing and get used to a short board. the board says "sueƱo" on it (Spanish for dream/sleep). I guess it was a dream come true.

Wednesday, June 27, 2007