Implemented sound playing with test sound
[projects/chimara/chimara.git] / tests / soundtest.c
1 #include <libchimara/glk.h>
2 #include <stdio.h>
3 #include <unistd.h>
4
5 void
6 glk_main(void)
7 {
8         if(!glk_gestalt(gestalt_Sound, 0)) {
9                 fprintf(stderr, "Sound not supported.\n");
10                 return;
11         }
12         if(!glk_gestalt(gestalt_SoundVolume, 0)) {
13                 fprintf(stderr, "Sound volume not supported.\n");
14                 return;
15         }
16         
17         schanid_t sc = glk_schannel_create(0);
18         if(!sc) {
19                 fprintf(stderr, "Could not create sound channel.\n");
20                 return;
21         }
22
23         if(!glk_schannel_play(sc, 0)) { /* resource number doesn't matter right now */
24                 fprintf(stderr, "Could not start sound channel.\n");
25                 return;
26         }
27         
28         glk_schannel_set_volume(sc, 0x10000);
29         sleep(1);
30         glk_schannel_set_volume(sc, 0x08000);
31         sleep(1);
32         glk_schannel_set_volume(sc, 0x04000);
33         sleep(1);
34         glk_schannel_set_volume(sc, 0x00000);
35         glk_schannel_set_volume(sc, 0xA0000); /* max supported volume */
36         glk_schannel_set_volume(sc, 0xB0000); /* should be coerced */
37         glk_schannel_set_volume(sc, 0x10000);
38
39         glk_schannel_stop(sc);
40         glk_schannel_destroy(sc);
41 }