Archive for November, 2009
Old school Nokia ringtones
Posted by bumscientist in Music, Ramblings on November 29, 2009
I found some really old code today. In the early days of the cellphone before middle schoolers and elementary schoolers had cellphones, the ringtones for Nokia phones were input using an ancient code.
Here’s the zelda theme, which I scrapped off a website a long time ago.
| 4#a1, 4.f1, 8#a1, 16#a1, 16c2, 16d2, 16#d2, 2f2, 8-, 8f2, 16.f2, 16#f2, 16.#g2, 2.#a2, 16.#a2, 16#g2, 16.#f2, 8.#g2, 16.#f2, 2f2, 4f2, 8#d2, 16#d2, 16f2, 2#f2, 8f2, 8#d2, 8#c2, 16#c2, 16#d2, 2f2, 8#d2, 8#c2, 8c2, 16c2, 16d2, 2e2, 4g2, 8f2, 16f1, 16f1, 8f1 |
Here’s some MATLAB/OCTAVE code
function nokia2wav (filename, tempo)
Fs = 44.1e3;
if (nargin == 0)
filename = 'zelda.txt';
end
if (nargin < 2)
tempo = 125;
end
% read in file and turn it into a long string
fid = fopen(filename);
notebuf = '';
while feof(fid) == 0
notebuf = [notebuf fgetl(fid)];
end
fclose(fid);
% convert to wav
y = NOKIAtoWAV(notebuf, tempo, Fs);
% write wav file
[buf rem] = strtok(filename, '.');
wavfilename = [buf '.wav'];
wavwrite(y', Fs, wavfilename);
function y = NOKIAtoWAV (str, tempo, Fs)
%NOKIATOWAV converts a string of nokia text into a wavefile
%
% y = NOKIAtoWAV (str, tempo, Fs)
%
% input:
% str - nokia text string
% tempo - beats per minute
% Fs - sampling frequency
%
% output:
% y - waveform
%
% parse the string to individual NOKIA notes
notes = words(str,',');
% convert each NOKIA note into a frequency and duration
for m = 1:length(notes)
[midi(m) t(m)] = analyzeNOKIAnote(notes(m,:), tempo);
end
% massage data
midi = midi';
t = t';
% assignment allocation
nend = length(midi);
y = 0;
p = 0;
% keep adding next note to waveform
for n = 1:nend
y = [y generatenote(MIDItoFreq(midi(n)), t(n), p, Fs)];
p = asin(y(length(y)));
end
%------------------------------------------------------------------------------
% String Tokenizer
%------------------------------------------------------------------------------
function allWords = words(inputString, delim)
%WORDS parses string by delimiter
%
% allWords = words(inputString, delim)
%
% input:
% inputString - input string
% delim - delimiters
% output:
% allwords - array of parsed strings
%
remainder = inputString;
allWords = '';
while (any(remainder))
[chopped,remainder] = strtok(remainder, delim);
allWords = strvcat(allWords, chopped);
end
%-------------------------------------------------------------------------------
% Turn NOKIA string into freq and duration
%-------------------------------------------------------------------------------
function [midi t] = analyzeNOKIAnote(str, tempo)
%analyzeNOKIAnote
%
% [midi t] = analyzeNOKIAnote(str, tempo)
%
% input:
% str - NOKIA note
% tempo - beats per minute
%
% output:
% midi - frequency
% t - duration
%
% split duration and frequency
[duration note] = strtok(str,'abcdefg#-');
t0 = 4*60/tempo;
% compute duration
[duration onehalf] = strtok(duration,'.');
t = t0*1/str2double(duration);
midi = 100;
if(length(onehalf));
t = 1.5*t;
end
% compute frequency
note = strtrim(note);
if strcmp(note,'c1')
midi = 60;
elseif strcmp(note,'#c1');
midi = 61;
elseif strcmp(note,'d1');
midi = 62;
elseif strcmp(note,'#d1');
midi = 63;
elseif strcmp(note,'e1');
midi = 64;
elseif strcmp(note,'f1');
midi = 65;
elseif strcmp(note,'#f1');
midi = 66;
elseif strcmp(note,'g1');
midi = 67;
elseif strcmp(note,'#g1');
midi = 68;
elseif strcmp(note,'a1');
midi = 69;
elseif strcmp(note,'#a1');
midi = 70;
elseif strcmp(note,'b1');
midi = 71;
elseif strcmp(note,'c2');
midi = 72;
elseif strcmp(note,'#c2');
midi = 73;
elseif strcmp(note,'d2');
midi = 74;
elseif strcmp(note,'#d2');
midi = 75;
elseif strcmp(note,'e2');
midi = 76;
elseif strcmp(note,'f2');
midi = 77;
elseif strcmp(note,'#f2');
midi = 78;
elseif strcmp(note,'g2');
midi = 79;
elseif strcmp(note,'#g2');
midi = 80;
elseif strcmp(note,'a2');
midi = 81;
elseif strcmp(note,'#a2');
midi = 82;
elseif strcmp(note,'b2');
midi = 83;
elseif strcmp(note,'-');
midi = 0;
else
note;
end
midi = midi;
function f = MIDItoFreq(MIDInum)
%MIDItoFreq gets the frequency of a MIDI note number
%
% f = MIDItoFreq(MIDInum)
%
% input:
% MIDInum - MIDI note number
%
% output:
% f - frequency of MIDI note number
%
f = 440*(2^(1/12).^(MIDInum-69));
function y = generatenote(f, t, p, Fs)
%generatenote generates a wav of a certain frequency and duration
%
% y = generatenote(f, t, p, Fs)
%
% input:
% f - frequency
% t - duration
% p - phase shift
% Fs - sampling frequency (usually 44.1 kHz for audio)
%
% output:
% y - waveform
%
% t in seconds
t = 0:Fs*t;
y = sin(2*pi*f/Fs*t+p);
% add fade to eliminate pops
x0 = round(10e-3*Fs);
y(end-x0+1:end) = y(end-x0+1:end).*linspace(1,0,x0);
ICC Profile
Posted by bumscientist in Photography on November 29, 2009
I’m too cheap to pay lots of money for color management solutions from X-rite. I already have a gretag-macbeth colorchecker chart, so that’s a sunk cost. I originally planned to use it to calibrate my scanner and camera. I wrote some MATLAB code to analyze the scanned image and did some tweaking on the settings to improve the color, but it was time consuming, because I had to do it iteratively. I looked at the documentation for the ICC profile and I think I can write some MATLAB code to adjust the colors. I think this project usurps the astrolabe, because I haven’t bought the astrolabe book required to design an astrolabe. I also want to scan some old pictures during the christmas break. I’ll put up the MATLAB code for it and try to make some money by putting an affiliate link to amazon for the color checker target.
Waste Heat
Posted by bumscientist in Science on November 29, 2009
I’ve read of pools built next to data centers to make use of the heat generated by the racks of servers, but what about in one’s own home. I have a 750 W/1500 W space heater. Would I get the same amount of heat if I ran 750 W work of computers? The energy has to go somewhere, so I would think that those 750 W would be more useful if they were spent on computation in addition to heating up my room on a cold cold San Francisco night. I’ve noticed a room being warm when I turn on a bunch of pumps and electronics, but I never tried this in my own room. I only have about 300 W of electronics (PS3, KPC, MBP, 24″ LCD) to operate at one time in my effort to reduce how much electricity I use. I think the LCD doesn’t contribute to heat since it gives off light.
The popular vote
Posted by bumscientist in Ramblings on November 29, 2009
Let’s say we have 9 people total, representing 3 classes such that there are 3 people in each class. If a class has a majority vote, then it takes the votes of the whole class, so a possibility is
Class 1 – A, A, B
Class 2 – A, A, B
Class 3 – B, B, B
Popular vote puts 5 Bs to 4 As, or 56% in favor of B, but if we use an electoral college like system, then it will be 2 As to 1 B, or 66 % in favor of A.
So the popular vote can be 56% in favor of B, but A can win the electoral vote with 66%. That’s a 22% swing in the vote, almost a quarter. I wonder which way makes more sense.
YKK on Your Zipper
Posted by bumscientist in Ramblings on November 28, 2009
Newsflash
Posted by bumscientist in Ramblings on November 28, 2009
I grossly underestimate the time it takes me to do things. Time to do less, because it is all that I can do. Do less and do it well, so I don’t have to do it again.
SSH Host Keys
Posted by bumscientist in Computers on November 28, 2009
A machine I’ve been remotely connecting to was compromised recently forcing me to change my password into a new stronger password. I don’t pay as much attention to security as I should. I should be more careful about host keys, but I don’t think I can easily get the fingerprint until after I’ve made the first connection.
Find your fingerprint of your server with
$ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
This should match with the fingerprint when you try to ssh into the server. If it doesn’t match, then you have a problem.
Scroogenomics
Posted by bumscientist in Ramblings on November 26, 2009
Maybe I should rethink gift giving since I might be destroying value according to this interview on marketplace. One way to retain value is to give awesome gifts or give cash.
Astrolabe
Posted by bumscientist in Musings, Science on November 24, 2009
I love watching TED videos, because they are always so inspiring. This latest one about the astrolabe is conjuring all types of images of early explorers and old school science and astronomy. I’m tempted to design on and build it through ponoko, but unfortunately it seems it will be quite expensive and they can not etch brass, only cut. I might try to make it out of acrylic depending on costs.
Git
Posted by bumscientist in Computing on November 24, 2009
My history with version control is as follows.
cvs – used it only to get source to compile
svn – setup a server for myself, but didn’t really use it much
git – setup on my server, actually making use of it.
So far, I’m liking git, svn wasn’t too bad, but it was a bit more difficult to setup. There’s got to be a reason why everyone is switching over to git. I watched the google Linux talk, but didn’t understand it that well. Now I think it get it a bit more.
Quick Reference
On remote system
$ sudo adduser git
$ cd /home/git
$ mkdir example.git
$ cd example.git
$ git –bare init
On your system
$ git config –global user.name “Your Name Comes Here”
$ git config –global user.email you@yourdomain.example.com
initialize
$ mkdir example
$ cd example
$ git init
committing
$ touch README
$ git add README
$ git commit –m ‘first commit’
$ git remote add origin git@REMOTE_SERVER:example.git
$ git push origin master
cloning
$ git clone git@REMOTE_SERVER:exmaple.git myrepo
pulling
$ git pull origin master