How we built TiSynthEngine to generate audio in Titanium apps and games

We built a native module that generates sound from JavaScript on Android and iOS. Titanium Frontier put the mix to the test during play, and Sound 2.0 gave apps a way to reuse a sound and control each playback.

64 views 2 minutes
TiSynthEngine Audio Videogames
Photo for How we built TiSynthEngine to generate audio in Titanium apps and games

In Titanium Frontier, a short cue can start while the ship's thruster is still fading out. The cue has a fixed duration. The thruster has to keep playing while the player accelerates, change when boost kicks in, and fade when the player releases the control. In a single scene, the game needs to trigger one sound, change another that's already playing, and let the two overlap.

That's the development problem we addressed with ti.synthengine. The app could describe a sound in JavaScript and generate it on the spot on Android and iOS. Early versions already produced tones, chords, and patterns. An app could change a cue's pitch or duration without exporting another file. Keeping the thruster running and changing its sound during play also required a way for the engine to hold a note and accept changes while it played. TiSynthEngine repository · Development history

What stayed in JavaScript and what went into the native engine

The app decides when an event happens and which sound goes with it. The engine calculates the audio samples and schedules repeats and sequences on its own clock. JavaScript can start a pattern from the game screen while the engine handles the timing of each attack. We open the output stream with Oboe on Android and AVAudioEngine on iOS. Both platforms share the code for the envelope, filters, and frequency changes. The envelope shapes how a sound comes in and how long it takes to fade. Audio engine · Sound design guide

What Frontier and Synth Studio needed from the same engine

In Frontier, ti.game runs the scene and the audio service turns game actions into sounds. As the ship accelerates, the service adjusts the thruster's pitch and position. When thrust ends, it releases the note and the engine lets it fade while other effects keep playing. Titanium Frontier

Synth Studio let us hear changes that compete with the rest of the mix during a game. A note on the keyboard lets you hear how long the sound fades after you lift your finger. In Frontier, that same fade can overlap with the start of another effect. During validation for version 1.0.2, we tested both uses on an Android phone and an iPad. Validation record · Synth Studio on Google Play · Synth Studio on the App Store

Why 2.0 separated a sound from its playback

With direct calls, apps could end up repeating the same settings in several places and keeping IDs for any playback they wanted to change. In 2.0 we added createSound() to define a reusable recipe and adjust settings such as pitch for a single call to play(). For a held note, noteOn() returns a control for that playback. Frontier's integration uses that control to update and release the thruster. The module kept the direct calls. Sound API · 2.0 upgrade guide

To validate the change, we compared 80 captures of audio samples from the production renderer with captures from the previous version. The pairs matched byte for byte in the tested cases, with Android and iOS compared against their own baselines. Sound 2.0 validation

That separation lets Frontier adjust the thruster while it plays and release it when the maneuver ends. The open-source module gives other Titanium apps the same capability through a shared JavaScript interface on Android and iOS.

Example app · Android 2.0 release · iOS 2.0 release

Read in Spanish

Contact us on WhatsApp

Tell us what you would like to build. We will get back to you soon.

Send a message
Business hours: 9 a.m. to 6 p.m.