How do I sync a sound to a division of a musical beat?

0 favourites
  • 14 posts
From the Asset Store
146 high-quality musical sounds divided in different styles
  • I want to build a sample player and when you click a sound it "quantizes" the playback point to the next nearest division of the beat, so, if I've set the lengths of my sounds up correctly, they should all start correctly and stay in time with each other. Is there a good way of doing this with dt?

  • Has nothing to do with 'dt'. Just use a Timer and get the percentage of it's period to see if the click goes left or right.

    http://www.blackhornettechnologies.com/ ... eBeat.capx

  • So, if I click "play loop" in my game, how do I use that to wait until the next division to play the loop?

  • The timer is ticking at the beat. That's when you play each note.

  • Yeah but what I want is you click to play a loop, it waits until the timer arrives at a division (say 8th note) and then starts. Should I do it with something like a global, and when I click to play a loop it turns the global to 1 and if the global is 1 and the time is a precise division, turn global to 0 and play loop? What expression should I use to test if the timer is currently on a division of the timer? Also, this would have to be compatable with different tempos rather than just, say, 120bpm (which is easy cos it's division of a realtime minute)

  • Has nothing to do with 'dt'. Just use a Timer and get the percentage of it's period to see if the click goes left or right.

    http://www.blackhornettechnologies.com/ ... eBeat.capx

    blackhornet

    What bpm does the BeatFrequency correlate to?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The timer frequency = 60/bpm, so at a freq of 0.5s, which is in the code, 0.5 = 60/bpm, bmp = 60/0.5 = 120bpm. If you think it out, the frequency is a beat every 1/2 second, so that's 2 beats per second, times 60 seconds, which is 120 bpm.

    bpm are generally considered 1/4 notes, so for 1/8 notes, divide the timer freq by 2, so 120bpm would be a freq of 0.25.

    I had a few bugs in my sample, so I've cleaned those up and added a start button. The trick is just to start at beat -1, so that it leads into that first beat.

    http://www.blackhornettechnologies.com/ ... Beat2.capx

  • The timer frequency = 60/bpm, so at a freq of 0.5s, which is in the code, 0.5 = 60/bpm, bmp = 60/0.5 = 120bpm. If you think it out, the frequency is a beat every 1/2 second, so that's 2 beats per second, times 60 seconds, which is 120 bpm.

    bpm are generally considered 1/4 notes, so for 1/8 notes, divide the timer freq by 2, so 120bpm would be a freq of 0.25.

    I had a few bugs in my sample, so I've cleaned those up and added a start button. The trick is just to start at beat -1, so that it leads into that first beat.

    http://www.blackhornettechnologies.com/ ... Beat2.capx

    Okay, so with this, it places a marker on the visual beat, but I'm trying to wait until the moving blue box gets to a beat and THEN it plays the loop, is there a way of modifying this to get that to work easily?

  • The timer frequency = 60/bpm, so at a freq of 0.5s, which is in the code, 0.5 = 60/bpm, bmp = 60/0.5 = 120bpm. If you think it out, the frequency is a beat every 1/2 second, so that's 2 beats per second, times 60 seconds, which is 120 bpm.

    bpm are generally considered 1/4 notes, so for 1/8 notes, divide the timer freq by 2, so 120bpm would be a freq of 0.25.

    I had a few bugs in my sample, so I've cleaned those up and added a start button. The trick is just to start at beat -1, so that it leads into that first beat.

    http://www.blackhornettechnologies.com/ ... Beat2.capx

    blackhornet I've come up with a hack that works very well for what I required, do you mind if I send you, you can see what you think to it, maybe it might be of use to you?

  • You can PM me if you want. There should be no reason to 'hack' anything.

  • blackhornet Here's my example, it's buggy is the browser is a bit low on memory, probably because I'm using visual cues as references, and the fx buttons sometimes "short out" the samples: https://www.dropbox.com/s/3cdl7txdqhizm ... .capx?dl=0

    Any ideas how to improve this a bit? <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

  • It's hard to know where to start. You don't need clones of the same button, to start. Multiple instances of the same button would make things much simpler. You would use instance variables to store anything unique to that button, and use the same code to do all the same things, just with the various instance variables.

    Event 2 should be inside the "On start of layout" - it's creating 8 BeatSprites every tick!

    I see what you are trying to do now. You've got your work cut out for you. You are going to have to calculate the bpm of the samples you already have and try to sync them all together. That's going to take some work, and a good understanding of the math.

  • It's hard to know where to start. You don't need clones of the same button, to start. Multiple instances of the same button would make things much simpler. You would use instance variables to store anything unique to that button, and use the same code to do all the same things, just with the various instance variables.

    Event 2 should be inside the "On start of layout" - it's creating 8 BeatSprites every tick!

    I see what you are trying to do now. You've got your work cut out for you. You are going to have to calculate the bpm of the samples you already have and try to sync them all together. That's going to take some work, and a good understanding of the math.

    blackhornet

    Okay, I probably could used more efficient sprite reusage, but I have calculated the samples and they do sync most of the time (have you pressed start then clicked a sample button?) but the issue is they don't trigger accurately if the users browser isn't running at full speed. I'll fix that Sprite respawn issue! Could I tighten your triggering code to work more on the code side rather than relying on the visual cues?

  • You are reading the "0" out of the text object, so just look where the value is set and check for zero there instead. Call a function there and process whether or not to run the loop. The timer should deal with any dt discrepancies, but if you find it doesn't, you could look at tracking the "Audio->On ended" trigger of your main timing sample and use that as your sync point instead. You are going to have to experiment with how to sync everything together.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)