AudioData class

Class to manage audio samples.

The visualization must be enabled to be able to acquire data from the player. You can achieve this by calling SoLoud.instance.setVisualizationEnabled(true);.

Audio samples can be get from the player in three ways. See GetSamplesKind for more information.

IMPORTANT: remember to call dispose method when there is no more need to acquire audio.

After calling updateSamples it's possible to call AudioData.getAudioData to have back the audio samples. For example, using a "Ticker" in a Widget that needs the audio data to be displayed:

...
late final Ticker ticker;
late final AudioData audioData;
late final double waveData;
late final double fftData;

@override
void initState() {
  super.initState();
  audioData = AudioData(GetSamplesKind.linear);
  ticker = createTicker(_tick);
  ticker.start();
}

@override
void dispose() {
  ticker.stop();
  audioData.dispose();
  super.dispose();
}

void _tick(Duration elapsed) {
  if (context.mounted) {
    try {
      audioData.updateSamples();
      setState(() {});
    } on Exception catch (e) {
      debugPrint('$e');
    }
  }
}

Then in your "build" method, you can read the audio data:

try {
  /// Since we are used [GetSamplesKind.linear], `samples` will contain
  /// 512 floats: the first 256 are FFT values, the other 256 are wave values
  final samples = audioData.getAudioData();
  Float32List ffiData = samples.sublist(0, 256);
  Float32List waveData = samples.sublist(256, 512);
  /// Do something with `ffiData` and `waveData`
} on Exception catch (e) {
  debugPrint('$e');
}

To smooth FFT values use SoLoud.setFftSmoothing.

Constructors

AudioData.new(GetSamplesKind _getSamplesKind)
Initialize the way the audio data should be acquired.

Properties

getSamplesKind GetSamplesKind
The current type of data to acquire.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

changeSamplesKind(GetSamplesKind newKind) → void
Changes the input device from which to retrieve audio data and its kind.
dispose() → void
Dispose the memory allocated to acquire audio data. Must be called when there is no more need of AudioData otherwise memory leaks will occur.
getAudioData({bool alwaysReturnData = true}) Float32List
Get audio data only for visualization purposes. Don't use this method for audio processing or for saving audio data.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
updateSamples() → void
Update the content of samples memory to be read later using getAudioData.

Operators

operator ==(Object other) bool
The equality operator.
inherited