9 releases

0.6.0 Jun 2, 2019
0.5.1 Apr 3, 2018
0.5.0 Mar 27, 2018
0.4.0 Jan 16, 2017
0.3.1 Jan 22, 2016

#7 in Audio

Download history 12/week @ 2019-02-15 6/week @ 2019-02-22 24/week @ 2019-03-01 11/week @ 2019-03-08 51/week @ 2019-03-15 86/week @ 2019-03-22 81/week @ 2019-03-29 51/week @ 2019-04-05 67/week @ 2019-04-12 63/week @ 2019-04-19 31/week @ 2019-04-26 24/week @ 2019-05-03 21/week @ 2019-05-10 14/week @ 2019-05-17 23/week @ 2019-05-24

183 downloads per month
Used in 6 crates

MIT license

205KB
3K SLoC

ears Build Status Build status

A simple library to play sounds and music in Rust.

  • Convenient and easy to understand interface over OpenAL.
  • Supports a wide variety of audio formats via libsndfile.
  • Advanced features like HRTF and spatialization for free.
  • Perfect for game developers.

View documentation

Before you start

You need to install OpenAL and libsndfile on your system.

Linux (Debian and Ubuntu):

sudo apt install libopenal-dev libsndfile1-dev

Linux (Fedora):

sudo dnf install openal-soft-devel libsndfile-devel

Mac:

brew install openal-soft libsndfile

Windows:

Install MSYS2 according to the instructions. Be sure to use the default installation folder (i.e. C:\msys32 or C:\msys64), otherwise compiling won't work. Then, run the following in the MSYS2 shell:

pacman -S mingw-w64-x86_64-libsndfile mingw-w64-x86_64-openal

Usage

Include ears in your Cargo.toml dependencies.

[dependencies]
ears = "0.6.0"

Playing a sound effect while simultaneously streaming music off disk is as simple as it gets.

extern crate ears;
use ears::{Music, Sound, AudioController};

fn main() {
    let mut music = Music::new("your-music.ogg").unwrap();
    music.play();

    let mut sound = Sound::new("your-sound-effect.wav").unwrap();
    sound.play();

    while music.is_playing() || sound.is_playing() {};
}

Running examples

cargo run --example basic
cargo run --example advanced
cargo run --example music
cargo run --example record
cargo run --example simple_player
cargo run --example threads
cargo run --example direct_channel

Dependencies

~210KB