A Flutter plugin to allow Flutter apps to use the BASS audio library from un4seen Developments.
BASS is an audio library that supports (among other architectures) both iOS and Android.
The flutter_bass example app has four buttons related to BASS:
As a comparison, there are also three buttons below to use the soundpool Flutter package:
Finally, as a further comparison, there are three buttons to use the [flutter_ogg_piano Flutter package] (https://pub.dev/packages/flutter_ogg_piano). (Note that these buttons are not shown in the image below.)
<img src="/LatencyTesting/IMG_0034.PNG" alt="Example app screenshot" title="Example app screenshot" style="display: inline-block; margin: 0 auto; max-width: 300px">
Latency can be measured using an audio recorder on another (i.e. not the one running flutter_bass) device. For example, I use the Samsung VoiceRecorder app on a Samsung Galaxy S7. Record audio while hitting the "Play" button on the flutter_bass app. Try to make a sound when hitting the play button, for example by using your fingernail. Note that this latency will include the time for Flutter to recognize the button press as well as the time to play the audio file.
Save the audio recording and then open it in an audio tool such as Audacity. Zoom in on the waveform and measure the time between the button press and the cowbell sound.
<img src="/LatencyTesting/LatencyMeasurementUsingAudacity.png" alt="Latency measurement using Audacity" title="Latency measurement using Audacity" style="display: inline-block; margin: 0 auto; max-width: 300px">
The following table compares the button-press-to-playback latency of the different sound libraries/plugins on the devices I've tested so far. As mentioned above, these latencies all include the time for the OS to recognize the button press so are not a true absolute measure of the playback latency of the sound library; they are however useful for relative comparisons.
Sound library/plugin | Device | Mean Latency (N=5) | Latency Stdev (N=5) |
---|---|---|---|
BASS 2.4 | iPhone 6 | 115ms | 11.3ms |
Soundpool | iPhone 6 | 238ms | 12.3ms |
BASS 2.4 | Samsung Galaxy S7 | 153ms | 5.6ms |
flutter_ogg_piano | Samsung Galaxy S7 | 158ms | 5.9ms |
To achieve the Android BASS result above, some tweaking was required to get from the first working result of 267ms (yikes!) to the improved result of 153ms:
W/AudioTrack(29616): AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 44100 Hz, output 48000 Hz.
[ +6 ms] I/AudioTrack(29616): AUDIO_OUTPUT_FLAG_FAST successful; frameCount 480 -> 480
My conclusions: