Archive for the ‘/usr/bin’ Category
quick notes on using gnuplot’s lua terminal
In gnuplot,
set term tikz fulldoc color solid createstyle
set output 'tmp.tex'
p x**2 tit '$x^2$'
then in shell,
pdflatex tmp.tex
NB:
(1) ‘createstyle’ is crucial, otherwise tex will complain about missing ‘gnuplot-lua-tikz.sty’. This doesn’t seem to be mentioned in the first several google results
(2) I have to comment out the ‘utf8x’ package in the resulting tmp.tex. That may just be a problem with my tex environment
gnuplot: different color on different segments of a curve
I’m not sure what’s the proper description, but here’s a task at hand and how it is done in gnuplot:
suppose I have a datafile with 3 columns. I can plot columns 1 and 2 as a curve:
gnuplot> p 'datfile' u 1:2
In my problem, the 3rd column indicates whether the entry is “localized on the left side”, which will have abs($3)>1, or the “right side”, having abs($3)<1. I want the curve to be plotted in one color (say red) for the “left side” segment(s), and another color (say green) for the “right side” segment(s)
somewhere in gnuplot’s manual, it says it will silently drop data if they are unplottable, and gives an example that 1/0 is unplottable (division by zero). so here’s the idea:
define the “above” and “below” function:
gnuplot> above(x,a) = x > a ? 1 : 1/0
gnuplot> below(x,a) = x < a ? 1 : 1/0
then I can use them to pick out the left/right segments:
gnuplot> p '' u 1:($2*above(abs($3),1)) w l lt rgb 'red' lw 2 tit "localized to the right"
gnuplot> rep u 1:($2*below(abs($3),1)) w l lt rgb 'green' lw 2 tit "localized to the left"
there is a minor problem: for data files, the segments with different colors are always separated by a small gap b/c neither above nor below would cover that gap. Haven’t thought about how to solve this yet, probably a clever redef of above and below could do the job.
Exporting Yamaha YPG-635 recorded songs to wav via AV-710 Line-in jack
I recently bought myself a Yamaha YPG-635 digital piano. It saves
recordings internally as SMF (Standard Midi Format) files. While
that’s good if you want to do some further midi sequencing, I don’t
yet feel the urge to properly set up a linux midi workstation just to
share some of my amateurish playings with family and friends–a quick
way to export them to wav files would be enough. The built-in speaker
of this DP is crappy, but the headphone out is pretty decent (I’m
using a pair of Sennheiser HD650 cans), so it seems natural to feed it
into the soundcard’s Line-in jack.
Turns out it’s not a simple matter of “plug and record”, so here’s a
mini-Howto. I’m using a Chaintech AV-710 soundcard (already
discontinued for some time now, but among other things has a pretty
decent wolfson DAC on the alt-out jack).
1 Sound card settings:
I’m talking about the settings you can tweak in alsamixer
-
Playback. Go to the playback tab in alsamixer. To reproduce the
line-in signal on the wolfson output (the black jack right next
to the actual S/PDIF jack), set “S/PDIF” from PCM to “H/W In 0″,
and “S/PDIF 1″ to “H/W In 1″. These correspond to the left/right
channel of the line-in signal (so you get stereo!)NB: I didn’t try to reproduce it on the “front out” jack (which
nobody using AV-710 would use!). The “S/PDIF” and “S/PDIF 1″ are
probably referring to the wolfson device. (“S/PDIF 0″ is probably
the actual S/PDIF jack) -
Capture. Go to the capture tab in alsamixer. Press space on the
“Line” device. There are multiple capture devices on this card
and they seem mutually exclusive (i.e., pressing space on e.g.
“Mic” would activate “Mic” and deactivate “Line”).Since the DP jack is really a headphone out, better set the
“Capture” gain to zero–no good can come out of double amping!
2 Recording command:
arecord -D plughw:0,0 -f cd -t wav cavatina.wav
Now hit the Play button on your DP. The song (Cavatina in this case.
Beautiful piece by Stanley Myers btw.) will be recorded to
cavatina.wav as you hear it from your wolfson out. Notice that
plughw is necessary b/c natural format of AV-710 is S32LE instead
of the 16bit cd format (S16LE). The “plughw” ALSA plugin will do
the format converting job.
3 Combining audio with video:
mencoder cavatina.avi -audiofile cavatina.wav -delay -0.55 -oac copy -ovc copy -o cavatina-song5-track4-audio.avi
dumping audio from a video clip using mplayer
mplayer your-video.mkv -ao pcm:waveheader:file=output.wav
mplayer will suggest you to use -vo null -vc null -ao pcm:fast to achieve faster result, but somehow this doesn’t work for my file at hand

automatically (un)compress files with arbitrary suffix in emacs
Xournal, the note-taking app I’m using on my tablet, has the nice feature of gzipping its xml-format files. The following snippet in ~/.emacs will allow emacs to automatically compress/uncompress it during writing/reading.
(add-to-list 'jka-compr-compression-info-list
["\\.xoj"
"compressing" "gzip" ("-c" "-q")
"uncompressing" "gzip" ("-c" "-q" "-d")
t nil
"\213"]
)
(jka-compr-update)
playing .nrg format dts cd with mplayer
Well, I was about to write about using cdemu to simulate a cd-device from an .nrg file, and then use mplayer to play the simulated device. It turns out you don’t even need cdemu if it’s a media cd/dvd image. Here’s the cli:
mplayer cdda:// -cdrom-device yourfile.nrg -rawaudio format=0x2001
the only mysterious part is the magic number 0x2001, telling mplayer the disc has dts rawaudio. Apparently you can find this number by man mplayer and search for dts.
