1 #include <libchimara/glk.h>
11 if(!glk_gestalt(gestalt_Sound2, 0)) {
12 fprintf(stderr, "Sound not supported.\n");
16 schanid_t sc[NUM_CHANNELS];
18 for(count = 0; count < NUM_CHANNELS; count++) {
19 sc[count] = glk_schannel_create(count);
21 fprintf(stderr, "Could not create sound channel number %d.\n", count);
26 /* Open the main window. */
27 winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
29 /* It's possible that the main window failed to open. There's
30 nothing we can do without it, so exit. */
33 glk_set_window(mainwin);
34 glk_put_string("Copy a sound file to the current directory and rename it "
35 "to SND3. Supported formats: AIFF, OGG, MOD, S3M, IT, XM. Type 'play' "
37 "If you want to test multi-sound playing, copy another sound file and "
38 "rename it to SND4 as well. You can't stop it, so make it a short "
49 glk_put_string("\nprompt> ");
50 glk_request_line_event(mainwin, buffer, 1024, 0);
52 printf("Received event:\n");
53 printf("Type: %d\n", ev.type);
56 printf( "%d\n", glk_window_get_rock(ev.win) );
59 printf("Var1: %d\n", ev.val1);
60 printf("Var2: %d\n", ev.val2);
62 case evtype_LineInput:
63 // Null-terminate string
67 if(strcmp(buffer, "quit") == 0) {
68 glk_put_string("That's all, folks.\n");
70 } else if(strcmp(buffer, "play") == 0) {
71 glk_put_string("Playing sound.\n");
72 if(!glk_schannel_play_ext(sc[0], 3, repeat, 1)) {
73 fprintf(stderr, "Could not start sound channel.\n");
76 } else if(strcmp(buffer, "stop") == 0) {
77 glk_put_string("Stopping sound.\n");
78 glk_schannel_stop(sc[0]);
79 } else if(strcmp(buffer, "repeat") == 0) {
80 glk_put_string("Setting repeat to ");
82 glk_put_string("TWICE.\n");
84 } else if(repeat == 2) {
85 glk_put_string("INFINITE.\n");
87 } else if(repeat == -1) {
88 glk_put_string("DON'T PLAY.\n");
90 } else if(repeat == 0) {
91 glk_put_string("ONCE.\n");
94 } else if(strcmp(buffer, "pause") == 0) {
95 glk_put_string("Pausing channel.\n");
96 glk_schannel_pause(sc[0]);
97 } else if(strcmp(buffer, "unpause") == 0) {
98 glk_put_string("Unpausing channel.\n");
99 glk_schannel_unpause(sc[0]);
100 } else if(strcmp(buffer, "ramp") == 0) {
101 glk_put_string("Ramping volume to ");
103 glk_put_string("HALF.\n");
104 glk_schannel_set_volume_ext(sc[0], 0x8000, 3000, 42);
106 } else if(ramp == 1) {
107 glk_put_string("FULL.\n");
108 glk_schannel_set_volume_ext(sc[0], 0x10000, 3000, 69);
111 } else if(strcmp(buffer, "multi") == 0) {
112 glk_put_string("Playing two sounds. (These will not repeat.)\n");
113 glui32 sounds[NUM_CHANNELS] = { 3, 4 };
114 if(glk_schannel_play_multi(sc, NUM_CHANNELS, sounds, NUM_CHANNELS, 1) < 2) {
115 fprintf(stderr, "Tried to start %d sounds, but not all were successful.", NUM_CHANNELS);
118 } else if(strcmp(buffer, "help") == 0) {
119 glk_put_string("Type PLAY or MULTI or REPEAT or PAUSE or UNPAUSE or RAMP or STOP or QUIT.\n");
122 case evtype_SoundNotify:
123 glk_cancel_line_event(mainwin, NULL);
124 glk_put_string("\nGot sound notify event!\n");
126 case evtype_VolumeNotify:
127 glk_cancel_line_event(mainwin, NULL);
128 glk_put_string("\nGot volume notify event!\n");
135 for(count = 0; count < NUM_CHANNELS; count++) {
136 glk_schannel_stop(sc[count]);
137 glk_schannel_destroy(sc[count]);