This example demonstrates how to pronounce "Linux" correctly! Since it is
not sure that everyone will be able to make out the words, here they are:
"Hello, this is Linus Torvalds. I'd like to pronounce `Linux': that's Linux!"
I took this file from http://www.ssc.com/lj/images/english.au .

Unlike the same test from the oofficial RTL release it uses a task and not an
interrupt handler to do the job.
A periodic real time task runs at 8 kKhz and at each schedule it tries to get a
sample from the RT-FIFO number 0. If successful, it transforms the sample from
8bit ulaw encoding to 1-bit sample and turns the speaker on or off accordingly.
This takes advantage of the fact that .au files are typically sampled at 8kHz.

The sound quality is pretty low. 1-bit sampling is clearly not enough.

To run the example type `make; insmod rt_process.o; cat linux.au >/dev/rtf0'.



#define MODULE
#include <linux/module.h>
#include <asm/rt_irq.h>
#include <linux/mc146818rtc.h>

#include <rtl_fifo.h>
#include <rtl_sched.h>

#define ONESHOT

#define TICK_PERIOD 125000

#define STACK_SIZE 4000

RT_TASK task;

static int filter(int x)
{
	static int oldx;
	int ret;

	if (x & 0x80) {
		x = 382 - x;
	}
	ret = x > oldx;
	oldx = x;
	return ret;
	
}


void intr_handler(int t) {
	char data;
	char temp;
	while(1) {
		if (rtf_get(0, &data, 1) > 0) {
			data = filter(data);
			temp = inb(0x61);            
			temp &= 0xfd;
			temp |= (data & 1) << 1;
			outb(temp,0x61);
		}
		rt_task_wait_period();
	}
}


int init_module(void)
{
	RTIME now, tick_period;
	rtf_create(0, 4000);
	rt_task_init(&task, intr_handler, 0, STACK_SIZE, 0, 0, 0);
#ifdef ONESHOT
	rt_set_oneshot_mode();
#endif
	tick_period = start_rt_timer(nano2count(TICK_PERIOD));
	now = rt_get_time() + tick_period;
	rt_task_make_periodic(&task, now, tick_period);
	return 0;
}


void cleanup_module(void)
{
	stop_rt_timer();
	rtf_destroy(0);
	rt_task_delete(&task);
}