1 #include <libchimara/glk.h>
11 if(!glk_gestalt(gestalt_Sound, 0)) {
12 fprintf(stderr, "Sound not supported.\n");
15 if(!glk_gestalt(gestalt_SoundVolume, 0)) {
16 fprintf(stderr, "Sound volume not supported.\n");
19 if(!glk_gestalt(gestalt_SoundNotify, 0)) {
20 fprintf(stderr, "Sound notification not supported.\n");
24 schanid_t sc[NUM_CHANNELS];
26 for(count = 0; count < NUM_CHANNELS; count++) {
27 sc[count] = glk_schannel_create(count);
29 fprintf(stderr, "Could not create sound channel number %d.\n", count);
34 /* Open the main window. */
35 winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
37 /* It's possible that the main window failed to open. There's
38 nothing we can do without it, so exit. */
41 glk_set_window(mainwin);
42 glk_put_string("Copy a sound file to the current directory and rename it "
43 "to SND3. Supported formats: AIFF, OGG, MOD, S3M, IT, XM. Type 'play' "
45 "If you want to test multi-sound playing, copy another sound file and "
46 "rename it to SND4 as well. You can't stop it, so make it a short "
57 glk_put_string("\nprompt> ");
58 glk_request_line_event(mainwin, buffer, 1024, 0);
60 printf("Received event:\n");
61 printf("Type: %d\n", ev.type);
64 printf( "%d\n", glk_window_get_rock(ev.win) );
67 printf("Var1: %d\n", ev.val1);
68 printf("Var2: %d\n", ev.val2);
70 case evtype_LineInput:
71 // Null-terminate string
75 if(strcmp(buffer, "quit") == 0) {
76 glk_put_string("That's all, folks.\n");
78 } else if(strcmp(buffer, "play") == 0) {
79 glk_put_string("Playing sound.\n");
80 if(!glk_schannel_play_ext(sc[0], 3, repeat, 1)) {
81 fprintf(stderr, "Could not start sound channel.\n");
84 } else if(strcmp(buffer, "stop") == 0) {
85 glk_put_string("Stopping sound.\n");
86 glk_schannel_stop(sc[0]);
87 } else if(strcmp(buffer, "repeat") == 0) {
88 glk_put_string("Setting repeat to ");
90 glk_put_string("TWICE.\n");
92 } else if(repeat == 2) {
93 glk_put_string("INFINITE.\n");
95 } else if(repeat == -1) {
96 glk_put_string("DON'T PLAY.\n");
98 } else if(repeat == 0) {
99 glk_put_string("ONCE.\n");
102 } else if(strcmp(buffer, "pause") == 0) {
103 glk_put_string("Pausing channel.\n");
104 glk_schannel_pause(sc[0]);
105 } else if(strcmp(buffer, "unpause") == 0) {
106 glk_put_string("Unpausing channel.\n");
107 glk_schannel_unpause(sc[0]);
108 } else if(strcmp(buffer, "ramp") == 0) {
109 glk_put_string("Ramping volume to ");
111 glk_put_string("HALF.\n");
112 glk_schannel_set_volume_ext(sc[0], 0x8000, 1000, 42);
114 } else if(ramp == 1) {
115 glk_put_string("FULL.\n");
116 glk_schannel_set_volume_ext(sc[0], 0x10000, 1000, 69);
119 } else if(strcmp(buffer, "multi") == 0) {
120 glk_put_string("Playing two sounds. (These will not repeat.)\n");
121 glui32 sounds[NUM_CHANNELS] = { 3, 4 };
122 if(glk_schannel_play_multi(sc, NUM_CHANNELS, sounds, NUM_CHANNELS, 1) < 2) {
123 fprintf(stderr, "Tried to start %d sounds, but not all were successful.", NUM_CHANNELS);
126 } else if(strcmp(buffer, "help") == 0) {
127 glk_put_string("Type PLAY or MULTI or REPEAT or PAUSE or UNPAUSE or RAMP or STOP or QUIT.\n");
130 case evtype_SoundNotify:
131 glk_cancel_line_event(mainwin, NULL);
132 glk_put_string("\nGot sound notify event!\n");
134 case evtype_VolumeNotify:
135 glk_cancel_line_event(mainwin, NULL);
136 glk_put_string("\nGot volume notify event!\n");
143 for(count = 0; count < NUM_CHANNELS; count++) {
144 glk_schannel_stop(sc[count]);
145 glk_schannel_destroy(sc[count]);