Converting AMR to MP3 29 October 2009
Posted by ojmason in misc.add a comment
For a teaching project, students were required to audio record a group discussion meeting. For this they could either use a digital recorder, or any other recording equipment they had available. One group used a mobile phone, and we managed to transfer the audio file from the phone to my MacBook using Bluetooth.
Initially I was surprised at the small size of the file: 4.5 MB for a recording of about 50 mins. The quality is of course poor, but AMR does a pretty good job of keeping it small. The equivalent MP3 file comes in at 22.5 MB.
But there was a problem: dealing with AMR files. I cannot load it into my version of Audacity to convert it to MP3, but perhaps there’s a plug-in somewhere. I was not able to immediately find one. Then I found that Quicktime can play back AMR files, and save them in other formats, but for that you need to fork out money to get the Pro version. I then tried out iMovie, and managed to import the file as the sound track of a yet to complete movie. Attempts to extract the audio were fruitless; but then I accidentally noticed that the sound track was referred to as ‘aiff’ file. I opened the movie project package, and, hey presto, there was an aiff file. iMovie had converted it during the import.
So now I could import that into Audacity, and export from there to MP3.
Thinking Erlang, or Creating a Random Matrix without Loops 26 February 2009
Posted by ojmason in erlang, misc, programming.9 comments
For a project, my Erlang implementation of a fast PFNET algorithm, I needed to find a way to create a random matrix of integers (for path weights), with the diagonal being filled with zeroes. I was wondering how best to do that, and started off with two loops, an inner one for each row, and an outer one for the full set of rows. Then the problem was how to tell the inner loop at what position the ‘0′ should be inserted. I was thinking about passing a row-ID, when it suddenly clicked: lists:seq/2 was what I needed! This method, which I previously thought was pretty useless, creates a list with a sequence of numbers (the range is specified in the two parameters). For example,
1> lists:seq(1,4). [1,2,3,4] 2> lists:seq(634,637). [634,635,636,637] 3> lists:seq(1000,1003). [1000,1001,1002,1003]
Now I would simply generate a list with a number for each row, and then send the inner loop off to do its thing, filling the slot given by the sequence number with a zero, and others with a random value.
But now it gets even better. Using a separate (tail-)recursive function for the inner loop didn’t quite seem right, so I thought a bit more about it and came to the conclusion that this is simply a mapping; mapping an integer to a list (a vector of numbers, one of which (given by the integer) is a zero). So instead of using a function for filling the row, I call lists:seq again and then map the whole thing. This is the final version I arrived at, and I’m sure it can still be improved upon using list comprehensions:
random_matrix(Size, MaxVal) ->
random:seed(),
lists:map(
fun(X) ->
lists:map(
fun(Y) ->
case Y of
X -> 0;
_ -> random:uniform(MaxVal)
end
end,
lists:seq(1,Size))
end,
lists:seq(1,Size)).
This solution seems to be far more idiomatic, and I am beginning to think that I finally no longer think in an imperative way of loops, but more in the Erlang-way of list operations. Initially this is hard to achieve, but with any luck it will become a lot easier once one is used to it. Elegance, here I come!
Example run:
4> random_matrix(6,7). [[0,1,4,6,7,4], [3,0,5,7,5,4], [5,1,0,2,5,2], [4,2,4,0,3,1], [4,4,3,3,0,1], [5,7,3,2,2,0]]
Note: I have used random:seed/0 above, as I am happy for the function to return identical matrices on subsequent runs with the same parameters. To get truly random results, that would have to be left out. However, for my benchmarking purposes it saved me having to save the matrix to a file and read it in, as I can easily generate a new copy of the same matrix I used before.
Dealing in meteorites 9 April 2008
Posted by ojmason in misc.add a comment
While clearing out a decade’s worth of paper from my office I came across an article in the Feb 2003 issue of the university’s in-house paper, Buzz. In one article, the following extract struck me: … artists had acquired a meteorite from a meteorite dealer in Scotland.
Several questions come to mind: Can you make a living as a meteorite dealer? I guess there are more meteorites hitting Earth as one would think, not all of course big enough to make (no pun intended) an impact. And why Scotland? Is Scotland especially prone to being hit by meteorites?
Thanks to the web, the first question can be supplemented by a useful snippet of information: Over the whole surface area of Earth, that translates to 18,000 to 84,000 meteorites bigger than 10 grams per year. But of course 70% of that end up in the sea, and most of them never make it through the atmosphere in the first place. I also don’t want to speculate how much demand there is for meteorites, other than from conceptual artists and perhaps astrophysicists.