Archive for February, 2007

February 21st 2007

C/C++

I hate that term. People write it on job applications and job specifications. People use it in conversation. People use it on reference sites and books, gah.

I hate it because it gives C++, a lovely language, a bad name. Below are some examples, both of these are nowhere near the most efficient way to do these in either language, but they are the most obvious way, and the ones you’re likely to see:

C
#include <stdio.h>

int main()
{
char name[20];

// Crash here if name > 19 characters:
gets(name);

{
int length = strlen(name) + 4;

// Manual memory allocation, no exception safety.. wait, what exceptions?!
char *row = (char *) malloc(length);
int i;

// Clean the memory so strcat works:
memset(row, 0, length);

for (i=0; i < length; ++i)
strcat(row, "*");

strcat(row, "\n");

// What does that format string do? Nobody knows.
printf("%s* %s *\n%s\n", row, name, row);

// Cleanup:
free (row);
}
}

C++
#include <iostream>
#include <string>

using namespace std;

int main()
{
string name;
getline(cin, name);

string row;

for (int i=0; i < name.size() + 4; ++i)
row += "*";

row += "\n";

cout << row <<
"* " << name << " *\n" <<
row << endl;

return 0;
}

I hope, from that, you can see that there’s absolutely no similarities at all, in any way, between those two programs (they both do nearly the same thing, differing only in that you can easily crash the C one).

Ignoring the fact that it’s simply sane, you get pretty much the entirety of C to play with so, if something is easier to write in C, do so, plus “templates, exceptions, namespaces, constructors/destructors (and therefore RAII), virtual function polymorphism, references, operator/function overloading, reusable standard generic containers, explicitly named casts” and, best of all, Boost.

If you’re still not convinced, the closing evidence should be that it took me seven attempts to get the C one not to segfault on run, and the C++ one worked first time. :)

4 Comments »

February 14th 2007

Music in pieces

I was involved in a discussion a few days ago about my favourite track featuring a guitar.. and I realised that I really don’t listen to anything with guitars in. All of the music I listen to tends to lack guitars, and, in fact, stringed instruments of any kind (I’m including the piano here).

Further than that, it tends to lack instruments that I can’t distinguish between whilst it’s playing. To pick an extreme (aha) example, trackStraight Ahead (Hardcore remix) ( sample: as .ogg ), despite sounding awfully chaotic, contains “clearly” distinguishable instruments (I count seven), each of which are on their own “channel”.

When I say “clearly”, I mean that you can work it out, not that it’s easy to do so. It takes me a depressingly long time. I’m using the MOD definition of “channels”, ie. if you have a set of audio samples (snippets), you can only have one playing on any given channel at a time.

This raises a couple of interesting (at least, for me) questions:

  • Can you teach a computer to take it back to samples and a playing order? Assuming this is insanely hard to do, can you do it for a restricted set/layout/etc. of songs, and/or with human interaction?
  • Would the sampled version offer better quality/compression? This depends on loads of things, like track length, repetitiveness, how well you can store the samples themselves (lots of little dissimilar files tend to be harder to compress than a long one), etc.
  • Assuming it does, and the artists are in on it (ie. you don’t have to do the conversion), would this help with music distribution? How small can you get a 70min CD?
  • Can people with “different” hearing to me distinguish between guitars/other string instruments in anything but the simplest of songs?
  • If so, does people’s varying ability to “focus” on the music change their enjoyment of it?
  • What would you do with partially discrete instruments like pianos, where more than one key can be held at once, producing a subtly different sound. 88 samples or one sample and fiddle the frequency? Fading off over time? Fall back to what’d have to be done with voice: try and seperate out “verses” of piano, and have them as a sample? trackPiano Track would be particularily susceptible to that.
  • Could one design a game based on people’s ability to pick out instruments/number of channels? It’d have to be more fun than DDR and Guitar Hero. ;)
  • Do I really think that I can rate tracks simply on the number of channels they’d require to compose, ie. their compressability? ie., for ogg, Chris Lake – Changes track (generated by oggspot and sed).
  • ..and so on.

This unfocused ramble was sponsored by Lasse Gjertsen‘s Ameteur (two channels).

No Comments yet »