# Is it possible to subscribe to sub-beat callbacks?

**URL:** <https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403>\
**Category:** FMOD Engine\
**Tags:** unity\
**Created:** [October 14, 2022, 11:26pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403 "2022-10-14T23:26:05Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![akita\_engineer](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@akita\_engineer](https://qa.fmod.com/u/akita_engineer)\
**Post date:** [October 14, 2022, 11:26pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/1 "2022-10-14T23:26:05Z")

</div>

Hello,

We are working on an adaptive audio game project that relies on callbacks from an FMOD event, in particular FMOD\_STUDIO\_EVENT\_CALLBACK\_TIMELINE\_BEAT and FMOD\_STUDIO\_EVENT\_CALLBACK\_TIMELINE\_MARKER. All in all it works well for our purposes!

However, I’ve realized that while it’s possible to get callbacks for beats in the fashion of 21.1, 21.2, 21.3, etc., there is no evidence that we can subscribe to 21.1.1, 21.1.2, 21.1.3 and so forth. Essentially we may want to support certain game events triggering of eighth notes and sixteenth notes inside a measure.

What would be the best way to go about implementing something like that? Do we have to build something custom or is there a more elegant solution?

Any help is appreciated - big thanks!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [October 17, 2022, 5:34am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/2 "2022-10-17T05:34:03Z")

</div>

Hi,

Currently we don’t support getting callbacks on sub-beats, but I have suggested this feature to the dev team. In the mean time something custom might be your best choice.

---

<div class="post-metadata">

**Author:** ![akita\_engineer](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@akita\_engineer](https://qa.fmod.com/u/akita_engineer)\
**Post date:** [October 17, 2022, 4:30pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/3 "2022-10-17T16:30:36Z")

</div>

I see, thank you for the swift response.

Do you have any recommendations on how to go about this? My first thought is to keep track of the last time beat callback occurred in Unity and then check how much time has passed since that moment to see if we need to trigger anything else. FMOD is playing on a different thread though so it might be imprecise…

One of my teammates said we could potentially use different tempo markers to account for the sub-beats for a particular section of the song, which seems to be the only reasonable workaround.

What do you think?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [October 18, 2022, 11:49pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/4 "2022-10-18T23:49:05Z")

</div>

No worries!

Tempo markers are your best bet. I tested checking time against the last beat and you are right it is rather imprecise.

---

<div class="post-metadata">

**Author:** ![Kiru176](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kiru176](https://qa.fmod.com/u/Kiru176)\
**Post date:** [January 24, 2024, 4:55pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/5 "2024-01-24T16:55:20Z")

</div>

I am working on a similar project that would require certain actions being assigned to eighth and/or fourth notes. You mentioned using tempo-markers and I was wondering on how they could be used to achieve this as I find it hard to grasp.

Thanks.

Edit: After randomly playing with FMOD, I did manage to get a similar effect by multiplying bpm by 2 and making the 4/4 an 8/8. Don’t know if this is appropriate but I was wondering if this approach is similar to what you discussed?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [January 29, 2024, 1:48am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/6 "2024-01-29T01:48:42Z")

</div>

Hi,

If you are having an issue creating the callbacks we do have a scripting example here: [Unity Integration | Scripting Examples - Timeline Calbacks](https://fmod.com/docs/2.02/unity/examples-timeline-callbacks.html)

However, if your method is working could you elaborate on the issue you are experiencing?

---

<div class="post-metadata">

**Author:** ![Kiru176](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kiru176](https://qa.fmod.com/u/Kiru176)\
**Post date:** [January 29, 2024, 10:06am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/7 "2024-01-29T10:06:51Z")

</div>

Thanks for the response.  
I have a similar script to the one you linked and it works as expected. I tried altering the signature and managed to get the quarter notes, but I might need things like triplets to also be assigned to events, which seems hard to do.

```auto
        accurateTime = dspclock / 48800;
        halfTime = dspclock / 48800 * 0.5f;
        tripletTime = dspclock / 48800 * GetIntervalLength(_bpm, 0.3f);
        quarterTime = dspclock / 48800 * 0.25f;
      
        public float GetIntervalLength(float bpm, float noteLength)
        {
            return 60f / (bpm * noteLength);
        }

```

This is what I’m trying as of now, but for some reason it keeps being triggered with every frame in a condition like this.

```auto
        if (lastTripletTime != Mathf.FloorToInt(tripletTime))
        {
            lastTripletTime = Mathf.FloorToInt(tripletTime);
            //TripletEventUpdated();
            Debug.Log("Triplet");
        }

```

Any help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [January 31, 2024, 3:31am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/8 "2024-01-31T03:31:04Z")

</div>

Hi,

Would it be possible to get the full script DM’d to me to test on my side?

---

<div class="post-metadata">

**Author:** ![zanhulme](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/zanhulme/32/5069_2.png) [@zanhulme](https://qa.fmod.com/u/zanhulme)\
**Post date:** [January 31, 2024, 4:06am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/9 "2024-01-31T04:06:00Z")

</div>

I’m not sure if there is a limit to tempo or time signature when it comes to the API, but quickly experimenting in Studio I was able to take a 4/4 track and play it back with a time signature of 24/8 using triple the original tempo.

This gives me 24 beats to the bar, which should allow you to send whole-beat callbacks that align with crotchets, quavers, triplet crotchets, and triplet quavers in the original 4/4. If you wanted semiquavers or semiquaver triplets, it seems to allow me to set the time signature to 48/4 at 6 times the original tempo to achieve that.

---

<div class="post-metadata">

**Author:** ![Kiru176](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kiru176](https://qa.fmod.com/u/Kiru176)\
**Post date:** [January 31, 2024, 10:25am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/10 "2024-01-31T10:25:04Z")

</div>

This could work, however after seeing another post about how the beat tracking became less precise as the game progressed, I opted in for this approach using sample time and eventually thought I’d convert the normal FMOD beat tracking I’m using to that as well, but I can’t just ditch FMOD as I still need it for other audio stuff. But if I can’t get the subbeat callbacks o work this way I’ll give this approach a shot as well and see if it’s accurate enough.

Thank you for your responses.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [January 31, 2024, 11:39pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/11 "2024-01-31T23:39:59Z")

</div>

Hi,

Thank you for sharing your code. Having a look it may be that the `if()` statement may be backward.

```c
 if (lastTripletTime != Mathf.FloorToInt(tripletTime))
// Change to 
if (Mathf.FloorToInt(tripletTime) != lastTripletTime)

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Kiru176](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kiru176](https://qa.fmod.com/u/Kiru176)\
**Post date:** [February 1, 2024, 10:56am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/12 "2024-02-01T10:56:11Z")

</div>

Tried it, still i gets triggered nearly every frame. I think the condition might still be doing something however since not every frame triggers the Debug.Log.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 8, 2024, 2:14am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/13 "2024-02-08T02:14:44Z")

</div>

Apologies for the delayed response:

The code you shared with Connor is mostly sound - I suspect the main issue is the math being used to calculate the triplet timing.

For example, the code contains the following:

```auto
public void SampleTime(){
    //...
    tripletTime = dspclock / 48800 * GetIntervalLength(_bpm, 0.3f); 
    //...
}

public float GetIntervalLength(float bpm, float noteLength)
{
    return 60f / (bpm * noteLength);
}

```

The fundamental issue is that the order and type of operations in the code is incorrect - the calculation should be the following:

1. time elapsed = total samples / sample rate
2. beat length in seconds = 60 / BPM
3. triplet subdivision length in seconds = beat length in seconds \* 3
4. triplet subdivisions elapsed = time elapsed / triplet subdivision length in seconds

In code, this would be:

```auto
tripletTime = (dspclock / sampleRate) / (60f / _bpm) * 3f;

```

The sample rate needs to match the rate at which samples are being processed. You can get this for the FMOD System with [`System::getSoftwareFormat`](https://www.fmod.com/docs/2.02/api/core-api-system.html#system_getsoftwareformat) - by default this should be 48000khz, not 48800khz. Additionally, the `noteLength` for a triplet should be 0.333… recurring, not a flat 0.3.

---

<div class="post-metadata">

**Author:** ![Kiru176](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kiru176](https://qa.fmod.com/u/Kiru176)\
**Post date:** [February 8, 2024, 8:59pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/14 "2024-02-08T20:59:39Z")

</div>

Thank you so much for the respone, can you please provide the usage of System::getSoftwareFormat in a C# script, I’ve been looking but still have yet to figure it out.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 9, 2024, 2:14am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/15 "2024-02-09T02:14:01Z")

</div>

To return info, System::getSoftwareFormat uses the `out` keyword to pass variables by references. In C#, you can either create variables when calling the method:

```auto
RuntimeManager.CoreSystem.getSoftwareFormat(out int samplerate, out FMOD.SPEAKERMODE speakermode, out int numrawspeaker);

```

Or pass existing variables:

```auto
int samplerate, numrawspeaker;
FMOD.SPEAKERMODE speakermode;
RuntimeManager.CoreSystem.getSoftwareFormat(out samplerate, out speakermode, out numrawspeaker);

```

---

<div class="post-metadata">

**Author:** ![Batata\_Person](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@Batata\_Person](https://qa.fmod.com/u/Batata_Person)\
**Post date:** [October 13, 2024, 11:29am UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/16 "2024-10-13T11:29:01Z")

</div>

Hi! I’m having a similar issue with 8th and 16th notes - wouldn’t simply multiplying the tempo in the tempo marker by 4 give you access to 8th and 16th notes? Seems like it’s working for me 🙂

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [October 20, 2024, 11:27pm UTC](https://qa.fmod.com/t/is-it-possible-to-subscribe-to-sub-beat-callbacks/19403/17 "2024-10-20T23:27:36Z")

</div>

For the purposes of receiving timeline callbacks for sub-beats, that is definitely one way to go about it, especially if you don’t want to calculate the timings yourself in code.
