Microtone

Combining this and this to create tiny music programs.

How tiny you ask? 128 bytes.
The sound generation itself takes up just 14 lines of assembly, generating 31 bytes of machine code.
The rest is taken up the ELF header and functions needed to open the sound device and outputting samples.

In case you wonder how the sound was generated, here is the relevant part of the source:

	mov		ebx, eax
	shr		ebx, 14
	and		bl, 0x03
	inc		ebx

	mov		ecx, eax
	shr		ecx, 11
	and		cl, 0x07
	shl		ecx, 1
	
	sub		ebx, ecx
	
	mov		ecx, eax
	shl		ecx, 1
	
	mul		ebx
	shr		eax, 1
	or		eax, ecx

EAX is a timer counting up at 8000hz, and at the end the lower byte of EAX is written to the audio device.


Demo

In case you don't have a computer that runs Linux or OSS you can listen to the "music" here:


Download: microtone.ogg


Download

Needs OSS (/dev/dsp) to run.

Download: microtone.tar.gz


Index