ears is a simple library to play Sounds and Musics in Rust

Related tags

Audio and Music ears
Overview

ears Build Status

ears is a simple library to play Sounds and Musics in Rust.

ears is build on the top of OpenAL and libsndfile.

  • Provides an access to the OpenAL spatialization functionality in a simple way.
  • Accepts a lot of audio formats, thanks to libsndfile.

A simple example

extern crate ears;
use ears::Sound;

fn main() {
	// Create a new Sound.
	let snd = Sound::new("path/to/my/sound.ogg").unwrap();

	// Play the Sound
	snd.play();

	// Wait until the end of the sound
	while snd.is_playing() {}
}

Functionalities

ears provides two ways to play audio files.

  • The Sound class, which represents light sounds who can share a buffer of samples with another Sound.
  • The Music class, which is a bigger sound and who can't share sample buffer.

Use ears

Like previously said, ears requires OpenAL and libsndfile. You need to install these two libraries on your system.

ears compiles against the last Rust compiler, so if it doesn't work on your computer you may need to update your compiler.

ears is built using make, so just type make at the root of the ears repository, this command builds ears, examples and the documentation.

You can build them separately too with the dedicated commands:

> make ears
> make examples
> make doc

then import stuff from ears in your project, you can import all the stuff:

#[feature(globs)];
extern crate ears;

use ears::*;

or a specific one:

extern crate ears;

use ears::Music;
Comments
  • linker does not find openal and sndfile during compilation

    linker does not find openal and sndfile during compilation

    compiler: aarch64-unknown-linux-gnu

       Compiling ears v0.7.0
    error: linking with `cc` failed: exit code: 1
      |
      = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/home/user/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.0.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.1.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.10.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.11.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.12.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.13.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.14.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.15.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.2.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.3.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.4.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.5.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.6.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.7.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.8.rcgu.o" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.ears.anbm2kd2-cgu.9.rcgu.o" "-o" "/home/user/damp_testbench/app/target/debug/deps/libears-5e84cb97ec7d30d6.so" "-Wl,--version-script=/tmp/rustc7lDbkB/list" "/home/user/damp_testbench/app/target/debug/deps/ears-5e84cb97ec7d30d6.37gvm7rvuv5hrvct.rcgu.o" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/user/damp_testbench/app/target/debug/deps" "-L" "/usr/local/opt/openal-soft/lib" "-L" "/usr/local/lib" "-L" "/home/user/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-lopenal" "-lsndfile" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustc7lDbkB/liblazy_static-2887b875a2ba4468.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc7lDbkB/liblibc-2e30353b214bbefe.rlib" "-Wl,--no-whole-archive" "-Wl,--start-group" "-L" "/home/user/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lstd-7b112611ce4b72da" "-Wl,--end-group" "-Wl,-Bstatic" "/tmp/rustc7lDbkB/libcompiler_builtins-68a4f8466685ed76.rlib" "-Wl,-Bdynamic" "-lutil" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil" "-shared"
      = note: /usr/bin/ld: cannot find -lopenal
              /usr/bin/ld: cannot find -lsndfile
              collect2: error: ld returned 1 exit status
              
    
    error: aborting due to previous error
    
    error: Could not compile `ears`.
    
    opened by vervaekejonathan 1
  • Minor cleanups and fixes

    Minor cleanups and fixes

    Remove ~ from the documentation, assert_eq! now compares slices in test, remove cargo-lite.conf plus edit .gitignore and use Travis CI's rust support.

    opened by suhr 1
  • Update to latest rust

    Update to latest rust

    Changed cases of #[deriving(Eq)] and #[deriving(Ord)] to #[deriving(PartialEq)] and #[deriving(PartialOrd)] Added #![allow(non_snake_case_functions)] to src/openal.rs to suppress warnings

    opened by branarm 1
  • Update the github repo

    Update the github repo

    I wanted to submit a PR for this to get it working on latest rust nightly but I can't find the real source code. The version on crates.io has been updated as recently as last month but the version here is ancient.

    opened by canndrew 3
  • Ears call crashes on even runs only

    Ears call crashes on even runs only

    I have very simple code:

    let mut sound = Sound::new(sound_ogg_file).unwrap();
    sound.play();
    while sound.is_playing() {
       sleep(Duration::from_millis(100));
    }
    sound.stop();
    

    It runs fine the first time (I cancel it with Ctrl+C since it loops and plays other files) but crashes on second, fourth, sixth etc. runs with the error below. Something does not get cleaned up properly on Ctrl+C signal. Any ideas what needs to be cleaned up?

    Crash location: https://github.com/jeremyletang/ears/blob/14b6c0bbf53ca4cfd70ff8884f67fb105d1eb382/src/internal.rs#L50

    ALSA lib pcm_dmix.c:1079:(snd_pcm_dmix_open) unable to open slave
    AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': File descriptor in bad state
    internal error: cannot open the default device.
    thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:325
    stack backtrace:
       1:     0x5567001175df - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
       2:     0x55670011a2bb - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
       3:     0x556700119f3f - std::panicking::default_hook::he0146e6a74621cb4
       4:     0x55670010ec1e - std::panicking::rust_panic_with_hook::h983af77c1a2e581b
       5:     0x55670011a501 - std::panicking::begin_panic::he426e15a3766089a
       6:     0x55670010faea - std::panicking::begin_panic_fmt::hdddb415186c241e7
       7:     0x55670011a49e - rust_begin_unwind
       8:     0x55670014fe3f - core::panicking::panic_fmt::hf4e16cb7f0d41a25
       9:     0x556700150118 - core::panicking::panic::h907815f47e914305
      10:     0x5566ffff0840 - _<core..option..Option<T>>::unwrap::h40c081deed71d1e9
                            at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/macros.rs:21
      11:     0x5566fffe87e5 - df_ambiance::main::hcebc08599674c5fb
                            at /home/skirmis/Work/DfAmbiance/src/main.rs:296
      12:     0x556700119b78 - std::panicking::try::call::h852b0d5f2eec25e4
      13:     0x55670012403b - __rust_try
      14:     0x556700123fde - __rust_maybe_catch_panic
      15:     0x55670011961e - std::rt::lang_start::hfe4efe1fc39e4a30
      16:     0x5566ffff0ea9 - main
      17:     0x7fb7bca86740 - __libc_start_main
      18:     0x5566fffbb728 - _start
      19:                0x0 - <unknown>
    error: Process didn't exit successfully: `target/debug/df_ambiance` (exit code: 101)
    
    opened by skligys 0
  • lib fix according Rust 1.0 standart

    lib fix according Rust 1.0 standart

    • all compilation errors fixed at lib, tests and examples
    • simple_player example works
    • not all tests passes, every launch random number of test fails or hungs up, seems like there is exists some threading mistake
    opened by rjdgtn 3
  • Compiling fails (v0.3.0)

    Compiling fails (v0.3.0)

    Compiling fails with:

    $ cargo build [17:05:34] Compiling ears v0.3.0 (file:///tmp/ears) src/internal.rs:36:100: 36:101 error: macros that expand to items must either be surrounded with braces or followed by a semicolon src/internal.rs:36 thread_local!(static AL_CONTEXT: RefCell<Box> = RefCell::new(box OpenAlData::default())) ^ src/internal.rs:192:1: 192:2 error: macros that expand to items must either be surrounded with braces or followed by a semicolon src/internal.rs:192 ) ^ src/init.rs:104:15: 104:19 error: proc is a reserved keyword src/init.rs:104 spawn(proc() { ^~~~ Could not compile ears.

    To learn more, run the command again with --verbose.

    $ cargo build --verbose [17:05:40] Compiling ears v0.3.0 (file:///tmp/ears) Running rustc src/ears.rs --crate-name ears --crate-type dylib --crate-type rlib -g --out-dir /tmp/ears/target/debug --emit=dep-info,link -L dependency=/tmp/ears/target/debug -L dependency=/tmp/ears/target/debug/deps src/internal.rs:36:100: 36:101 error: macros that expand to items must either be surrounded with braces or followed by a semicolon src/internal.rs:36 thread_local!(static AL_CONTEXT: RefCell<Box> = RefCell::new(box OpenAlData::default())) ^ src/internal.rs:192:1: 192:2 error: macros that expand to items must either be surrounded with braces or followed by a semicolon src/internal.rs:192 ) ^ src/init.rs:104:15: 104:19 error: proc is a reserved keyword src/init.rs:104 spawn(proc() { ^~~~ Could not compile ears.

    Caused by: Process didn't exit successfully: rustc src/ears.rs --crate-name ears --crate-type dylib --crate-type rlib -g --out-dir /tmp/ears/target/debug --emit=dep-info,link -L dependency=/tmp/ears/target/debug -L dependency=/tmp/ears/target/debug/deps (exit code: 101)

    opened by hanckmann 4
Owner
Jeremy Letang
Jeremy Letang
The sounds of sorting algos, in wasm

WebAudio View documentation for this example online or View compiled example online You can build the example locally with: $ npm run serve and then

Ian Schweer 0 Nov 6, 2021
musify is a simple discord bot to play music within a voice channel, written in the rust programming language.

musify-rs musify is a simple discord bot to play music within a voice channel, written in the rust programming language. Features A simple song queue

NV6 5 Aug 14, 2022
Drumsthesia is a simple software that helps you to learn how to play the drums (or midi controllers).

Drumsthesia A shameless copy of Neothesia adapted for e-Drums. Youtube Video Binaries for MacOS, Linux (untested) and Windows (untested). Download Scr

Rodrigo Watanabe 4 Mar 20, 2023
Play it here: https://ebbdrop.com/AoCropeSnake/

AoC Rope Snake A snake clone based on the rope physics from the day 9 puzzle from Advent of code 2022. The code is based of the snake example from mac

Ebbe Steenhoudt 3 Dec 15, 2022
simple-eq is a crate that implements a simple audio equalizer in Rust.

simple-eq A Simple Audio Equalizer simple-eq is a crate that implements a simple audio equalizer in Rust. It supports a maximum of 32 filter bands. Us

Mike Hilgendorf 11 Sep 17, 2022
Symphonia is a pure Rust audio decoding and media demuxing library supporting AAC, FLAC, MP3, MP4, OGG, Vorbis, and WAV.

Pure Rust multimedia format demuxing, tag reading, and audio decoding library

Philip Deljanov 1k Jan 2, 2023
Simple examples to demonstrate full-stack Rust audio plugin dev with baseplug and iced_audio

iced baseplug examples Simple examples to demonstrate full-stack Rust audio plugin dev with baseplug and iced_audio WIP (The GUI knobs do nothing curr

Billy Messenger 10 Sep 12, 2022
A library and application for lossless, format-preserving, two-pass optimization and repair of Vorbis data, reducing its size without altering any audio information.

OptiVorbis A library and application for lossless, format-preserving, two-pass optimization and repair of Vorbis data, reducing its size without alter

OptiVorbis 27 Jan 3, 2023
A CLI and library to convert data to sound, and vice versa (dependency-free)

Data to sound A simple crate to convert data to sound, and sound to data. The sound file format is wave (.wav). You can use it as a library or as a co

Awiteb 8 Feb 28, 2023
A very simple synth with 3 waveforms and configurable oscillators.

simple-synth This is an experimental project that implements a basic software synthesizer in Rust using the CPAL library. The synthesizer can generate

Juanma López G 6 Mar 8, 2023
Very simple, efficient, task oriented, low cognitive, Midi player and jukebox for midi instruments

Midi and Virtual Book jukebox Player A cross-platform MIDI and virtual book jukebox player. It only includes the necessary functionalities to play MID

Barrel Organ Discovery 4 Jun 29, 2023
A wav encoding and decoding library in Rust

Hound A wav encoding and decoding library in Rust. Hound can read and write the WAVE audio format, an ubiquitous format for raw, uncompressed audio. T

Ruud van Asseldonk 345 Dec 27, 2022
A low-overhead and adaptable audio playback library for Rust

Awedio   A low-overhead and adaptable audio playback library for Rust. Examples Play a single sound file: let (mut manager, backend) = awedio::start()

10 Buttons 20 May 25, 2023
🎵 A super simple VST written in Rust

DigiDist This is a simple little VST plugin, developed in Rust using the vst2 crate. It doesn't sound particularly great, but it demonstrates just how

Joe Clay 34 May 29, 2022
A simple GUI audio player written in Rust with egui. Inspired by foobar2000.

Music Player A simple GUI music player inspired by foobar2000 written in Rust using egui. The goal of this project is to learn about making gui/ nativ

Ryan Blecher 5 Sep 16, 2022
A simple GUI rust application that keeps track of how much time you spend on each application.

TimeSpent A simple GUI rust application that keeps track of how much time you spend on each application. Installation Click here to download the Setup

Slacked Lime 4 Sep 23, 2022
Simple personal server to serve audiofiles files from folders.

Simple personal server to serve audio files from directories. Intended primarily for audio books, but anything with decent directories structure will do. Focus here is on simplicity and minimalistic design.

Ivan Zderadicka 571 Dec 29, 2022
A simple CLI audio player with strange features.

legacylisten legacylisten is a simple CLI audio player I wrote because no existing one fulfilled my needs. The main feature is that you can change how

Matthias Kaak 3 Jun 8, 2022
A very simple audio synthesizer with a tuix gui

In this tutorial we'll create a very simple audio synthesiser application from scratch with a ui using tuix. The finished code for this tutorial can b

George Atkinson 24 Jan 6, 2023