29 June 2007

OpenAL - Test #1

Well, it wasn't in my plans to to this this evening... This test wasn't planned at all :D But since I had headache this evening, I didn't feel the right mood for studying :P
So, I got disconnected from the IM client (all of them), took a tutorial and the reference of OpenAL and I tried to make a sound.

The reason is simple: in these days I'm getting into nerdcore music (notabily, 8 Bit Weapon :D So I absolutely wanted to create my own 8-bit sound (and, you know, once you get the sound you want, you did the most).

So, OpenAL was my way.

I'm not an audio expert, I really find sampling, frequencies and so on difficult to get (well, actually it isn't at all :D It's only that I found a bit difficult to build a PCM sine wave from nothing. Then I found out that my problem is only that "buffer frequency" was the "sampling frequency", not the "frequency of my signal" (obviusly)).

So, this is my test. Quite short for 2 hours of works! (or more). Well, it was my first time :D Now I got it, so next works should be more easy.

#if 0
#!/bin/sh

FILE=`basename $0 | sed "s/\.[Cc].*$//"`
EXT=` basename $0 | sed "s/^.*\.\([Cc].*\)$/\1/"`

CC="gcc -g -Wall -Wextra -pedantic -std=c99"

$CC $FILE.$EXT -o $FILE -lm -lopenal -lalut

exit
#endif

#include
#include

#include

#define D2R 0.0174532925

#include
#include

#include

int main(int argc, char **argv)
{
// Initialize a context
alutInit(&argc, argv);
// Clean error flags
alGetError();

// Allocate buffers
ALuint buffer[1];

// Create the buffers
alGenBuffers(1, buffer);
if (alGetError() != AL_NO_ERROR)
return -1;

// Build the data
ALenum format = AL_FORMAT_MONO8;
ALsizei size;
ALsizei freq;
ALboolean loop;
ALvoid *data;

char file[512];
printf("Please insert a path for the file to play (space for none), enter to confirm\n");
fgets(file, 512, stdin);
if (file[0] < ' ') // The first char is not a string valid char (i.e. empty string)
// Load from extern file
alutLoadWAVFile(file, &format, &data, &size, &freq, &loop);
else {
printf("Generating sine wave on user parameters\n");
// Generate using math
// We want a note of 440 Hz. 32 samples for each oscillation
// for 1 seconds, means 440*32 bytes
unsigned char *sineWave;
int samples,
frequency;
printf("Which frequency? ");
scanf("%d", &frequency);
printf("How many samples for the wave? [try me between 2 and 16] ");
scanf("%d", &samples);
freq = samples * frequency;
printf("We will use a sampling frequency equal to the signal frequency:\n"
"sgnFreq * sgnSampl = %d * %d = %d\n", frequency, samples, freq);
size = freq; // We don't need an higher frequency than the signal
if (!(sineWave = malloc(size)))
return -2;

for (int i = 0; i < size; ++i) {
float x = i * 360.0 / (float)samples;
sineWave[i] = sin(x * D2R) * 128 + 128; // Clamp to [0,255]
// printf("Sinewave[%d] = %d\n", i, sineWave[i]);
}
data = sineWave;
}

printf("Values: fmt: %d siz %d freq %d\n", format, size, freq);
alBufferData(buffer[0], format, data, size, freq);

// Setup sources
ALuint source[1];
alGenSources(1, source);
if (alGetError() != AL_NO_ERROR)
return -3;

float srcPos[] = {3.0, 0.0, -3.0};

alSourcei(source[0], AL_BUFFER, buffer[0]);
alSourcefv(source[0], AL_POSITION, srcPos);

float lstPos[] = {0.0, 0.0, 0.0};
alListenerfv(AL_POSITION, lstPos);

alSourcePlay(source[0]);

// Wait until termination of the sound
sleep(2);

// Clear the things
alDeleteSources(1, source);
alDeleteBuffers(1, buffer);
alutExit();

return EXIT_SUCCESS;
}

The scope of this isn't really the use of openal (which is really simple), but the construction of a digital signal. In detail, you can actually understand how changing sampling frequency affect the riproduction of the signal.

Stay --sync

24 June 2007

I bei tempi andati

Io non so cosa facevate voi da piccoli, ma ogggi mi sono scandalizzato. Mi e' venuta in mente la parola dei bei tempi andati: ho pensato di guardare cosa ne pensa wikipedia a proposito. Sono rimasto shockato nel vedere che non esiste la pagina per nessuna delle due versioni che conoscevo:

http://it.wikipedia.org/wiki/Arimo
http://it.wikipedia.org/wiki/Arimus

Ma, se una parola cosi' fondamentale per la ricreazione dei bambini non c'e' su wikipedia, vuol dire che i bambini di oggi crescono con troppi videogiochi?

Mea culpa.

23 June 2007

I sogni son deeeeemenziali

Mh. Avete presente quando si inizia tutto per scherzo?
Quando poi ci si dice "bhe non e' mica male come idea"?
Quando poi inizi a fantasticare su quella cosa?
E che poi fantastichi in continuazione?
Poi quella fantasia diventa un'idea fissa.

No Ale, toglitela dalla testa. LEI no.


E' troppo bella.
E' troppo grande (in tutti i sensi, meno uno).
E' troppo disinteressata.
E' troppo per te.

C'e' un piccolo problema: ormai ce l'ho in testa. Dovro' sopprimere tutto questo enorme scherzo-gioco-interesse. In qualche modo magari ci riesco.

No, Ale, no.

Una situazione cosi' non ve la auguro proprio. Gia' persa, gia' sbagliata in partenza.

17 June 2007

STP - Short Term Proejcts for June07

I'm working on a stupid-but-nice demo for the EIGEM course at university. For now it's just a stupid animation done in OpenGL - it's good just for showing transformations (which one isn't a standard rigid body transformation, so i guess it'll be interesting). I'll add some textures, controls, shadows and - if i've time - a toon shader.

Of course I'm studying for the exam. I'm reading an e-book version of the 3D Computer Graphics a mathematical introduction, by Samuel R. Buss. The book is really nice, it's really a pity for the DRM: this was my first e-book, and DRM made it my worste experience with a book **ever**. Even chm-on-linux-when-chm-readers-weren't-around was a lot happier experience.
To begin, I can't read it on linux. I'm still using the online reader from eb20. Then i have troubles with Acrobat Reader on windows. In addition i can download it only 3 times (hey, how many times can you get a real book out from your shelf?? I guess far more than 3). Of course all the horrible limitations on printing, copying, taking it around...

I guess I'll never buy an ebook again, unless it'll be in clear, normal, non-DRM pdf or an OeB (Open eBook) or else.

Next project: social revolution. You'll see... I hope you'll see it.

Last but not least, I'm gonna learning how to use d-bus. It's too interesting and cross-platform/application to be snobbed :D

14 June 2007

Shock! Which kind of wrapper is this??

Well, everyone know that 'm not a java expert, but this evening i just
found something unbelivable, to me.Java has "wrapper" classes around primitive types (like Double, Integer, etc).
Well, so one may be happy doing something:
static void swapInt(Integer a, Integer b) {
int t = a.getValue();
a.setValue(b.getValue());
b.setValue(t);
}

Well, I just discovered that Integer doesn't have a method to set the value.
And of course the value field in the class is private.

So one should do:

class Int {
private int _v;
Int(int v) { _v = v; }
void setValue(int v) { _v = v; }
int getValue() { return _v; }
}

And use Int as i used Integer above.

Well, I REALLY hope to be wrong, and I really hope that Java wrap isn't that crap :D

Please, tell me I'm wrong (and please, argue your reply :P)

Stay --sync

09 June 2007

L'italietta democratica

Ecco, io alla politica non devo pensarci, che poi m'infervoro :D

Ma due parole su questo caso "Bush" dovevo spenderle.

Bush is a moron - lo scrivo in inglese perche' ne sono cosi' convinto
che voglio esportare questo mio pensiero al mondo. Bush non va
sostenuto, e' stato un incidente della storia. Ha fatto evidenti danni
tanto che la stessa america gli ha concesso la seconda possibilita'
"per riscattarsi" e ora (anzi, gia' da qualche mese direi) - stufa -
ha dimostrato che il repubblicano non si merita altro supporto.

Bene, preso atto di cio' mi chiedo: com'e' possibile che esiste
qualche essere (dis)umano che parla di democrazia in un paese da un
lato, mentre dall'altro sostiene che la protesta in piazza sia
disdicevole?

Noi siamo alleati dell'america (non di Bush), a maggior ragione
abbiamo diritto di parola: proprio perche' ne siamo coinvolti e'
giusto dimostrare al nostro e al loro governo come non appoggiamo la
campagnia di "esportazione della democrazia" intrapresa dal presidente
americano.

Bene, facciamolo. Cosa c'e' di meglio che una bella - pacifica -
protesta nei confronti di mr. Bush proprio quando viene nel nostro
paese?

Io dico: non e' certo una bella cosa che una persona riceva fischi di
protesta (non piace a nessuno), ma e' *esattamente* questo il senso
della democrazia. Siamo in un paese democratico, ergo e' giusto
manifestare.

E allora perche' il sig. Berlusconi si ostina a parlare di democrazia
e liberta', stravolgendone completamente il significato per il solo e
unico scopo di screditare gli avversari politici? Perche' la gente
ascolta qualcuno che non fa politica, ma fa uno stupido braccio di
ferro?

Perche' siamo in una democrazia bellissima, dove anche chi farfuglia
concetti stupidi e privi di senso viene ascoltato e - purtroppo -
anche votato dal popolo.

Come al solito, quel nano parla a vanvera... Ma cosa volete, se per
fare dei cori da "bar dello sport" c'e' anche chi lo vota...

... Il bello della democrazia :)

04 June 2007

So... Can we move on?

I say: it's 2007. Damn, it's TWO THOUSAND AND SEVEN! 2*10*10*10+7. Year MMVII.

The first car by Benz (exluding every experiment before him), was in the year 1885.

I think it's time to get rid of all this:

http://it.wikipedia.org/wiki/Eolo_(auto)
http://en.wikipedia.org/wiki/Eolo_Car
http://www.youtube.com/watch?v=cHmn1jGa9fA
http://www.ecplanet.com/canale/tecnologia-2/veicoli-78/0/0/7330/it/ecplanet.rxdf
http://en.wikipedia.org/wiki/Air_car
http://en.wikipedia.org/wiki/Air_engine
http://it.wikipedia.org/wiki/Motore_ad_aria_compressa
http://www.theaircar.com/

and the author, of course:
http://it.wikipedia.org/wiki/Cyril_Guy_N%C3%A8gre

After saying (err, reading) all this, this is my question:
can we move on, please?

03 June 2007

Upgrading blog

Yeee! I'm back :D (sometimes all the world seems to call me "aki here!" "no aki, there!" "no no, here please!" and so on, so i'm quite busy, sometimes).

Well, today's nerdy news is about... Papapapaaaa' PyS60! Ahaha yeeee! Finally I'm start using my smartphone Nokia 6630 as a smartphone (i.e. I just started to program on it). There is also Ruby for Series 60, but I don't know it, and python will be fine (for now).

It's a bit hard to program directly on the cellphone :P But this is only the beginning... I'll get used to this XD

- Oh, and it support OpenGL-ES so i absolutely have to try it! -

If you want to try it or start to program with python on your Nokia, take a look here:
http://opensource.nokia.com/projects/pythonfors60/

Well, what to say? I still have to study it! I just got some pdf doc (which can be read on the phone :P So i can enjoy it when i'm on travel)... We'll see :)

Stay tuned!

---
Btw , I was busy for 3 days with a briscola game :'D It's stupid, on shell (hence the name Shell-Briscola (shiscola)), buggy (but I don't remember which bugs there are to fix, so please test it for me :D), and support only 2 players for now (but, hey, it's made for easily switch to 3/4/5/6-players ;)

The cool (i.e. nerdy) thing, is that it uses extensively files I/O. stdout is used just for status messages, but each user has 2 files opened for I/O (well, this is also obvious, because in briscola game, cards are hidden to other players :).
"Embe?" (wf?) you may ask... Well, it's just powerful :) For example, I made a simple-raw-shell-script which creates the FIFOs, bind them to two netcat listener and then starts the game.
In that way, the players can play simply using a remote (or local) connection with netcat/telnet :D isn't that wonderful?? I find it wonderful.

And of course, if you like the backend, you can use it to create your own ncurses/qt/gtk/fltk/mind-controlled user interface :D So, 1 game, 1000 interfaces! And this is wonderful, because one can play with a console or a complex X11 window system!

So, study it, play it, debug it (or report bugs here), share it, modify it. It's Free Software. Please keep my name as the original developer. Then you can do anything you want (get paid for it, use in a commercial game, use in a GPL game, use to command a shuttle and so on).

Oh, I couldn't use it with just one RW file... I tried, but it didn't worked. I'm not an IPC expert, so I'm not sure if it's faseable to use just one file for bi-directional use (fifo are half-duplex, but oddly it didn't worked properly). If you have an exaple of using one FIFO for both reading and writing, please link it :)

S.T!