Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
Wednesday
Feb022011

Over Compressed Audio

These images don’t tell you you bad it is going to sound…..

This evening I thought I’d spend a few minutes taking some of my old records and making them into MP3 tracks. I’m not sure about the legal issues here, but since I’m not going to actually sell the recordings I think I should be OK. Years ago I recorded some albums by just recording the entire record and converting it into MP3.  What I wanted to do now was just pull out individual tracks. I used Audacity, the best audio editing program you can get. It is free and works a treat.  If you want to play with audio, get a copy here:

http://audacity.sourceforge.net/download/

A tip, the latest beta (1.3.12) is the one that you should use for Windows 7 and works fine. It also seems to have the MP3 encode/decode built in.

Anyhoo, I opened up each large MP3 file and then laboriously saved the sections that held each track. And was rewarded with some recordings that sounded, well, horrible. Horrible, horrible. Then I realised what I’d just done. I’d taken a compressed signal, decompressed it and then recompressed it again. They tell you not to do this, and blimey they are right.

Next step is to dig out “Ye Olde Recorde Deqque” and re-record uncompressed (wav files I guess) of the records and then save sections of these to compressed form. Oh well.

One of the records I was converting was Andrew Gold, “What’s wrong with this picture” which has one of the best record sleeves ever:

image

See if you can find a high resolution copy of the image and find all 32 mistakes in it…..

Tuesday
Feb012011

Reference and Value Types

IC 2007 Fri Trip f10 124

 

I reckon that the day I give a lecture and don’t learn anything is the day that I will give up teaching. I always take something away from a lecture, although sometimes it is only a decision not to use that particular joke again…

Today I was telling the first year about reference and value types in C# and I learnt something as well. For those of you who are not familiar with programming in C# (and why should you be?)  this is all about how data is held in a program.

Once you get beyond programs that do simple sums you find yourself with a need to lump data together. This happens as soon as you have to do some work in the Real World™. For example, you might be creating an account management system for a customer and so you will need to have a way of holding information about a particular customer account. This will include the name of the customer, their address and their account balance, amongst other things.

Fortunately C# lets you design objects that can contain these items, for example a string for the name, a number for the balance, a string for the address and so on.  In fact, C# provides two ways that you can lump data together. One of these is called a struct (short for structure) and the other is called a class (short for class). These two can be hard to tell apart, in that the way that they are created is exactly the same. But they have one very important difference. Structures are managed by value, but classes are managed by reference.

Today is the point in the course where I have to explain the difference between the two.  I’ve got a routine for doing this which I’ve used in the past, and it usually gets there. If an item is managed by value (for example a struct) you can think of it as a box with a name painted on it.  If we move data between two variables managed by value:

destination= source;

- the result is that whatever value is in the source box is copied into the destination box. If my source is a structure value which contains lots of elements all of these are copied into the destination. This is how simple variables such as integers and floating point values are managed.

However, if an item is managed by reference the effect of the assignment above is different. You can think of a reference as a named tag which is tied to an object in memory. If I assign one reference to another:

destination = source;

- the result of this is that both reference tags are now tied to the same object in memory.  No data is actually copied anywhere.

At this point in the explanation I usually have a room full of people wondering why we bother with references. They just seems to be an added piece of confusion. Now that we have references we have the potential for problems when the equals behaviour doesn’t do what we expect.  Why do we have these two ways of working with data? Why can’t we just use values for everything?

My answer to this is that using references allows us to provide different views of data. If I have a list of customers that I want to order by both customer name and account number then this is not possible with a single array of values. But if I use references it is much easier. I can have a list of references which is ordered by name and another list ordered by account number.

So far I’m going by the slides. But then it occurred to me to go a bit further, and think about the use of reference and value types from a design point of view. If I’m designing a data structure for a  sprite in a game (for example a single alien in a Space Invaders game) the sprite will have to contain the image to be used to draw the sprite and the position of the sprite on the screen. I posed the question which of these two elements should be managed by value and which by reference.

After some discussion we came to the conclusion that it is best if the image to be used to draw the sprite is managed by reference. That means that a number of sprites can hold references to the same sprite design. You see this a lot in computer games, where a game has multiple identical elements (soldiers, cars, spaceships etc) it is often the case that they are all sharing a single graphic. However the position of the sprite on the screen is a value that should be unique to each sprite, we are never going to want to share this, and so the position should be a value type.

We then went through a bunch of other situations where an object contains things, and pondered for each thing whether it should be managed by value or by reference. Generally speaking we came to the conclusion that anything you want to share should be managed by reference, but stuff that is unique to you should be a value.

Of course references bring a lot of other benefits too, which we will explore in the next few weeks, but the thing I learnt was that the more you can show a context in which a particular language characteristic is applicable the more chance you have of getting the message across.

As a little puzzle, one thing we talked about was the storage of the address of a customer in our account database. Should that be managed by value or reference, and why?

Monday
Jan312011

Save Dalby Forest

Dalby Forest with Horse

Dalby forest is one of my favourite places in the country. We go there a couple of times a year with a packed lunch and just wander round the place. Years ago, when the kids were smaller, we used to go and have barbeques. It’s just a nice place with loads of trees and some lovely walks.

Dalby Forest Bridestones

And if the government have their way I won’t be able to go there much longer. They have this cunning plan to sell off, or lease, or give away, or whatever, the forests in the UK. This will save them some money and avoid them having to levy so much tax on very rich people. Or something.  It will also almost certainly mean that places like Dalby Forest will be out of bounds to folks like you and me.

Dalby Forest Path

I’m not a particularly political person. My theory is that whoever you vote for the government always gets in. I’m also very aware that there are much more important things out there than whether or not Rob has a nice place to go and have his picnics.  But I’m also aware that there are a lot of us packed onto this tiny little island,  and that the few really nice green spaces that we have left should be protected, not sold off for profit.

There is a petition you can sign up to if you want your voice to be heard on this matter. I’ve already done so. You can find it at the Woodland Trust web site:

http://www.woodlandtrust.org.uk

Sunday
Jan302011

Lazy Sundays Don’t Exist

Space Needle.jpg

I was planning a kind of lazy Sunday. Soundproof my PC, wash the cars, find out who murdered Clarissa Lisle and so on. That’s kind of how it turned out. Except that nothing was quite as easy as it was supposed to be. First off was soundproofing. Having obtained a soundproof kit from http://www.akasa.com.tw/ I set about fitting it to the PC. This involved taking off all the panels and sticking what looked like a cross between foam and felt on each of them. The instructions mentioned that it was a bad idea to block up any ventilation holes and I agree with this, so I had to cut out gaps for the air to get in and out, which was kind of fun and left me with lots of odd foam shapes that I can put to one side in case they might be useful one day and then throw away in a couple of years’ time.

I managed to get all the cutting and sticking done and then carefully reassembled the PC and slotted it into place under the desk, forgetting the golden rule that is “Always test it before you put the lid on”. Of course, once I’d connected all the network, usb, video, power and audio cables I found that the machine no longer started when I pressed the go button.

A tip, if you are not sure whether or not power is reaching your PC, listen carefully as you plug in the mains cable. You should hear a tiny “crack” as the plug goes in. This is a smoothing capacitor in the power supply charging up. If you get this then there is a good chance that the fault is in the output of the PSU, not the input. I was hearing the sound, and so I knew that something was wrong inside the box. Of course. So I removed all the cables, pulled the machine back, took the side off and found that I’d managed to dislodge some cables from the motherboard. Since these were the ones connected to the power switch it was fairly obvious where the fault was. Pushed them back in, tested the machine with the lid off (even at my advanced years it is still possible to learn stuff) and then, having heard the happy sound of fans whirring into life, put everything back into place. It is a bit quieter with the padding. Most of the noise seems to be air moving around, which is difficult to silence completely. The machine itself seems nicely quick, and I’m looking forward to doing some serious work on it. I’ve even managed to get my old, broken, mouse back working again by the simple expedient of putting in some batteries that work, rather than a replacement set that seem to have been pre-flattened before I got them.

Next up was wash the car. Some people drive down to a car wash but I’m not one of them I’m afraid. I’m more of a “bucket and sponge” kind of guy. The main reason for this is because I like the idea of going carefully over the car looking for damage. Particularly at this time of year, when the authorities drop loads of salt and sharpened stones on the road which are then shot at your car by the tyres of the one in front. I was sad to see a bit of stone damage to the front of the Cube, which meant a trip down to Halfords for the right coloured paint and a little bit of touch up action, which sounds vaguely rude but actually just involved me and a very small pot of paint. I don’t think that the problem is completely solved, but at this time of year the best you can hope for is a holding action until the weather improves.

On the way back into the house I noticed that one of the tyres of the other car looked a bit flat. Or was it standing in a puddle? No, the tyre was on the flat side of flat. Something to do with the galvanised steel nail stuck in it. Ho hum. I’ve pumped the tyre up and if it still has some air in tomorrow this should get the car as far as the nearest repair place. So, I’ve done lots of stuff but still not found the murderer. I’m reading a story by PD James, “The Skull Beneath The Skin”. It took a while to get going, I was half way through before anyone got their clogs popped, but things are now hotting up nicely with a grisly death in a locked room and a whole drawing room full of suspects with their own motives and alibis. I do like murder mysteries, and PD James plays very fair with her plots. There is lots and lots of well written detail about the characters and the locations inside which are scattered enough clues to get you thinking. And this particular story even has a suspicious butler, which really marks it for greatness.

I’m reading the book on the Kindle, which is a lovely device for consuming things like this. Some books you want to own (those are the ones with big pages and coloured pictures) and some books you buy just to read once and throw away (those are the ones by John Grisham). The Kindle does the second type of books very well. I’d been put off the idea of an electronic book by the fact that you never actually own anything. It wasn’t until I realised that I didn’t want to actually own some of the books, but just read them that I actually cottoned on to the plot as it were.

The good news for us I guess is that eventually we will end up with a house full of books that are actually nice to own, rather than lots of paperbacks that we bought and now don’t quite know what to do with. Eventually they find their way down to the charity shop, which is fair enough but involves me having to do something, which is not great. And I often come back with more books than I took. We used to have a weekly pilgrimage to the library when we were younger, but I’ve not been there for a while. I used to get books about subjects that I found interesting, like advertising, and then read a whole bunch. I don’t have as much time for that kind of thing just right now, but I’d like to think I could go back and the books will still be there. Even with the magic of the Kindle and the interweb there is still something nice about walking down a row of books and picking out one to read. I hope we still have that in the future. Anyhoo, back now to a world of shady characters and murky plotting. And I might read some of the book as well...

Saturday
Jan292011

Tangled Movie Review

Note: I’m having a long weekend. I’m making my blog posts at least 1,000 words long for the next couple of days. Just to see if I can. You don’t have to read them all. Normal, truncated, service will be back next week.

image

Tangled is the latest animated film from Disney. It follows in the footsteps of some pretty heavy hitters like Little Mermaid, Beauty and the Beast and Aladdin. Unfortunately Disney has also made some pretty dodgy animated films as well. Anyone remember Lilo and Stitch? In a good way? Opinions in the reviews were pretty sharply divided, with critics either praising it to the heavens or calling it lacklustre and run of the mill. As we sat down with our popcorn I was consoled by the fact that most of the nastier reviews had been in the posh papers.

We were seeing the film in 2D instead of the much touted 3D. This was not because we couldn’t afford the 3D seats (although the difference in price had paid for the drink and meal combo that we carried gingerly into the theatre), but because we happen to prefer to see our movies the way that they are supposed to be made. Flat. There is a very good discussion of why 3D doesn’t work out there on the web somewhere, I recommend that you seek it out (search for “Why 3D doesn't work and never will” by Roger Ebert). Essentially he makes the point that when you watch a 3D movie your eyes have to focus at a fixed distance on the screen. But when you see 3D your brain thinks that the 3D bits are different distances away. The 3D seeing part of your brain then has to override the 2D part of your eyes to make the scene look right. In the 600 million years that the brain has been developing to give us useful 3D vision it has never had to do this before and the resulting mental tussle gives me (and lots of people) a headache after a while. Actually, there is another good reason why we only saw the 2D version. Due to a quirk of fate number one wife and I only have two good eyes between us (fortunately we were given one each) and so we don’t really miss the third dimension much. And anyhoo, although there were a few bits obviously added for 3D (point stuff at the audience and swing it around, lots of tiny particles etc etc) seeing it in 2D didn’t really make much difference. We were pleased to see that the theatre was packed with people who didn’t mind missing 3D either.

But back to the film itself. I’m not giving too much away if I tell you that the film is a reworking of “Rapunzel”, the fairy tale about the girl in the tower with the unfeasibly long locks. And they’ve done a pretty good job. If you know the story you’ll appreciate the stuff they’ve put in to make it interesting. If you don’t you’ll just appreciate the story. The villainess of the piece is very well portrayed, one of the better and more plausible fairy tale nasty’s and the hero and heroine are nicely matched. The music is not intrusive. It’s not a musical film (or of course I would not have gone) but the songs that they do are very well realised and enjoyable in a hum along but then forget after the film kind of way. The best one is the set piece in a lair of ner-do-wells which manages to echo some of the best of the song about Gaston in Beauty and the Beast (I don’t dislike all musicals, just ones that aren’t Beauty and the Beast).

The film is all computer rendered, but looks very lush. The fabric on the clothes is particularly impressive, especially the dress worn by the villainess (I’m wondering if we now call female baddies villains, in the same way that actor and comedian have now gone unisex. Perhaps this is something I’d best not dwell on). But the cloth does look very real, as if there actually was a character wearing clothes, rather than a surface with a texture on it. The characters look good, move well and fit their voices. Disney spent a lot of money on this film and it shows.

I liked the film a lot. It has been unfavourably compared with Shrek, another reworking but of a less popular children’s tale. I think this is unfair. Shrek had the advantage that nobody (or at least me) knew how it would turn out and did have some really standout actors voicing the characters. One big advantage of Tangled is that it is unlikely that we will see any massively inferior sequels, something that was unfortunately not true of Shrek. The critics also compared Tangled unfavourably to films by Pixar, saying that it lacks the wit and invention of some of their efforts. I kind of agree, but the producers are a bit constrained by the fact they are reworking a fairy tale. There is little chance of a cute robot or house dangling from balloons being able to make an appearance, and at least they avoided making any crass references to contemporary culture that can date a film faster than side splitting jokes about Betamax. The characters they have added to fill out the story are good, with a particular call out to Maximus the horse, who would get a film of his own if there was any justice in the world.

So, to sum up I really enjoyed the film. So did the rest of the theatre. If it can keep an audience made up of around 40% kids under 10 quiet (and me) then it must have something going for it. It is a genuinely nice story with well defined baddies and a good solid triumph of good over evil. The computer graphics are some of the best that you will see at the moment and it has the Disney trademark of lots going on in the background that marks some of their best work. The songs aren’t the best in my opinion, but they are OK and you will not leave the theatre feeling shortchanged. In fact you should work out feeling that you have just seen a really good film. I did.