Is there a way to play an Fmod Event backwards, ie. reverse the audio playback?
In Unity it is possible to do this on an AudioSource by setting the AudioSource’s pitch to -1f, see this code:
// Reverses playback of the audiosource we send in.
// Manually play the AudioSource after calling this method to hear it
// play the audio in reverse from the end of the AudioClip
public static void ReversePlaybackFromEnd(AudioSource audioSource)
{
audioSource.timeSamples = audioSource.clip.samples - 1;
audioSource.pitch *= -1f;
}
How would I go about doing this with an Fmod Studio event?
Use cases where I’d like to use this:
“Timescroll”-effects where the player can manipulate time and make the game simulate backwards/forwards.
An easy way of getting more variation out of some types of sound assets, since with this you can basically “duplicate” the amount of sound variations you have in the game, without using actual reversed versions of your pre-existing sound files.
FMOD Studio does not currently support playing sound files backwards. This feature is already on our feature/improvement tracker, but has not yet been scheduled for development.
Other games that feature “timescroll” play a generic rewind sound effect, or pitch down all diagetic sound (or apply some other effect to make the audio sound distorted).
Alright, so it’s safe to say that that feature will not be available for quite some time?
Yeah, those are all valid “timescroll”-techniques, but I’m mostly interested in the possibilities that (dynamically) reversed audio can bring to a game, especially how that could allow a Sound Designer to create even more interesting sound events, without adding any extra files to the game. Also how it could be used for music (eg. as heard in the video I shared above).
Speaking creating interesting events:
Are there any plans for Studio to add a “Reverse”-functionality to Instruments within an Fmod Event? Or at least something akin to the “Replace Audio with Trimmed Copy”-command, but replace it with a reversed copy instead (even though we’d lose getting “free” sound assets with this approach)?
We generally do not implement features that allow editing of audio files, as FMOD Studio is not a tool for editing audio files, but rather a tool for defining adaptive audio behavior in games. Our intent is that FMOD Studio be used in conjunction with linear audio editing software such as Ableton Live, Logic Pro, or Reaper; the expected workflow is that a sound designer makes their source assets in their linear audio editing tool, then gives them adaptive behavior in FMOD Studio.
Still, we do occasionally add features that allow editing of source audio files in simple ways, if a particular kind of file edit comes up frequently while using FMOD Studio or solves a common adaptive audio problem. “Replace Audio with Trimmed Copy” was one of these. Accordingly, I’ve submitted “Create reversed asset context menu item” to our feature/improvement tracker, and our developers will consider implementing it.
Ultimately we have decided not to go ahead with reverse playback as a feature in Studio. I’d recommend using a placeholder reverse-like sound or creating reversed assets in your editor of choice and importing them to Studio.
We have kept the task for a “create reversed” context menu item on sounds, but so far it has not been scheduled for development.
I was wondering if there have been any updates or changes regarding the backward playback feature. Has it been revisited, or are there any new alternatives or workarounds that you would recommend? My question is about FMOD Engine, not FMOD Studio, by the way.
FMOD engine had always been able to back an FMOD::Sound in reverse.
First, make sure you load it as FMOD_CREATESAMPLE, this decompresses the asset up front, which is required as you cannot decompress piecemeal in reverse (that’s not how compression algorithms are designed).
Next, when you play the FMOD::Sound, set the frequency of the FMOD::Channel to the negative of its sample rate. You can use FMOD::Channel::getFrequency to get the current value, then FMOD::Channel::setFrequency to apply the negative.
I can’t believe I missed that part in the Core API Reference page!
It’s a bit of a bummer that we can only do this with the CREATESAMPLE mode, though.
Like the original poster, I wanted to implement something that could completely play back in reverse, including long background music.
For short sound effects, it’s not an issue since I always import them with CREATESAMPLE for better performance. However, for background music, it’s not feasible due to the high memory usage when uncompressed. I understand the limitation with the current implementation, but I hope you can consider adding another API to achieve the same effect with longer audio files.
By the way, I noticed something odd while testing. Can you explain why the audio doesn’t play when I call setPosition() with the exact value returned by getLength()? To make it work, I have to subtract a small value, like 1, as shown below:
Most audio compression algorithms have a history, meaning to decode a section of audio, you need to have decoded several sections prior to it (to build up decoding state). When you play audio backwards you don’t have that history available, to do so would require seeking backwards, decoding forwards, then playing the result backwards. This causes a lot of duplicate decoding, since you need to discard (and not play) the history requirement of the file format. To manage expectations, this isn’t something we are considering.
A couple of alternate ideas:
Encode reversed versions of your audio files and switch when appropriate.
Create a DSP plugin that saves all the audio that passes through it up to a fixed time and can switch to playing back in reverse for up to that fixed time.
Open sounds as FMOD_CREATESAMPLE, save them to disk in reverse, then have FMOD stream them back in.
Fake the reverse noise with one or more pre-recorded reversed sounds.
With your question regarding setPosition, to avoid missing any audio, use FMOD_TIMEUNIT_PCM and seek to length - 1. You need the minus one because position is “zero based”. For example, at a sample rate of 48kHz, a PCM length of 48000 is exactly one second, the samples that make up that second are 0 to 47999, where 48000 is one past the end.
I actually thought of the first option after writing my previous comment, so thanks for confirming that! I think it’s the most appropriate approach since it doesn’t require many modifications, uses minimal memory, doesn’t limit the length of the backward playback, and allows easy control of other effects like matching the playback speed to the original or adjusting the reverse speed freely.
As for the answer to my question, I now understand why that happened. Thanks for all the detailed explanations!