1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 audio_sound_set_track_position jumping to wrong position

Discussion in 'Programming' started by Michael Stearns, Mar 7, 2019.

  1. Michael Stearns

    Michael Stearns Member

    Joined:
    Jul 3, 2017
    Posts:
    17
    Hello :)

    I have created a system for making looping songs following the guide from Pixelated Pope and it works great! However, following the same guide, I created a little helper to make it easier to ensure everything sounded right, so the song would jump forward to shortly before the "loop point" and I could test easily without waiting through the whole song, and for some reason sometimes it jumps to the wrong point and triggers the looping code. It doesn't appear to be a serious problem (since normally the game won't be skipping around in the song like this) but I'm concerned it might cause a problem later on somehow.

    Here's the code:
    Code:
    //helper to jump to end of song before loop
    if (currentSong != noone && keyboard_check_pressed(ord('Q')))
        {
        newPoint = songLoopPoint - 5;
        audio_sound_set_track_position(currentSong, newPoint)
        }
    
    //loop song
    if (currentSong != noone && songLoopPoint != -1)
        {
        var songTime = audio_sound_get_track_position(currentSong);
        if (songTime >= songLoopPoint)
            {
            audio_sound_set_track_position(currentSong, songTime - songLoopLength);
            }
        }
    The really weird thing is that I set that "newPoint" variable so I could see what was going on (and display it in the draw step), and it consistently displays the expected value, and not one that's larger than songLoopPoint. No other calls to audio_sound_set_track_position are made.

    Thanks!
     
  2. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    418
    When you use the function audio_get_track_position(sound_id), the value that is returned is the value for the instant you call it. Wait a little while, and the value you got before will be different from the value you would get if you called the function again.

    I'm guessing that you're not updating songLoopPoint immediately before calling the code you posted? That might help.
     
  3. Michael Stearns

    Michael Stearns Member

    Joined:
    Jul 3, 2017
    Posts:
    17
    Yes, I understand what audio_get_track_position does. The problem is that the first bit of code (when I press Q) is supposed to set it to a number 5 seconds less than songLoopPoint, but when the second part comes up (they're in the same step event) instead of getting me the new time I believe I set it to, or even the time that it was before I set it, it is somehow a number that's greater than songLoopPoint.

    songLoopPoint is set elsewhere when the song starts playing, it's not meant to change until a new song begins (it's the sum of the intro length and the length of the part of the song that loops). The song jumps back to the end of the intro part of the song when audio_get_track_position(sound_id) exceeds it.
     
  4. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    418
    Is songLoopPoint set when you load a song into currentSong?

    I wonder if maybe you can wind up with a value of songLoopPoint that is less than 5, and maybe the negative input value is throwing the track position off?

    If not, then I speculate that the error is somewhere else in your code that's not shown in the OP.
     
  5. Michael Stearns

    Michael Stearns Member

    Joined:
    Jul 3, 2017
    Posts:
    17
    Yep, that's when I do it. And none of the songs are less than 5 seconds, so no worries there.

    Any idea what else besides audio_set_track_position could affect the song position? The only sections of my program that deal with music are the ones here and the function that sets currentSong and the related values.
     
  6. YoSniper

    YoSniper Member

    Joined:
    Jun 24, 2016
    Posts:
    418
    Are you verifying that when you press Q that the track is set to AFTER the songLoopPoint value?

    Like, if you put this in an object's Draw Event, can you see the track value not being set to what it is supposed to be?
    Code:
    var TXT, track_pos;
    track_pos = audio_get_track_position(currentSong);
    TXT = "Loop Point: " + string(songLoopPoint) + "#Track Pos: " + string(track_pos);
    draw_set_halign(fa_left);
    draw_set_valign(fa_top);
    draw_text(view_xview + 4, view_yview + 4, TXT);
    Honestly, I'm grasping at straws here.
     
  7. Michael Stearns

    Michael Stearns Member

    Joined:
    Jul 3, 2017
    Posts:
    17
    Straw grasps are appreciated! :) And yep, I had some text displaying like that. But good news, I think I got to the problem.

    Maybe.

    I switched the song's compression attribute from "Compressed - Streamed" to "Uncompressed - Not Streamed." This was at the recommendation in the text below the video I linked, which apparently reduces popping in the loop (I was getting a little of that). Switching back makes it easy to recreate this behavior, but while using uncompressed, I can't get it to happen.

    Another weird thing I didn't mention is that text display produced some odd results. Besides my own variables, I was also showing audio_get_track_position(), and sometimes it would appear to stutter when the second position changed, flickering between the current value and the previous (ie 15 and 14 seconds). Since changing the attribute, those values are displaying steadily, like you'd expect, rather than stuttering, and I can't reproduce my bug. I experimented a little more:

    Compressed - Streamed: Yes bugs
    Compressed (Uncompress on Load) - Not Streamed: No bugs
    Compressed - Not streamed: Yes bugs
    Uncompressed - Not Streamed: No bugs

    So I guess the issue is something to do with the compression? (Since "uncompress on load" is basically the same as Uncompressed.) Could be the game is incredibly inefficient in some other area, or maybe my computer just sucks (definitely not ruling out the latter, ha ha).
     

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