AudioEngineFFI constructor

AudioEngineFFI({
  1. String? libraryPath,
})

Implementation

AudioEngineFFI({String? libraryPath})
    : _lib = openLibrary(libraryPath),
      _engine = ffi.nullptr {
  final allocLib = openAllocatorLibrary();
  _malloc = allocLib.lookupFunction<_MallocNative, _MallocDart>('malloc');
  _free = allocLib.lookupFunction<_FreeNative, _FreeDart>('free');

  _createEngine = _lib.lookupFunction<_CreateEngineNative, _CreateEngineDart>(
    'ae_create_engine',
  );
  _destroyEngine =
      _lib.lookupFunction<_DestroyEngineNative, _DestroyEngineDart>(
    'ae_destroy_engine',
  );
  _setPlaylist = _lib.lookupFunction<_SetPlaylistNative, _SetPlaylistDart>(
    'ae_set_playlist',
  );
  _addToPlaylist =
      _lib.lookupFunction<_AddToPlaylistNative, _AddToPlaylistDart>(
    'ae_add_to_playlist',
  );
  _insertToPlaylist =
      _lib.lookupFunction<_InsertToPlaylistNative, _InsertToPlaylistDart>(
    'ae_insert_to_playlist',
  );
  _removeFromPlaylist =
      _lib.lookupFunction<_RemoveFromPlaylistNative, _RemoveFromPlaylistDart>(
    'ae_remove_from_playlist',
  );
  _movePlaylistItem =
      _lib.lookupFunction<_MovePlaylistItemNative, _MovePlaylistItemDart>(
    'ae_move_playlist_item',
  );
  _clearPlaylist =
      _lib.lookupFunction<_ClearPlaylistNative, _ClearPlaylistDart>(
    'ae_clear_playlist',
  );

  _play = _lib.lookupFunction<_BoolOpNative, _BoolOpDart>('ae_play');
  _pause = _lib.lookupFunction<_BoolOpNative, _BoolOpDart>('ae_pause');
  _stop = _lib.lookupFunction<_BoolOpNative, _BoolOpDart>('ae_stop');
  _next = _lib.lookupFunction<_BoolOpNative, _BoolOpDart>('ae_next');
  _prev = _lib.lookupFunction<_BoolOpNative, _BoolOpDart>('ae_prev');

  _seek = _lib.lookupFunction<_SeekNative, _SeekDart>('ae_seek');
  _jumpTo = _lib.lookupFunction<_JumpNative, _JumpDart>('ae_jump_to');
  _jumpToWithPosition =
      _lib.lookupFunction<_JumpWithPositionNative, _JumpWithPositionDart>(
    'ae_jump_to_with_position',
  );
  _getStatus = _lib.lookupFunction<_GetStatusNative, _GetStatusDart>(
    'ae_get_status',
  );
  _getPipelineState =
      _lib.lookupFunction<_GetPipelineStateNative, _GetPipelineStateDart>(
    'ae_get_pipeline_state',
  );
  _getLastError = _lib.lookupFunction<_GetLastErrorNative, _GetLastErrorDart>(
    'ae_get_last_error',
  );
  _clearLastError =
      _lib.lookupFunction<_ClearLastErrorNative, _ClearLastErrorDart>(
    'ae_clear_last_error',
  );

  _setLoopMode = _lib.lookupFunction<_SetIntNative, _SetIntDart>(
    'ae_set_loop_mode',
  );
  _setShuffleEnabled = _lib.lookupFunction<_SetIntNative, _SetIntDart>(
    'ae_set_shuffle_enabled',
  );
  _reshuffle = _lib.lookupFunction<_ClearPlaylistNative, _ClearPlaylistDart>(
    'ae_reshuffle',
  );
  _setCrossfadeEnabled = _lib.lookupFunction<_SetIntNative, _SetIntDart>(
    'ae_set_crossfade_enabled',
  );
  _getCrossfadeEnabled = _lib.lookupFunction<_GetIntNative, _GetIntDart>(
    'ae_get_crossfade_enabled',
  );
  _setCrossfadeDurationMs = _lib.lookupFunction<_SetIntNative, _SetIntDart>(
    'ae_set_crossfade_duration_ms',
  );
  _getCrossfadeDurationMs = _lib.lookupFunction<_GetIntNative, _GetIntDart>(
    'ae_get_crossfade_duration_ms',
  );

  _setReverbEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_reverb_enabled',
  );
  _setReverbParams =
      _lib.lookupFunction<_SetReverbParamsNative, _SetReverbParamsDart>(
    'ae_set_reverb_params',
  );
  _setEqEnabled = _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_eq_enabled',
  );
  _setEqGains = _lib.lookupFunction<_SetEqGainsNative, _SetEqGainsDart>(
    'ae_set_eq_gains',
  );
  _setGain = _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
    'ae_set_gain',
  );
  _setPan = _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
    'ae_set_pan',
  );
  _setPitch = _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
    'ae_set_pitch',
  );
  _setLowpassEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_lowpass_enabled',
  );
  _setLowpassCutoff =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
    'ae_set_lowpass_cutoff',
  );
  _setHighpassEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_highpass_enabled',
  );
  _setHighpassCutoff =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
    'ae_set_highpass_cutoff',
  );
  _setDelayEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_delay_enabled',
  );
  _setDelayParams =
      _lib.lookupFunction<_SetReverbParamsNative, _SetReverbParamsDart>(
    'ae_set_delay_params',
  );
  _setStereoWiden =
      _lib.lookupFunction<_SetStereoWidenNative, _SetStereoWidenDart>(
    'ae_set_stereo_widen',
  );
  _setBandpassEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_bandpass_enabled',
  );
  _setBandpassParams =
      _lib.lookupFunction<_SetTwoFloatsNative, _SetTwoFloatsDart>(
    'ae_set_bandpass_params',
  );
  _setPeakEqEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_peak_eq_enabled',
  );
  _setPeakEqParams =
      _lib.lookupFunction<_SetReverbParamsNative, _SetReverbParamsDart>(
    'ae_set_peak_eq_params',
  );
  _setNotchEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_notch_enabled',
  );
  _setNotchParams =
      _lib.lookupFunction<_SetTwoFloatsNative, _SetTwoFloatsDart>(
    'ae_set_notch_params',
  );
  _setLowshelfEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_lowshelf_enabled',
  );
  _setLowshelfParams =
      _lib.lookupFunction<_SetReverbParamsNative, _SetReverbParamsDart>(
    'ae_set_lowshelf_params',
  );
  _setHighshelfEnabled =
      _lib.lookupFunction<_SetFxEnabledNative, _SetFxEnabledDart>(
    'ae_set_highshelf_enabled',
  );
  _setHighshelfParams =
      _lib.lookupFunction<_SetReverbParamsNative, _SetReverbParamsDart>(
    'ae_set_highshelf_params',
  );

  // Custom Filters
  _setCustomLpf1Params = _lib
      .lookupFunction<_SetCustomLpf1ParamsNative, _SetCustomLpf1ParamsDart>(
    'ae_set_custom_lpf1_params',
  );
  _setCustomHpf1Params = _lib
      .lookupFunction<_SetCustomLpf1ParamsNative, _SetCustomLpf1ParamsDart>(
    'ae_set_custom_hpf1_params',
  );
  _setCustomBiquadParams = _lib.lookupFunction<_SetCustomBiquadParamsNative,
      _SetCustomBiquadParamsDart>(
    'ae_set_custom_biquad_params',
  );

  // Spatialization
  _setSpatializationEnabled = _lib.lookupFunction<
      _SetSpatializationEnabledNative,
      _SetSpatializationEnabledDart>('ae_set_spatialization_enabled');
  _setPosition = _lib.lookupFunction<_SetSpatializationVec3Native,
      _SetSpatializationVec3Dart>('ae_set_position');
  _setDirection = _lib.lookupFunction<_SetSpatializationVec3Native,
      _SetSpatializationVec3Dart>('ae_set_direction');
  _setVelocity = _lib.lookupFunction<_SetSpatializationVec3Native,
      _SetSpatializationVec3Dart>('ae_set_velocity');
  _setAttenuationModel = _lib
      .lookupFunction<_SetIntNative, _SetIntDart>('ae_set_attenuation_model');
  _setRolloff =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_rolloff');
  _setMinGain =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_min_gain');
  _setMaxGain =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_max_gain');
  _setMinDistance =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_min_distance');
  _setMaxDistance =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_max_distance');
  _setDopplerFactor =
      _lib.lookupFunction<_SetSingleFloatNative, _SetSingleFloatDart>(
          'ae_set_doppler_factor');

  // Fading & Scheduling
  _setFadeInMilliseconds = _lib.lookupFunction<_SetFadeInMillisecondsNative,
      _SetFadeInMillisecondsDart>('ae_set_fade_in_milliseconds');
  _setStartTimeInPcmFrames =
      _lib.lookupFunction<_SetTimeInPcmFramesNative, _SetTimeInPcmFramesDart>(
          'ae_set_start_time_in_pcm_frames');
  _setStopTimeInPcmFrames =
      _lib.lookupFunction<_SetTimeInPcmFramesNative, _SetTimeInPcmFramesDart>(
          'ae_set_stop_time_in_pcm_frames');
  _getEngineTimeInPcmFrames = _lib.lookupFunction<
      _GetEngineTimeInPcmFramesNative,
      _GetEngineTimeInPcmFramesDart>('ae_get_engine_time_in_pcm_frames');
  _setEndCallback =
      _lib.lookupFunction<_SetEndCallbackNative, _SetEndCallbackDart>(
          'ae_set_end_callback');

  // Advanced Audio Features Bindings
  _setOutputFormat =
      _lib.lookupFunction<_SetOutputFormatNative, _SetOutputFormatDart>(
    'ae_set_output_format',
  );
  _getOutputFormat =
      _lib.lookupFunction<_GetOutputFormatNative, _GetOutputFormatDart>(
    'ae_get_output_format',
  );
  _setOutputSampleRate =
      _lib.lookupFunction<_SetOutputRateNative, _SetOutputRateDart>(
    'ae_set_output_sample_rate',
  );
  _getOutputSampleRate =
      _lib.lookupFunction<_GetOutputRateNative, _GetOutputRateDart>(
    'ae_get_output_sample_rate',
  );
  _setOutputChannels =
      _lib.lookupFunction<_SetOutputChannelsNative, _SetOutputChannelsDart>(
    'ae_set_output_channels',
  );
  _getOutputChannels =
      _lib.lookupFunction<_GetOutputChannelsNative, _GetOutputChannelsDart>(
    'ae_get_output_channels',
  );

  _setEngineResampleAlgorithm = _lib.lookupFunction<
      _SetEngineResampleAlgorithmNative,
      _SetEngineResampleAlgorithmDart>('ae_set_engine_resample_algorithm');
  _getEngineResampleAlgorithm = _lib.lookupFunction<
      _GetEngineResampleAlgorithmNative,
      _GetEngineResampleAlgorithmDart>('ae_get_engine_resample_algorithm');

  _setEngineDitherMode = _lib.lookupFunction<_SetEngineDitherModeNative,
      _SetEngineDitherModeDart>('ae_set_engine_dither_mode');
  _getEngineDitherMode = _lib.lookupFunction<_GetEngineDitherModeNative,
      _GetEngineDitherModeDart>('ae_get_engine_dither_mode');

  // Limiter & Clipping Detection
  _setLimiterEnabled =
      _lib.lookupFunction<_SetLimiterEnabledNative, _SetLimiterEnabledDart>(
          'ae_set_limiter_enabled');
  _setLimiterParams =
      _lib.lookupFunction<_SetLimiterParamsNative, _SetLimiterParamsDart>(
          'ae_set_limiter_params');
  _setClippingDetectionEnabled = _lib.lookupFunction<
      _SetClippingDetectionEnabledNative,
      _SetClippingDetectionEnabledDart>('ae_set_clipping_detection_enabled');
  _getClippedSamplesCount = _lib.lookupFunction<_GetClippedSamplesCountNative,
      _GetClippedSamplesCountDart>('ae_get_clipped_samples_count');
  _resetClippedSamplesCount = _lib.lookupFunction<
      _ResetClippedSamplesCountNative,
      _ResetClippedSamplesCountDart>('ae_reset_clipped_samples_count');

  _initMultibandEq =
      _lib.lookupFunction<_InitMultibandEqNative, _InitMultibandEqDart>(
    'ae_init_multiband_eq',
  );
  _setMultibandEqEnabled = _lib.lookupFunction<_SetMultibandEqEnabledNative,
      _SetMultibandEqEnabledDart>('ae_set_multiband_eq_enabled');
  _setMultibandEqGain =
      _lib.lookupFunction<_SetMultibandEqGainNative, _SetMultibandEqGainDart>(
    'ae_set_multiband_eq_gain',
  );
  _getMultibandEqGain =
      _lib.lookupFunction<_GetMultibandEqGainNative, _GetMultibandEqGainDart>(
    'ae_get_multiband_eq_gain',
  );
  _setMultibandFxEnabled = _lib.lookupFunction<_SetMultibandFxEnabledNative,
      _SetMultibandFxEnabledDart>('ae_set_multiband_fx_enabled');
  _setMultibandFxBands = _lib
      .lookupFunction<_SetMultibandFxBandsNative, _SetMultibandFxBandsDart>(
    'ae_set_multiband_fx_bands',
  );
  _clearMultibandFx =
      _lib.lookupFunction<_ClearMultibandFxNative, _ClearMultibandFxDart>(
    'ae_clear_multiband_fx',
  );

  _initPushStream =
      _lib.lookupFunction<_InitPushStreamNative, _InitPushStreamDart>(
    'ae_init_push_stream',
  );
  _pushStreamChunk =
      _lib.lookupFunction<_PushStreamChunkNative, _PushStreamChunkDart>(
    'ae_push_stream_chunk',
  );
  _endPushStream =
      _lib.lookupFunction<_EndPushStreamNative, _EndPushStreamDart>(
    'ae_end_push_stream',
  );
  _getPushStreamBufferedBytes = _lib.lookupFunction<
      _GetPushStreamBufferedBytesNative, _GetPushStreamBufferedBytesDart>(
    'ae_get_push_stream_buffered_bytes',
  );

  _setAnalyzerEnabled =
      _lib.lookupFunction<_SetAnalyzerEnabledNative, _SetAnalyzerEnabledDart>(
    'ae_set_analyzer_enabled',
  );
  _configureAnalyzer =
      _lib.lookupFunction<_ConfigureAnalyzerNative, _ConfigureAnalyzerDart>(
    'ae_configure_analyzer',
  );
  _getAnalyzerFrameSize = _lib.lookupFunction<_GetAnalyzerFrameSizeNative,
      _GetAnalyzerFrameSizeDart>('ae_get_analyzer_frame_size');
  _pollAnalyzerFrame =
      _lib.lookupFunction<_PollAnalyzerFrameNative, _PollAnalyzerFrameDart>(
    'ae_poll_analyzer_frame',
  );
  _getAnalyzerDroppedFrames = _lib.lookupFunction<
      _GetAnalyzerDroppedFramesNative,
      _GetAnalyzerDroppedFramesDart>('ae_get_analyzer_dropped_frames');

  try {
    _getNetworkStreamingSupport = _lib.lookupFunction<
        _GetNetworkStreamingSupportNative,
        _GetNetworkStreamingSupportDart>('ae_is_network_streaming_supported');
  } catch (_) {
    _getNetworkStreamingSupport = null;
  }
}