1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 audio_play_in_sync_group() doesn't return unique ID

Discussion in 'Programming' started by pieterator, Sep 7, 2017.

  1. pieterator

    pieterator Member

    Joined:
    Jun 20, 2016
    Posts:
    49
    I'm currently using audio sync groups for multi intensity music in my game. The idea is to have 3 pieces of music play in the sync group, and then cross fade between them as the intensity of the game increases.

    From the GameMaker Studio 2 help file on audio_play_in_sync_group():
    The example code provided in the help file:
    Code:
    sg = audio_create_sync_group(true);
    snd[0] = audio_play_in_sync_group(sg, sound1);
    snd[1] = audio_play_in_sync_group(sg, sound2);
    snd[2] = audio_play_in_sync_group(sg, sound3);
    snd[3] = audio_play_in_sync_group(sg, sound4);
    audio_sound_gain(snd[1], 0, 0);
    audio_sound_gain(snd[2], 0, 0);
    audio_sound_gain(snd[3], 0, 0);
    audio_start_sync_group(sg);
    Now as I understand GML, using audio_sound_gain(snd[1], 0, 0) would only change the gain of the instance of sound2 created with audio_play_in_sync_group(sg, sound2). However if you used audio_sound_gain(sound2,0,0) you would change the gain of ALL audio instances that were created from sound2.

    However, if you look at the values returned from the above code you get:
    Code:
    snd[0] = 0
    snd[1] = 1
    snd[2] = 2
    snd[3] = 3
    You get 0,1,2 & 3 regardless of what order you put in sound1,2,3 & 4. Also it doesn't matter if you have a project filled with audio files, the output is always 0,1,2 & 3 which are just the first 4 audio files you loaded into the IDE.

    I have reported this as a bug to the helpdesk, but was told that this was apparently not a fault or a bug, which I'm finding hard to accept. I was told that audio_play_in_sync_group() merely returns the order that the sounds were added to the audio sync group, which is a trivial thing to return and not useful at all.

    I mention this because audio_play_sound() does return a unique ID for the instance of the sound being played, whose gain you can then be adjusted without adjusting the gain of all other instance created from that sound index.

    Example project illustrating the problem I'm having:
    http://www.mediafire.com/file/78x0l0dgaect68g/Test_Audio_Groups.yyz

    Any advice or guidance is very much appreciated.
     
  2. pieterator

    pieterator Member

    Joined:
    Jun 20, 2016
    Posts:
    49
    So in short, audio_play_in_sync_group() not returning a unique ID makes it impossible to adjust the gain of sounds in an audio group
    without adjusting the gain of all other sounds played using the same sound index.
     
  3. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,318
    I just tested your project, and its just as you said, audio_play_in_sync_group() is returning 0, 1, 2, 3 etc...as each sound is added.

    This is similar behaviour to how data structures behave, but in the case of data structures, each type of ds is mapped independently to those indexes.

    So can confirm it is then not possible to use that id returned (0,1,2, 3...etc) because when you use those indexes in normal audio_sound_gain() they get treated as object_indexes, as per the resource tree, and not unique instance indexes for the sounds added.

    So either the documentation is incorrect, because it says it does return a unique index for that instance of the sound, or there is a bug / not useful behaviour in the return value from the audio_play_in_sync_group().

    I would persist with the helpdesk route for now, or perhaps @Nocturne can can take a look at the docs to see if that is the correct workings of the function.
     
    pieterator likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice