Sunday, December 27, 2009

last.fm 2009

Last.fm has a cool API that let's you gewt almost any sort of data from them just using a web request in XML or JSON format. During their countdown for the top artists of 2009 they encouraged people to use the API, and I used the Last.fm API to show how many plays you scrobbled from each artist in the top 40.

http://zxcvbn.t35.com/lastfm-2009.html

Features:
  • Uses Last.fm API to get JSON data for number of songs listened to
  • Dynamic page effect using JavaScript to organize page elements
  • Uses last.fm javascript client API

The program is pretty simple, it uses the Library.getTracks API method to retrieve your listening data. I create a last.fm object. you need an 'API key' and 'API secret', which you 'apply' for on their API page http://www.last.fm/api. Then, you can call any of the methods of the API you like

Using my program as an example
/* Create last.fm object */
var lastfm = new LastFM(
{
apiKey: 'Apply for key at http://www.last.fm/api',
apiSecret: 'Apply for API code at http://www.last.fm/api',
cache: cache
});

/* Success function parses JSON data. note: stringify JSON data before parsing */
function success(json_data) {
var json_string = JSON.stringify(json_data);
var json_parse = JSON.parse(json_string);
var tracks = json_parse.tracks;
}

/* Failure function parses error codes */
function failure(code, message) {
alert(code + ': ' + message);
}

/* Call the api function with JSON format API parameters */
lastfm.library.getTracks({ user: "LastFM Username", artist: "Britney Spears" },
success_function_callback, failure_function_callback);


Update:
I made it so you can find out how many songs you've listened to by any artist you type in. It's not very easy to find out if the artist isn't in your top charts

http://zxcvbn.t35.com/lastfm-2009.html

Tuesday, December 15, 2009

cpu post processing

Out of curiosity, I tried to replicate the post processing effect using the CPU instead of using shaders on the GPU. This is complicated because we're not supposed to access the graphics data directly, but uh-hmm -- whatever

To get the rendered graphics data, I use GetRenderTextureData which uses the system memory pool. But MSDN says that : "system memory is not typically accessible by the Direct3D device". So we must wait on a lock to copy from the system memory to default memory. This is a really costly operation and basically is the failure of my experiment. Running in exclusive (fullscreen) mode, takes about ~50ms to run, and the framerate is killed to <20fps

// Texture surfaces with given CreateTexture parameters
// renderTexture is D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT
// systemMemTexture is D3DUSAGE_DYNAMIC, D3DPOOL_SYSTEMMEM
// defaultMemTexture is D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT

pd3dDevice->GetRenderTargetData(renderTextureSurface, systemMemSurface);
systemMemSurface->LockRect(&source, NULL, 0);
defaultMemSurface->LockRect(&dest, NULL, 0);
copy(source.pBits, dest.pBits);
systemMemSurface->UnlockRect();
defaultMemSurface->UnlockRect();



Apparently, GPGPU programming is enabled by hardware and the software. For example in nVidia CUDA it let's programmers control shared memory for hardware the graphics that enables programmer control (see Toms's Hardware: CUDA from the Hardware Point of View )



From the GPGPU FAQ it says about the shared memory

"Texture read operations are routed through a cache structure to allow efficient exploitation of reference locality. Read operations also factor into shader thread scheduling as read operations that miss the cache will block the thread and cause other ready threads to run while waiting for the read to memory to complete. Writes are routed through different logic that does some amount of buffering to maximize the efficieny of writes."

Saturday, December 12, 2009

gpu post-processing

I wanted to explain an overview of the post-processing effects using GPU shader programs since I've been working on this for awhile now. Basically, the rendering for post processing is broken into two steps

- we render-to-texture using normal rendering routines
- then use a pixel shader to texture a square with the render-target texture

The code I used the DirectX SDK sample ($SDK\Samples\C++\Direct3D\PostProcess)
Here is a simple model of the rendering

// render-to-texture
graphics->SetRenderTarget( offscreenTexture );
graphics->RenderScene( );

// square is the size of the screen, from back buffer description
VERTEX quad [4] = /* use the BackBufferDescription( ); */

// set shader parameters
shader->SetTechnique( "RenderPostProcess" );
shader->SetTexture( “offscreen_texture", offscreenTexture );

// square is textured by the pixel shader effect
graphics->SetRenderTarget( screen );
graphics->DrawPrimitive( quad );


I based this code off of the DirectX SDK sample ($SDK\Samples\C++\Direct3D\PostProcess, definitely look at that this if you are trying this). The square is calculated to fit the screen (using DXUTGetD3D9BackBufferSurfaceDesc). Then we texture the "fullscreen square" using our RTT texture, and we can use pixel shader effects during this rendering.

Here, the simplest "toon shader" ever

// render target from effect->settexture
texture offscreen_texture;
sampler2D s = sampler_state {
Texture = <>;
};

// "toon shader"
float4 PostProcessPixel(float2 uv : TEXCOORD0) : COLOR
{
float4 c = tex2D(s, uv_coord);
c.rgba -= (Color.rgba % 0.3f );
return c;
}

technique RenderPostProcess {
pass p0 {
VertexShader = null;
PixelShader = compile ps_2_0 PostProcessPixel ();
ZEnable = false;
}
}


Thanks to gamedev for helping me with this miracle



Updated:

Source code - http://zxcvbn.googlecode.com/svn/trunk/skelly/
Wiki page - http://code.google.com/p/zxcvbn/wiki/skelly
Demo - http://zxcvbn.googlecode.com/files/Skelly.exe

Monday, November 16, 2009

graphics pipeline

It's important to know how shaders work with the graphics pipeline, because the "shader model" of graphics programming is totally different from the "fixed function model"! MSDN says here http://msdn.microsoft.com/en-us/library/ms800169.aspx

"The following user-mode display driver functions are not called by the Direct3D runtime when the vertex shader is enabled
  • * MultiplyTransform
  • * SetTransform
  • * SetMaterial
  • * SetLight
  • * CreateLight
  • * DestroyLight


This means that when you use shaders, you have to compute lighting and transformations! DirectX will also ignore flags like D3DRS_LIGHTING and texture state flags when you use shaders. When you program using the shader model, your shader program has responsibilities!

Contrast the API for the fixed function model, which uses the D3D device functions, with the shader model, which is similar but passeses parameters to your shader effects through the shader interface

IDirect3DDevice9::SetTexture vs ID3DXEffect::SetTexture
IDirect3DDevice9::SetTransform vs ID3DXEffect::SetMatrix
IDirect3DDevice9::SetLight vs ID3DXEffect::SetValue

I'll go over the exact responsibilities of shaders in your program. The MSDN page on the graphics pipeline says has some really important things about this - http://msdn.microsoft.com/en-us/library/ee415715(VS.85).aspx and I will use this gamasutra article for base code - http://www.gamasutra.com/features/20030418/engel_02.shtml



1) "The vertex-shader (VS) stage processes vertices ... performing per-vertex operations such as transformations, morphing, skinning, and per-vertex lighting."

Therefore, the vertex shader is typically responsible for worldview transformations and also calculating light values. The vertex shader sets up a VS_OUTPUT struct that contains transformed vertex information that is rasterized and passed to the pixel shader. The vertex shader outputs a VS_OUTPUT structure

struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Light : TEXCOORD0;
float3 Norm : TEXCOORD1;
};

VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position wrt worldview
Out.Light = vecLightDir; // output light vector
Out.Norm = normalize(mul(Normal, matWorld)); // transform normal wrt world
return Out;
}

2) "A pixel shader is a program that combines texture data, per-vertex values, and other data to produce per-pixel outputs...Pixel shader inputs are interpolated from the vertex attributes of the primitive being rasterized"

We basically receive a VS_OUTPUT from our vertex shader as our pixel shader input, but the vertex data is interpolated. We use the NORMAL value to calculate lighting in our pixel shader, because the NORMAL in our pixel shader is interpolated from the rasterizer for our little pixel! The pixel shader outputs is a RGBA

float4 PS(float3 Light: TEXCOORD0, float3 Norm : TEXCOORD1) : COLOR
{
float4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f};
float4 ambient = {0.1, 0.0, 0.0, 1.0};
return ambient + diffuse * saturate(dot(Light, Norm));
}

Note: The POSITION register is not valid in the pixel shader, we are using pixels and not 3D space, but we still use the NORMAL data for lighting. The rasterization stage that converts our vertex shader data into pixel shader data is interesting. See the wikipedia page is good http://en.wikipedia.org/wiki/rasterization

Monday, October 26, 2009

erasing linux passwords also



I actually forgot my root password on a debian linux, for real! I was actually able to reset the root password on my the linux also pretty easily. I had to boot into single user mode, by way of the grub command line, add the option (see in the picture where it says press e to edit? add this onto the end)

single init=/bin/bash

apparently, it skipped loading the operating system or something, gave me a root shell in single user mode, butthen I was getting the error 'Authentication token lock busy' trying to reset the password. presumably this was because it was read only, so in the bash shell entered

mount -o remount,rw /

this made gave me read-write and then I was able to I was then able to reset the password using the passwd program like normally. wow.

Friday, October 23, 2009

erasing windows passwords



I thought that to fix a windows computer if you've forgotten a password, you needed to like recover the sam file (using like a recovery disk) and crack the password hashes using a program, some complicated process! It turns out that it is actually very simple to just clear the password on the passworded account using a boot disk, without harming anything, using the offline nt password editor - http://pogostick.net/~pnh/ntpasswd/

you burn the boot disk image to a cd using nero or some other program, and the boot disk automatically detects hard drive partitions with windows installed, and the accounts on the computer, and erases the password on the given accounts. It has lots of automatic and default options and is absolutely easy to use, you just literally hit enter a couple times and it will erase the password for you to login to an admin account. too easy

Monday, October 5, 2009

Tuesday, September 29, 2009

doctor fill

I set up emacs to run with the sml/nj for one of my classes, and it turns out for my sanity that emacs comes with this artificial intelligence psychotherapist named doctor fill. it's pretty funny -- here's some things it says
F: Maybe your life have something to do with this.
F: What makes you believe your life has nothing to do with this?
F: Can you elaborate on that?
F: Is it because of the people you hang around with that you are going through all this?
F: I would appreciate it if you would continue.
F: Go on, don't be afraid.
F: Is it because of problems at school that you say you say arghh?
F: My secretary will send you a bill.
F: Bye bye.
It's pretty funny, it just keeps asking you to explain your reasoning, which is pretty good if you're being irrational in the first place. If you want a pretty good personal psychotherapist you can download it here (http://ftp.gnu.org/pub/gnu/emacs/windows/)
get the bin, the barebin download you have to download the sources also so just get the bin. you can use the sml-mode if you create a site-start.el file in the emacs/site-start/ directory.. follow the instructions here http://www.smlnj.org/software.html.

also very newest version (23.1, 07/30/09) has M-x butterfly ... "Do you really want to unleash the powers of the butterfly? (yes or no)"

Saturday, September 19, 2009

record last.fm radio with foobar

I found a weird applciation of some foobar components that allows you to record last.fm radio.

I posted about foo_lastfm_radio earlier, the component let's you not just stream, but sample from a playlist of like 4-8 songs on average. interestingly you can also copy this stream using the foo_converter component. the converter tool automatically comes with foobar. just select any number of songs in the playlist, and then use the converter utility to download the songs.



unfortunately, this method generates transcodes, because of the converter utility, but if you don't care very much about the quality, then this method works pretty well. unfortunently, you cannot use foo_fileops to 'copy' the file from the last.fm radio but there might be a way to copy the radio stream without transcoding it.

Thursday, August 27, 2009

analog-to-digital

I have recently learned how to 'rip' cassettes and stuff to digital so I thought I'd share some tips. I used this technique to rip cassettes but you can defintiely take this advice for ripping vinyl, the procedure is the same, it's just the set up is different. anyways, here's what you need to get started

1) you should get one of these monster icables, or something that joins the rca->1/8'' for your line-in
2) you need 'exact audio copy' [1] to record the audio from the line-in and it helps create a 'cue sheet'
3) then cuetools [2] to split the wav into tracks using the cue sheet


so set it up so you have the cables running into your computers mic slot or line-in and run eac -> tools -> 'record wav'. you should be able to see levels, but if you can't try going into the volume control panel and go to properties -> recording controls and select the line-in checkbox



after you get the levels, just let it record the whole tape, both sides, and then select 'process wav'

in the 'process wav' tool, first delete the leading and ending silence, but not the silence on the tape though, just the silence that is recorded when the tape wasn't even playing. then you place the 'track start' and 'gap start' markers to create a 'cue sheet'. track changes are marked by 'silence' on the tape, and the silence is much easier to see if you use the spectral view instead of the waveform view (view -> spectral).



inserting track start markers generates track n index 1 and gap markers generate track n index 0. insert a track start at the beginning of the tape's first song, and change the first marker marked track 1 index 1 into track 1 index 0 (effectively making the beginning of the recording a pregap until the first song). I also make the end of the tape silence a whole track that I edit into the cue sheet as a postgap.

go through the whole tape and then you basically get a cue sheet that looks like this




tell eac to save this cue sheet and the open it in a text editor to make sure it's correct (sometimes it doesn't export the gaps correctly, or some of the gaps correctly! see [3] you might have to manually edit the cue sheet, the syntax is easy enough) after you have saved the cue sheet then load cuetools and use the default settings

audio output - wav
output style - gaps left out



this will generate all the tracks
Directory of C:\Music\Kites - 2007 - Deny 1\New

01.wav
02.wav
03.wav
04.wav
05.wav
06.wav
07.wav
08.wav
09.wav
CUESheet.cue
the final step is to tag the files and compress the wav. use either musicbrainz or foo_discogs to tag the files, and either foobar2000's converter utility or eac to compress the wav's.

my favorite way to do it is to load the cue sheet into foobar, select the cue sheet and tag it with the foo_discogs plugin, this writes the track metadata into the cue sheet, and then you can give the cue sheet to eac and it outputs the compressed files with properly formatted filenames!

I hope this can help you create proper rips of your music, either with your cassettes or your vinyl

Monday, August 3, 2009

corruption 2




corrupting every frame of a video movie and re-encoding it. source video is some video feedback with high-def digital camera, music is made from some fm synth effects

Wednesday, July 29, 2009

fractals

I got this book called 'chaos in wonderland' and decided to try out mathematica to create some of the fractals in the books. the fractals are 'dynamical systems' described by basically differential equations (x[n+1] can be thought of as a discrete form of dx) [1]

x[n+1] = sin(y[n]*a) + c*sin(y[n]*b)
y[n+1] = sin(x[n]*a) + d*sin(y[n]*b)

my first attempt at code

ListPlot[Table[
xn = N[Sin[y*b] + c*Sin[x*b]];
yn = N[Sin[x*a] + d*Sin[y*a]];
{x = xn, y = yn},
{i, 0, 10000}]]




this worked great. but to create a more functional style of iterated programming, I use the nestlist function which creates a list {x, f(x), f(f(x)), ...}, however instead of the one parameter 'x', I have parameters {x, y}. to deal with this I have to pass nested lists that I flatted at the end

Iter[list_] :=
{
{{x, y}} = list;
xn = N[Sin[y*b] + c*Sin[x*b]];
yn = N[Sin[x*a] + d*Sin[y*a]];
{xn, yn}
}

FSystemsPlot[l_, ax_, bx_, cx_, dx_] :=
{
a = ax; b = bx; c = cx; d = dx;
list = NestList[Iter, {{0.1, 0.1}}, 10000];
ListPlot[Flatten[list,1]]
}]


the book had a list interesting parameters for this system that created these graphs

http://img198.imageshack.us/g/image10jhh.png/

Tuesday, July 28, 2009

someone has set us up the bomb

a new hack is going around that checks what sites you've been too. guess how? the script has a little database of sites and it just checks whether the link is the changed color of when it has been visited

 var link = document.createElement("a");
link.id = "id" + i;
link.href = websites[i];
link.innerHTML = websites[i];

document.body.appendChild(link);
var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");
document.body.removeChild(link);

if (color == "rgb(255, 0, 0)") // the site has been visited :)


demo - http://ha.ckers.org/weird/CSS-history-hack.html

Monday, July 27, 2009

foobar last.fm radio

so, I just found this component that plays last.fm radio straight from foobar, and i couldn't control my love. beautiful!!! it constantly updates a playlist of like 4-7 songs from the last.fm radio, and you can play any of those tracks. i never listened to the last.fm radio before this, but playing 'your personal last.fm radio' from foobar is awesome!!!

http://www.unkempt.co.uk/fb2k/foo_lastfm_radio.html

Saturday, July 25, 2009

dammit dell

"Is there anyone who is not happy with the audio quality of the E6500? I have found that even through high quality headphones, the audio quality is very tinny and lacks proper equalization. If anyone has managed to sort the problem out, it would be great if you can share." http://en.community.dell.com/forums/t/19235508.aspx

I'm pretty mad about this because these awful IDT audio drivers are pretty much to blame for this. the fix? uncheck the mysterious "PC Spk Mute" button in the volume control panel. apparently this setting disables the on-board laptop speakers, and unintuitively, makes headphone/external sound a billion times better. I listened to music for months with the bass turned up to try to compensate for the horrible sound.

Friday, July 17, 2009

physics


I've recently taken an interest in physics (well, so much as to absorb my reading of books and wikipedia articles constantly) because there's just so many interesting explanations for such things as gravity and matter the more you keep reading about it

today, I found these lectures that richard feynman did at cornell in 1964 that bill gates and microsoft have published. they aren't like scientific lectures about physics (typical feynmann lectures are way beyond) this series is called 'the character of physical law' and they're just really entertaining (7 lectures)

http://research.microsoft.com/apps/tools/tuva/

1. The Law of Gravitation, an example of Physical Law
2. The Relation of Mathematics to Physics
3. The Great Conservation Principle
4. Symmetry in Physical Law
5. The Distinction of Past and Future
6. Probability and Uncertainty
7. Seeking New Law

Thursday, July 2, 2009

cool devtools

http://www.resedit.net/ - free resource editor for .rc resource compiler scripts - the dialog wysiwyg editor is great. you can hardcore hardcode handcode win32 stuff but don't code the gui layout, that's tedious

http://www.codeguru.com/cpp/c14981 - visual studio add-on that auto-increments versioninfo in .rc and .rc2 resource scripts, works for almost all versions of visual studio

the version auto-increment is fun, and so far we're at version 1, 3, 1, 137



versioninfo resource http://msdn.microsoft.com/en-us/library/ms647003(VS.85).aspx

Tuesday, June 30, 2009

evil!



totally evil

Friday, June 26, 2009

choons

Alright, my second itunes monitor plug-in is in working order



Features:

-automatically updates the aim status bar with the song playing in itunes
-can be minimized to the notification tray while it is running
-the program is multithreaded to support multiple interfaces 'event sink' interfaces

Download - http://zxcvbn.googlecode.com/files/itunes-nowplaying.zip
Source - http://zxcvbn.googlecode.com/svn/trunk/itunes/
Wiki - http://code.google.com/p/zxcvbn/wiki/choons

see: CAccEventSink (AimEventHandler), _IiTunesEvents, IDispatch, IUnknown (ItunesEventHandler), GetFileVersionInfo (AboutDlg)

see also: my other itunes plugin

source - http://zxcvbn.googlecode.com/svn/trunk/habit/
wiki - http://code.google.com/p/zxcvbn/wiki/habit

Monday, June 22, 2009

father's day

Image Hosted by ImageShack.us

live demo

I made this for father's day, it's his company logo and I animated the colors using javascript dom

Sunday, June 14, 2009

phoken brone



that's the outside lcd, the inside is fine

memory feetprints

microsoft's sql server (sqlserv.exe) is really great at taking up all the free memory on my computer ... the default behavior of the server is to allocate the entire memory pool and give it back to the system when it's requested http://www.cisco.com/en/US/ts/fn/200/fn29019.html

Wednesday, June 10, 2009

shredded windows

the windows 95 screensaver, resolume video editor, synth noise, this


windows 95 shenanigans



...



...



brian eno did the startup sound ^^

Saturday, June 6, 2009

slit scanning flash applet

I converted this project from http://blog.onepixeloff.com/index.cfm/2006/12/2/Slit-Scan-Camera-Experiment-In-Flash

http://zydecogroup.com/scanner.html



new features:

- is able to save captures to local hd as jpeg
- converted from as2 to as3

you can get the fla source here
http://zxcvbn.googlecode.com/files/scanner.zip

keywords: as3corelib, FileReference.save, Camera.getCamera, JPGEncoder.encode

Wednesday, May 27, 2009

texture mapping glitch



uninitialized texture

diabetes explosion



from s30e19, feat the will ferrel's cowbell skit

Monday, May 25, 2009

vim



I think I figured out vim finally, you like press exit to get into insert mode --

Sunday, May 24, 2009

Thursday, May 21, 2009

distorted



opengl image viewer