I’m new to working with both Unity and FMOD, so I apologize if this question is either too simple or poorly phrased. I’m primarily a 3D artist rather than a programmer.
I’m currently working on a project with the following goal:
When a recording is triggered, Unity should record all game world audio along with user microphone input into a single audio file. Later, when playback is triggered, FMOD should play that recording and apply various audio effects. Users can make multiple recordings; a new file is created each time.
Project Context
The project simulates an old phonograph.
Users will be able to start a recording and then create sounds in the game environment (i.e. by clicking on instruments in the game world) while also speaking into their microphone. Both the in-game audio and microphone input should be recorded simultaneously into one file.
Once the recording is finished, users can play their recording back through the phonograph. During playback, FMOD should apply effects such as:
Pitch instability / wow and flutter
EQ filtering
Surface noise
Other artifacts to emulate a real phonograph
My Current Idea
Since my programming experience is limited, my initial idea was the following workflow:
Record audio using Unity
Save the recording to a file in a specific project folder
When playback is triggered, FMOD loads that file and plays it back with the phonograph effects applied
My Questions
How can I implement my idea? (Code examples welcome!)
Is this a reasonable approach for achieving this effect?
Is there a better or more typical way to handle something like this using Unity and FMOD?
Are there recommended workflows for recording both in-game audio and microphone input together?
Any advice, suggestions, or pointers to documentation would be greatly appreciated.
Hi! It’s entirely possible to implement this behavior, though for simplicity’s sake, it’s worth noting that you don’t need to use both Unity Audio and FMOD. You can implement it solely in Unity Audio or FMOD, depending on which better suits your purposes.
With that said, to implement it as you’ve described, recording audio in Audio and passing it to FMOD, you’d want to do the following:
To record audio from the Unity side of things, I’d recommend using MonoBehavior.OnAudioFilterRead, likely on the Audio Listener component, which should give you access to all audio data in the scene. From there, you can copy the data to a buffer, and optionally save it to file. You should be able to use the Microphone class in Unity’s audio system to record microphone audio alongside all the audio sources in the scene.
Then, once you have a stored audio buffer or saved audio file, you can play it back into your FMOD system. The simplest way to do this would be to set up your phonograph effects in FMOD Studio, and then create an event containing a programmer instrument that is routed into the effects. The event will expose a “programmer sound” callback that lets you play your recorded sound directly into the event. Our Programmer Sounds scripting example shows how to set up the callback, though instead of passing through a “key” to the callback via setUserData(), you’d want to pass your audio data/file in instead.
I’ve had a little time to play around with Unity and FMOD and actually managed to record audio using FMOD and a DSP node attached to the master bus. I can now record both microphone input and game world audio onto two separate tracks and combine them using a script! I was unable to record both mic and world audio into a single file straight away because the microphone audio would play back into my headphones as I was recording it. Couldn’t figure out how to mute that, so I decided to split the audio into two files and unify them.
Now the only thing that’s left is what you said - implementing a programmer instrument for playback