initial
[fpgammix.git] / workloads / audio / test-audio.c
blobb0e01ed68baf830c84dec61dccf1a9d40704b4a2
1 #include "stdio.h"
3 #define RATE 11250
4 #include "newgame-sound.c"
6 unsigned char *next_sample;
7 unsigned char *stop_sound;
9 extern void interruptvector(void);
11 long time_at_last_run = 0;
12 long delta = 0;
15 void
16 interrupthandler(long unsigned interrupt_source)
18 setInterval(FREQUENCY / 11250 - 100);
20 long time = now();
22 if (next_sample != stop_sound) {
23 DAC_both = *next_sample++ << 6;
26 delta = time - time_at_last_run;
27 time_at_last_run = time;
30 int
31 main()
33 fb_clear();
35 mmix_fprintf(1, "Hello?", 0);
37 next_sample = stop_sound = blob + sizeof blob;
40 * XXX 8 and even 7 distorts the sound. Why? AAhh, it's only
41 * when on head phones. Amplified it sounds great
43 unsigned scale = 6;
44 unsigned sw;
46 for (;;) {
47 unsigned char *p;
48 long unsigned my_sample, time_for_next;
50 mmix_printf("Starting sound. Scale is %d\n", scale);
52 time_for_next = now() + (FREQUENCY / RATE);
53 for (p = blob; p != blob + sizeof blob; ++p) {
54 MMIX_IOSPACE[11] = (long) p >> 8;
55 my_sample = *p;
56 my_sample = my_sample << scale;
57 time_for_next += (FREQUENCY / RATE);
58 while (now() < time_for_next)
60 DAC_both = my_sample;
63 while ((sw = get_switches()) == 0);
64 if (sw & (SW2|SW3))
65 scale += (sw & SW3) ? 1 : -1;
66 else if (sw & SW1)
67 stdout = !stdout;
68 else if (sw & SW0)
69 break;
72 mmix_printf("Trying interrupts!\n", 0);
74 setInterruptVector(interruptvector);
75 setIntrMask(1 << 7); // Enable interval
77 for (;;) {
78 mmix_printf("Starting sound\n", 0);
79 next_sample = blob;
81 setInterval(FREQUENCY / RATE);
83 while ((get_switches() & SW3) == 0)
84 mmix_printf("delta %d\n", delta);
85 while ((get_switches() & SW3) != 0);