Multiple Sounds

version 3 by Massimo Stella

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - IF6 Code

    Include (-

    Global gg_thirdchan = 0;
    Constant GG_THIRDCHAN_ROCK 412;

    Global gg_fourthchan = 0;
    Constant GG_FOURTHCHAN_ROCK 413;

    Global gg_fifthchan = 0;
    Constant GG_FIFTHCHAN_ROCK 414;

    Global gg_sixthchan = 0;
    Constant GG_SIXTHCHAN_ROCK 415;

    -) before "Glulx.i6t".

    [Add globals for any more channels you want in the above Include section.]

    Include (-

    [ SoundReproduce sound chan loop;
    if (glk_gestalt(gestalt_Sound,0) && glk_gestalt(gestalt_SoundMusic,0)) {
        glk_schannel_play_ext(chan,sound,loop,0);
        }
    else {
        "Your interpreter doesn't support sound reproduction.";
        }
    ];

    [ VolumeControl chan val;
    if (glk_gestalt(gestalt_SoundVolume,0)) {
        if ((val <= 5) && (val > 0)) {
            glk_schannel_set_volume(chan, val * 13107+1);
            }
        else if (val == 0) {
            glk_schannel_set_volume(chan, val);
        }
        else {
            "Invalid Volume Level: please insert a value between 0 and 5.";
            }
        }
    else {
        "Your interpreter doesn't support volume control.";
        }
    ];

    [ VolumeRaw chan val;
    if (glk_gestalt(gestalt_SoundVolume,0)) {
        if ((val <= 65536) && (val >=0)) {
            glk_schannel_set_volume(chan, val);
            }
        else {
            "Invalid Volume Level: please insert a value between 0 and 65536.";
            }
        }
    else {
        "Your interpreter doesn't support volume control.";
        }
    ];

    [ SoundStop chan;
    if (glk_gestalt(gestalt_Sound,0) && glk_gestalt(gestalt_SoundMusic,0)) {
        glk_schannel_stop(chan);
        }
    else {
        "Your interpreter doesn't support sound stopping.";
        }
    ];

    [ ThirdCreate;
        if (glk_gestalt(gestalt_Sound, 0)) {
            if (gg_thirdchan == 0)
                gg_thirdchan = glk_schannel_create(GG_THIRDCHAN_ROCK);
        }
    ];

    [ FourthCreate;
        if (glk_gestalt(gestalt_Sound, 0)) {
            if (gg_fourthchan == 0)
                gg_fourthchan = glk_schannel_create(GG_FOURTHCHAN_ROCK);
        }
    ];

    [ FifthCreate;
        if (glk_gestalt(gestalt_Sound, 0)) {
            if (gg_fifthchan == 0)
                gg_fifthchan = glk_schannel_create(GG_FIFTHCHAN_ROCK);
        }
    ];

    [ SixthCreate;
        if (glk_gestalt(gestalt_Sound, 0)) {
            if (gg_sixthchan == 0)
                gg_sixthchan = glk_schannel_create(GG_SIXTHCHAN_ROCK);
        }
    ]; -).

    [Add your own 'Create' calls for any new channels you want to add to your game here.]

    [Wade: I added the VolumeRaw call to allow the programmer to directly set the 0-65536 volume from their I7 code. This is needed for programming your own fades.]