libao 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

Libao #

A Dart wrapper for the libao library.

Libao is a cross-platform audio library that allows programs to output audio using a simple API on a wide variety of platforms. It currently supports:

  • Null output (handy for testing without a sound device)
  • WAV files
  • AU files
  • RAW files
  • OSS (Open Sound System, used on Linux and FreeBSD)
  • ALSA (Advanced Linux Sound Architecture)
  • aRts (Analog RealTime Synth, used by KDE)
  • PulseAudio (next generation GNOME sound server)
  • esd (EsounD or Enlightened Sound Daemon)
  • Mac OS X
  • Windows (98 and later)
  • AIX
  • Sun/NetBSD/OpenBSD
  • IRIX
  • NAS (Network Audio Server)
  • RoarAudio (Modern, multi-OS, networked Sound System)
  • OpenBSD's sndio

Example #

import 'dart:math';
import 'dart:typed_data';

import 'package:libao/libao.dart';

void main() {
  final ao = Libao.open();

  ao.initialize();

  final driverId = ao.defaultDriverId();
  
  print(ao.driverInfo(driverId));

  const bits = 16;
  const channels = 2;
  const rate = 44100;

  final device = ao.openLive(
    driverId,
    bits: bits,
    channels: channels,
    rate: rate,
    matrix: 'R'
  );

  const volume = 0.5;
  const freq = 440.0;

  // Number of bytes * Channels * Sample rate.
  const bufferSize = bits ~/ 8 * channels * rate;
  final buffer = Uint8List(bufferSize);

  for (var i = 0; i < rate; i++) {
    final sample = (volume * 32768.0 * sin(2 * pi * freq * (i / rate))).round();
    // Left = Right.
    buffer[4 * i] = buffer[4 * i + 2] = sample & 0xff;
    buffer[4 * i + 1] = buffer[4 * i + 3] = (sample >> 8) & 0xff;
  }

  ao.play(device, buffer);

  ao.close(device);
  ao.shutdown();
}

0.1.0 #

  • Initial version.

example/main.dart

import 'dart:math';
import 'dart:typed_data';

import 'package:libao/libao.dart';

void main() {
  final ao = Libao.open();

  ao.initialize();

  final driverId = ao.defaultDriverId();
  
  print(ao.driverInfo(driverId));

  const bits = 16;
  const channels = 2;
  const rate = 44100;

  final device = ao.openLive(
    driverId,
    bits: bits,
    channels: channels,
    rate: rate,
  );

  const volume = 0.5;
  const freq = 440.0;

  // Number of bytes * Channels * Sample rate.
  const bufferSize = bits ~/ 8 * channels * rate;
  final buffer = Uint8List(bufferSize);

  for (var i = 0; i < rate; i++) {
    final sample = (volume * 32768.0 * sin(2 * pi * freq * (i / rate))).round();
    // Left = Right.
    buffer[4 * i] = buffer[4 * i + 2] = sample & 0xff;
    buffer[4 * i + 1] = buffer[4 * i + 3] = (sample >> 8) & 0xff;
  }

  ao.play(device, buffer);

  ao.close(device);
  ao.shutdown();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  libao: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:libao/libao.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
ffi ^0.1.3 0.1.3
Dev dependencies
test ^1.9.2