Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Getting tight timing on music using settimer()

    Beginners
    4
    10
    529
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PickleCatStars
      PickleCatStars F last edited by

      I’ve been having a faff making music recently. Started off checking/doing stuff per frame, in the loop. As we all know though, if you start doing too much and your framerate drops, your music slows down too, and it sounds like butt.

      So moved to a time() based system. Even if your framerate slows, time keeps on ticking at the same rate, so things might get a little screwy sometimes, but at least it won’t sloooow doooownnn...

      It still sounds a little off though, and starts missing beats at high tempos, and I think it’s still to do with framerate, update() and the loop. 1 frame’s worth of time slop might explain it, so I thought I’d put all my audio decision making and note playing into a function to be called with settimer(), then it’d be totally disconnected from whatever 60fps is, and would hopefully sound rock-solid and never skip a beat.

      What do y’all think?

      spikey 1 Reply Last reply Reply Quote 1
      • spikey
        spikey F @PickleCatStars last edited by

        @toxibunny After I tried several things to get samples played at the right moment, I came to the conclusion that the settimer function is nice in theory but I got the best results using pure time() function and taking the diff to the last note/sample event.

        1 Reply Last reply Reply Quote 0
        • vinicity
          vinicity F last edited by

          Yeah, I prefer using time() as well. As an added precaution I call my music function twice in each update loop. The music function starts by checking the difference between current time() and last time a note was played. If the difference is less than the constant, nothing happens, so it shouldn’t affect performance.

          1 Reply Last reply Reply Quote 1
          • PickleCatStars
            PickleCatStars F last edited by

            It seems like you’re both doing the same thing, but I don’t understand it.

            I think mine basically checks to see if time() is within a certain small amount past the start of a regular period, and makes sure it only happens once per period.

            What exactly are you doing?

            1 Reply Last reply Reply Quote 0
            • PickleCatStars
              PickleCatStars F last edited by PickleCatStars

              Actually, I’ve described mine totally wrong. I’m actually multiplying time() up, int()ing it, and then later on, seeing if the modulo of something == 0. That’s how it loops around. I wonder if it would help to use floor() or ceil() instead of int()..

              1 Reply Last reply Reply Quote 0
              • vinicity
                vinicity F last edited by

                It’s basically the same as yours, but I have a “music counter” which I increase with one if a certain amount of time has passed. Then I do modulo on the counter to trigger the sounds.

                1 Reply Last reply Reply Quote 0
                • PickleCatStars
                  PickleCatStars F last edited by

                  Well I’ve been having another listen, and actually it’s okay as it is. My program is crashing fuze though. No sign of a memory leak. Could it be the settimer()?

                  Willpowered 1 Reply Last reply Reply Quote 0
                  • PickleCatStars
                    PickleCatStars F last edited by PickleCatStars

                    Removing the custom timer seems to have fixed the crash. Edit: putting the timer back in works fine too, so now I don’t know why it was crashing, I only know that it doesn’t do it now. Cosmic rays? Poltergeist activity? I don’t know..

                    1 Reply Last reply Reply Quote 1
                    • Willpowered
                      Willpowered Fuze Team @PickleCatStars last edited by

                      @toxibunny If possible, could you share some code to reproduce this crash? I'd like to investigate it.

                      PickleCatStars 1 Reply Last reply Reply Quote 0
                      • PickleCatStars
                        PickleCatStars F @Willpowered last edited by

                        @Willpowered I have tried to reproduce the crash, but haven’t managed. Even undoing my fixes doesn’t seem to do it. Sorry!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post