Archive for January, 2010

Red and blue stereo skiing

Sunday, January 10th, 2010

Commemorating Sony’s announcement of their dedication for 3D in winter CES

Pixel Bender – Chroma key filter

Monday, January 4th, 2010

As a study of Pixel Bender, I wrote a very rough chroma key filter that makes a specified range of colors transparent. This is my first time working on Pixel Bender, but it turned out to be quite simple as it didn’t take me more than half an hour to make this demo after downloading the reference.
The result may look clumsy, I admit, but the poor movie that I took with a mobile phone should be blamed rather than the filter itself.

<languageVersion : 1.0;>

kernel ChromaKey
<   namespace : "info.kynd";
    vendor : "kynd.info";
    version : 1;
    description : "makes specified range of colors transparent";
>
{
    input image4 src;
    output pixel4 dst;

    parameter float4 keyColor
    <
        minValue: float4(0.0, 0.0, 0.0, 0.0);
        maxValue: float4(1.0, 1.0, 1.0, 1.0);
        defaultValue: float4(0.0, 0.0, 0.0, 1.0);
        description: "color that is used for keying";
    >;
    parameter float range
    <
        minValue: 0.0;
        maxValue: 1.0;
        defaultValue: 0.0;
        description: "range of color that the filter is applied";
    >;

    void
    evaluatePixel()
    {
        float4 color = sampleNearest(src,outCoord());
        float dist = distance(color, keyColor);
        if (dist <= range) {
            dst = float4(0.0, 0.0, 0.0, 0.0);
        } else {
            dst = color;
        }
    }
}

Sound Spiral

Monday, January 4th, 2010

Sound draws a spiral. If you start from C, and go up the stairway of notes to D, E, F, and so on, you’ll get to another C, which is not the same place you previously were but one floor up from where you started. Since the ratio of frequencies of two notes an octave apart is 2:1, going up one floor means doubling the frequency.
So what if this relationship were literally visualized in 3D animation? The result did not turn out very simple and clear since even a single note of an instrument contains multiple frequencies as its component. But at least it’s somewhat fun to watch, isn’t it?
Clicking on the demo below starts/stops the sound. Watch out for the volume on your PC.

Sound.comuteSpectrum() method, which is used to analyze the sound, seems to have several problems. One of them that is critical is that the method doesn’t work properly when more than two movies play sound simultaneously in FireFox. If you don’t see the demo, try closing other browser windows.

Another demo that works without music is also posted to wonderfl.

Google Text-To-Speech API

Saturday, January 2nd, 2010

It turned out to be possible to use Google’s text-to-speech API via HTTP GET request though it’s not yet documented.
According to Weston Ruter, it is as simple as calling http://translate.google.com/translate_tts?tl=en&q=text, and the server returns a MP3 file(‘text’ can be replaced with any arbitrary text less than 100 letters).
So far, it seems only English is supported, but I hope that the API will cover other languages and to be officially available sometime soon.

package {
	import flash.display.*;
	import flash.events.*;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import fl.controls.Button;

	public class Main extends Sprite {
		private const REQ_URL_BASE:String="http://translate.google.com/translate_tts?tl=en&q=";
		private var sound:Sound;
		private var inputText:TextField;
		private var button:Button;
		public function Main() {
			addChild(inputText = createTextField());
			inputText.text = "Google text to speech test";
			inputText.x = inputText.y = 10;
			addChild(button = new Button());
			button.x = 10;
			button.y = 90;
			button.label = "Test";
			button.addEventListener(MouseEvent.CLICK, textToSpeech);
		}

		private function textToSpeech(evt:Event = null):void {
			var sound:Sound = new Sound();
			sound.addEventListener(Event.COMPLETE, playSpeech);
			sound.load(new URLRequest(REQ_URL_BASE + encodeURI(inputText.text)));
		}

		private function playSpeech(evt:Event):void {
			evt.target.play();
		}

		private function createTextField():TextField {
			var txt:TextField = new TextField();
			var tf:TextFormat = new TextFormat();
			tf.font = "_sans";
			tf.size = 16;
			tf.color = 666666;
			txt.defaultTextFormat = tf;
			txt.width = 320;
			txt.height = 70;
			txt.border = true;
			txt.multiline = true;
			txt.wordWrap = true;
			txt.maxChars = 100;
			txt.type = TextFieldType.INPUT;
			return txt
		}
	}
}
Related Posts with Thumbnails