intonarumori / libresample_flutter

A dart:ffi wrapper around libresample as a Flutter plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libresample_flutter

An implementation of libresample as a Flutter plugin using dart:ffi.

Usage

Firstly, import the package:

import 'package:libresample_flutter/libresample_flutter.dart';

You don't need to interact with the plugin class directly. (All its members are private anyway.) Instead, use the Dart wrapper classes Resampler or ResamplerStream.

Using Resampler

    // create a 2:1 upsampler
    var resampler = Resampler(true, 2, 2);

    // process a block of 160 floats
    resampler.process(2, Float32List(160), false);
    // etc

    // process the last block of 160 floats
    resampler.process(2, Float32List(160), true);

    // and free the native resources 
    resampler.close();

Using ResamplerStream

    // create a resampler node upsampling from 16kHz to the native sound card rate
    // and set its input to a previous processing block's output iterator
    var upsamplerStream = ResamplerStream(nativeRate / 16000.0, true)
      ..setInputStream(helper.getOutputStream().iterator);

    // and grab its iterator for use by the next block
    // (in the case of the ressmpler, the next block is typically the sound card,
    // perhaps using the companion project audio_worklet
    stream = upsamplerStream.getOutputStream().iterator;

See audio_worklet fo the companion project.

About

A dart:ffi wrapper around libresample as a Flutter plugin

License:Other


Languages

Language:C 59.8%Language:Dart 20.2%Language:Ruby 10.2%Language:Java 5.4%Language:Swift 2.2%Language:Objective-C 1.8%Language:CMake 0.5%