# How to set playback speed given a tempo scalar?

**URL:** https://qa.fmod.com/t/how-to-set-playback-speed-given-a-tempo-scalar/20825
**Category:** FMOD Engine
**Tags:** cpp
**Created:** [October 31, 2023, 9:59pm UTC](https://qa.fmod.com/t/how-to-set-playback-speed-given-a-tempo-scalar/20825 "2023-10-31T21:59:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![PooCluster](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@PooCluster](https://qa.fmod.com/u/PooCluster)
#### Post date: [October 31, 2023, 9:59pm UTC](https://qa.fmod.com/t/how-to-set-playback-speed-given-a-tempo-scalar/20825/1 "2023-10-31T21:59:49Z")

</div>

Hello! For context, I’m using FMOD Core API in my C++ project.

Let’s say I have a .wav file recorded at 60 BPM and depending on the game state, I want the .wav file to play at 75 BPM (1.25x faster) (pitch unaffected). I see a couple of options on how to set the playback speed:

1. Channel::setFrequency(float frequency)
2. ChannelControl::setPitch(float pitch) (speeds up playback and pitch) + FMOD\_DSP\_PITCHSHIFT (to pitch the playback back to original)

However, I’m a little confused how the speed scalar I derive (1.25) can map to any of the FMOD parameters. As in, what is the frequency/pitch value when a .wav file is played 1.25x? And of the 2 options listed, which is more performant based on my use case? Any pointers?

---

<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 31, 2023, 11:49pm UTC](https://qa.fmod.com/t/how-to-set-playback-speed-given-a-tempo-scalar/20825/2 "2023-10-31T23:49:15Z")

</div>

Hi,

FMOD has no simple solution for pitch-invariant time stretching, or time-invariant pitch shifting - changing the pitch is the same as playing the playback rate/frequency, and vice versa. As such, `Channel::setFrequency` and `ChannelControl::setPitch` both essentially do the same thing. The only major difference is that `ChannelControl::setPitch` is a higher level control, and when used on a channelgroup will affect all child channels and channelgroups. The only way to work around this is to do as you’ve noted in option 2, and combine a change in frequency with the use of a pitch shift DSP that shifts the pitch inversely proportionate to the change in frequency.

As for mapping your scalar:

- The `pitch` float should be a 1:1 mapping.

- The `frequency` float is proportionate to the default frequency of the sound being played on a given channel. You can get the sound playing on a channel with [`Channel::getCurrentSound`](https://www.fmod.com/docs/2.02/api/core-api-channel.html#channel_getcurrentsound), and then get the default playback frequency of the sound with [`Sound::getDefaults`](https://www.fmod.com/docs/2.02/api/core-api-sound.html#sound_getdefaults). For example, 1.25x the playback frequency of a 48Khz sound would be 60Khz.
