Wednesday, July 14, 2010


I few months ago I was struck with an idea. What would it look like if traditional audio effects were applied to videos?

I could treat every pixel as a separate signal in time, with its brightness being the value. These become sequences of values, just like streams of audio data. I could put these signals through various audio filters, like high-pass, low-pass, and so on. (I solely apply effects in time, not space.)

I wrote code in C that worked on individual frame images at the pixel level in order to have complete control.

Applying a low pass filter to all pixels created a motion-blur like effect, because it was essentially blurring together consecutive frames. A high pass filter looked more interesting - the video became all dark except for the areas with the fastest motion. Things really started to get interesting, though, when I used other audio effects. Watch this:

A flange effect can be created with is the sum of two signals: one is the input signal, unchanged, and the other is the input signal alternating between being played slightly faster, and slightly slower. Because of the alternation, they stay in sync, but the effect is heard as a moving, shimmering sound. (Used in guitars in psychedelic rock).

I applied an exaggerated version of this effect. I combine the video signal with an altered version of itself that speeds up and slows down, just like a flange effect. This means that sometimes the altered signal is a ghostly signal sometimes ahead in the future, and sometimes lagging behind.

The effect with rainbow colors is related to a high pass filter - the areas that are changing the most are the ones that are allowed to overflow into vivid colors.

In audio, there are methods of looping a non-periodic sound. One way is to play many copies of the sound offset in time, but giving each a envelope, so that each piece on its own fades in and out, and isn't very noticeable. I used this in the last effect of the video, creating a loop.

Tuesday, July 6, 2010

Launchorz scripts

My Launchorz project makes it easy to automate repetitive tasks in Windows. Here are some of the scripts I've found to be the most useful. (Note that they are intended for Windows 7 and might not be compatible with something earlier.)

Open command-line to the current Explorer directory

Window.activate( {'class':'CabinetWClass'});
// activate the most-recently-used Explorer window.
var strDir = getCurrentExplorerDirectory();
if (strDir)
  Process.openFile('cmd.exe', strDir);

You can download getExplorerDirectory.js.

Creating an index of all files in a directory

This script creates a text file index of all files in a directory, including subdirectories. The output is formatted nicely by indentation level. It uses the path of the currently open Explorer window and creates tree_files.txt.

Window.activate( {'class':'CabinetWClass'})
var strDir = getCurrentExplorerDirectory();
if (strDir)'cmd.exe /c tree /f /a > tree_files.txt', strDir);

Expand repeated code

When working on a quick project, or writing in a language like Verilog, sometimes the same line of code is repeated a few times, with a different index. The following script takes a code fragment like
a[#] = b[#] & c[#];
and expands it to
a[0] = b[0] & c[0];
a[1] = b[1] & c[1];
a[2] = b[2] & c[2];
(This isn't a useful example but it depicts what the script does). All it does is replace the '#' character with a number.
var sClipboard = Clipboard.getText();
if (sClipboard  && sClipboard.contains('#'))
  var sRep = Dialog.input('Replace', 'How many repetitions? n=0 to ?', '3');
  if (isNumber(sRep))
    var sResult = '';
    for (var i=0; i<sRep; i++)
      sResult += sClipboard.replace(/#/g, i) + '\r\n';

Sort lines in the clipboard

var strClipboard = Clipboard.getText();
if (strClipboard) 
  var arr = strClipboard.split('\r\n');
  var strResult = arr.join('\r\n');
(You could also normalize the line endings with strClipboard.replace(/\r\n/g, '\n') and split on \n).

Displaying an ANSI table

//opens an ascii table in notepad.
var s ='';
for (var i=32; i<128; i++)
  var si = (i<100)?' '+i : i.toString();
  s+= si + '\t' + String.fromCharCode(i);
  s+= '\r\n';
File.writeFile( File.getPathTemp()+'\\tmpascii.txt', s);'notepad.exe '+File.getPathTemp()+'\\tmpascii.txt');
Showing a simple reference of ansi characters.

I also have a clipboard replacement script that gives you 26 different clipboards, each recalled by a letter. However, there exist many other clipboard-handling tools.

To learn more about Launchorz, you can watch some screencasts here. (It is similar to AutoIt, but has a full JavaScript language and namespaces).