Archive for December, 2009
Rip audio from mp4
Posted by bumscientist in Computing on December 28, 2009
$ ffmpeg -i video.mp4 -f aac -vn -acodec copy audio.m4a
ICC Profile Part 2
Posted by bumscientist in Photography on December 26, 2009
After reading up on the ICC profile specification, it seems that there are many ways to define the color mapping, so I think it would be better to start off from reading a color profile. Thankfully drycreekphoto has the color profile for my local printer, which was just updated in August. If I need to look up any color transforms from one color space to another, there is this handy site by Bruce Lindbloom.
Here’s the comparison between the supposed values and the uncalibrated scanned image.
Stacking a Texas Hold’em Deck
Posted by bumscientist in Computer Science on December 23, 2009
I saw an interesting trick on Scam School. It turns out that you can stack a deck in such a way that the dealer always wins no matter how you cut the deck. This deck was found by Ben Joffe and detailed here.
Transparent solar cells
Posted by bumscientist in Engineering, Science on December 23, 2009
Can a solar cell be transparent?
The answer is yes, but you wouldn’t particularly want to unless you have some application like solar windows. The sun is a black body radiator at 5777 K. For a solar to be transparent it has to allow the visible spectrum (380 to 750 nm) through, but absorb the rest.
If we look at where the energy from the sun lies, you get
- 10% in the short wavelength
- 44% in the visible
- 46% in the long wavelength
So there is about just as much energy in the infrared and longer as there is in the visible, but the peak energy is in the visible. The way inorganic solar cells work is that they start absorbing at a certain wavelength and lower wavelengths with less efficiency.
MIT is working on solar cells that can be integrated into windows. Here’s a treehugger article.
One thing that decreases long wavelength energy production is that molecules in the atmosphere absorb certain frequencies as vibrational modes.
Aquarium Stand
Posted by bumscientist in Ramblings on December 22, 2009
Here’s a cheap aquarium stand design made with 6 2″x4″x96″ dimension lumber with rabbet joinery at a cost of ~$20.
Java and 16 bit sound
Posted by bumscientist in Computer Science on December 18, 2009
Here’s the same sound code, but for 16 bit sound instead of 8 bit sound. So, the number of bits tells you how high your signal to noise is. Each bit is about 6 dB, so 16 bits, means 96 dB is about as good as you going to get for a noise level off your sound. If you can keep your noise level below 96 dB, then you can enjoy the full dynamic range of your sound.
import javax.sound.sampled.*;
import java.lang.Math.*;
public class tonegenerator{
public static void main (String args[]){
float sampleRate = 44100;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = true;
int offset = 0;
int bufferSize = 44100*1*2;
byte[] data = new byte[bufferSize];
byte ci = 0;
short s;
for (int ni = 0; ni < bufferSize/2; ni ++){
s = (short)(32767*Math.sin(2*Math.PI*ni*1000/44100));
data[2*ni] = (byte)(((0xff << 8 ) & s) >> 8);
data[2*ni+1] = (byte)((0xff & s));
}
try{
Clip clip = AudioSystem.getClip();
clip.open(new AudioFormat(sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian), data, offset, bufferSize );
clip.start( );
}
catch(Exception e){
}
}
}
Sound in Java
Posted by bumscientist in Computer Science on December 16, 2009
Here’s a simple java program that should generate A440.
tonegenerator.java
import javax.sound.sampled.*;
import java.lang.Math.*;
public class tonegenerator{
public static void main (String args[]){
float sampleRate = 44100;
int sampleSizeInBits = 8;
int channels = 1;
boolean signed = true;
boolean bigEndian = true;
int offset = 0;
int bufferSize = 44100*1;
byte[] data = new byte[bufferSize];
byte ci = 0;
for (int ni = 0; ni < bufferSize; ni ++)
data[ni] = (byte)(127*Math.sin(2*Math.PI*ni*440/44100));
try{
Clip clip = AudioSystem.getClip();
clip.open(new AudioFormat(sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian), data, offset, bufferSize );
clip.start( );
}
catch(Exception e){
}
}
}
Spacepirates: Quaternions
Posted by bumscientist in Ramblings on December 15, 2009
So you have a ship in space that you want to rotate so it will be faced toward your destination before apply the boostering to get there.
v_{ship} and v_{dest} are the position vectors of the ship and the target.
v = v_{dest} – v_{ship}
To avoid the ships having any weird rotated angles, I’ll be confining rotations to yaw and the then pitch, which can be defined with theta and phi
theta = atan(v_y/v_x);
d = sqrt(v_x^2 + v_y^2)
phi = atan(v_z/d)
So the rotation that points to direction is Rz(theta) and then Rwing(phi). Assuming your unrotated mesh is facing in the x-direction.
To move the ship, you spherically linear interpolate from its current rotation to the required rotation. The angle between the two vectors, where you are pointing now and where you want to point can be calculated with the law of cosines. Speed of rotation will be limited, so only a certain angle change will be allowed per time step.
Command line java
Posted by bumscientist in Computer Science on December 15, 2009
It’s been a while since I’ve touched java. I’d figure I’d not use an IDE and just do it from the command line.
HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
$ javac HelloWorld.java
$ java HellowWorld





