Idiomatic Rust bindings for OpenAL 1.1 and extensions (including EFX).

Related tags

Audio and Music alto
Overview

alto

alto provides idiomatic Rust bindings for OpenAL 1.1 and extensions (including EFX).

WARNING

Because Alto interacts with global C state via dynamic linking, having multiple versions of Alto in one project could lead to unsafety. Please make sure only one version of Alto is in your dependency tree at any given time.

API Usage

let alto = Alto::load_default()?;

for s in alto.enumerate_outputs() {
    println!("Found device: {}", s.to_str()?);
}

let device = alto.open(None)?; // Opens the default audio device
let context = device.new_context(None)?; // Creates a default context

// Configure listener
context.set_position([1.0, 4.0, 5.0]);
context.set_velocity([2.5, 0.0, 0.0]);
context.set_orientation(([0.0, 0.0, 1.0], [0.0, 1.0, 0.0]));

let source = context.new_static_source()?;

// Now you can load your samples and store them in a buffer with
// `context.new_buffer(samples, frequency)`;
Comments
  • Building alto on Emscripten

    Building alto on Emscripten

    I recently tried to build a dummy project listing alto as one of its dependencies, targeting Emscripten with --target asmjs-unknown-emscripten, and it failed because libloading does not (yet) support Emscripten.
    I had reported this, but in the meantime, al-sys actually does not need the libloading dependency when target Emscripten, because there, "out-of-the-box" support for OpenAL is claimed (see this issue).

    My suggestion : When the target is Emscripten, fall back to simply declaring the FFI bindings, and disable the libloading dependency so that it builds successfully.

    opened by yoanlcq 15
  • Need alcGetCurrentContext() and alcGetContextsDevice() for library I'm writing.

    Need alcGetCurrentContext() and alcGetContextsDevice() for library I'm writing.

    Hello!

    I need those two methods in order to properly implement the destructor for my Rust library. Is there a way that they can be added, please?

    Thank you!

    opened by sunnystormy 12
  • Compiling for MinGW-W64

    Compiling for MinGW-W64

    I’ve been trying to compile the crate on mingw-w64 for hours. I haven’t found a way to make it through with the crates.io crate, so I downloaded openal-rs, add a local override to my project and changed the link target from #[link(name = "openal32")] to #[link(name = "openal")], because that’s what pkg-config expects if you pass it --libs openal.

    After our talk on IRC, you uploaded an upper-case version that will work for the native Windows installation but not for MinGW. What can we do about that?

    opened by phaazon 10
  • Add

    Add "alut" to this package?

    ALUT adds some helper methods for initializing audio files and creating/binding a buffer. Is there a way you can get that added inside of this package so users don't have to resort to the boilerplate "alc" conventions?

    opened by sunnystormy 6
  • add a dynamic feature flag, allowing static linking if desired

    add a dynamic feature flag, allowing static linking if desired

    On platforms like android, openalsoft can be linked to statically or dynamically. This feature flag allows deciding between the "emscripten" style static linking, or dynamic linking (default). Static linking can save a lot of space in the final APK, so android users will likely prefer it.

    Currently it is up to the client to figure out how to link statically to the openal implementation. This PR makes no attempt to build openal for android. Though, I may try to add that in the future (once I've worked out the kinks).

    opened by mtak- 5
  • Support for rustc nightly 2014-06-29

    Support for rustc nightly 2014-06-29

    • Changed * to *const
    • Changed enum repr to i32 to fix type mismatch errors
    • Also an unrelated change that fixes Source::unqueue_buffer and Source::unqueue_buffers so they handle errors and return results instead of filling buffers
    opened by samyatchmenoff 5
  • Alto::open_loopback(None) returns Invalid Device Error

    Alto::open_loopback(None) returns Invalid Device Error

    i get thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: InvalidDevice', libcore/result.rs:945:5 in the third line.

    fn main () {
        let alto =  Alto::load_default().unwrap();
        let mut loopback: LoopbackDevice<Stereo<i16>> = alto.open_loopback(None).unwrap()
    }
    

    when i call alcLoopbackOpenDeviceSOFT(NULL); in openal-soft directly, it works. Is the rust code equivalent to the c code or did i miss something?

    opened by sebastianpfluegelmeier 3
  • error[E0283]: type annotations required: cannot resolve `_: audio::alto::SampleFrame`

    error[E0283]: type annotations required: cannot resolve `_: audio::alto::SampleFrame`

    Sorry, this is probably a silly error on my part, but I can't figure this one out.

    I'm trying to load samples from an array of Vorbis bytes. I currently have this naive start:

        pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
            let reader = OggStreamReader::new(Cursor::new(bytes))
                .map_err(|e| err_msg("Failed to create stream reader"))?;
            let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
            let audio_channels = reader.ident_hdr.audio_channels;
            let decoded: Vec<i16> = Vec::new();
            /*while let Some(samples) = reader.read_dec_packet_itl()? {
                decoded.append(&mut samples);
            }*/
            self.0.new_buffer(decoded, sample_rate)
                .map_err(|e| err_msg("Error creating buffer"))
        }
    

    That case doesn't work. Neither does the case where the block is uncommented and, in theory, I'm appending decoded samples to a larger byte vec I'll ultimately pass to the buffer creation call. If I do:

        pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
            let reader = OggStreamReader::new(Cursor::new(bytes))
                .map_err(|e| err_msg("Failed to create stream reader"))?;
            let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
            let audio_channels = reader.ident_hdr.audio_channels;
            let decoded: Vec<i16> = Vec::new();
            while let Some(samples) = reader.read_dec_packet_itl()? {
                //decoded.append(&mut samples);
                self.0.new_buffer(samples, sample_rate);
            }
            self.0.new_buffer(decoded, sample_rate)
                .map_err(|e| err_msg("Error creating buffer"))
        }
    

    That seems to work, in so far as it creates a buffer with the freshly-loaded samples in the loop, but the last buffer creation call with decoded still fails.

    If I scatter around println! calls, I'm told that the samples are Vec<i16>. That's what my decoded buffer is as well, so I don't know what I'm getting wrong. I've tried a few type annotation combinations, but I can't get a match. What am I missing here?

    P.s. I know I'll likely ultimately want to switch to streaming, but I'm just working with short samples now, and am trying to build up complexity over time. Thanks for any help!

    opened by ndarilek 3
  • Link against openal-soft (libopenal.dylib) on OSX (instead of framework version)

    Link against openal-soft (libopenal.dylib) on OSX (instead of framework version)

    This may be kind of a pain for you, but I wonder if there is any way to give the option without needing have a whole other package. The problem is that openal-soft compiles as a dylib typically in /usr/local/lib but the openal link is specified as framework in this package so I just had to modify that one line in a local project to get it working.

    opened by venetanji 3
  • Relicense under dual MIT/Apache-2.0

    Relicense under dual MIT/Apache-2.0

    This issue was automatically generated. Feel free to close without ceremony if you do not agree with re-licensing or if it is not possible for other reasons. Respond to @cmr with any questions or concerns, or pop over to #rust-offtopic on IRC to discuss.

    You're receiving this because someone (perhaps the project maintainer) published a crates.io package with the license as "MIT" xor "Apache-2.0" and the repository field pointing here.

    TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that license is good for interoperation. The MIT license as an add-on can be nice for GPLv2 projects to use your code.

    Why?

    The MIT license requires reproducing countless copies of the same copyright header with different names in the copyright field, for every MIT library in use. The Apache license does not have this drawback. However, this is not the primary motivation for me creating these issues. The Apache license also has protections from patent trolls and an explicit contribution licensing clause. However, the Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and doing so would be wise for this project. This also makes this crate suitable for inclusion and unrestricted sharing in the Rust standard distribution and other projects using dual MIT/Apache, such as my personal ulterior motive, the Robigalia project.

    Some ask, "Does this really apply to binary redistributions? Does MIT really require reproducing the whole thing?" I'm not a lawyer, and I can't give legal advice, but some Google Android apps include open source attributions using this interpretation. Others also agree with it. But, again, the copyright notice redistribution is not the primary motivation for the dual-licensing. It's stronger protections to licensees and better interoperation with the wider Rust ecosystem.

    How?

    To do this, get explicit approval from each contributor of copyrightable work (as not all contributions qualify for copyright, due to not being a "creative work", e.g. a typo fix) and then add the following to your README:

    ## License
    
    Licensed under either of
    
     * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
     * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
    
    at your option.
    
    ### Contribution
    
    Unless you explicitly state otherwise, any contribution intentionally submitted
    for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
    additional terms or conditions.
    

    and in your license headers, if you have them, use the following boilerplate (based on that used in Rust):

    // Copyright 2016 openal-rs developers
    //
    // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
    // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
    // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
    // option. This file may not be copied, modified, or distributed
    // except according to those terms.
    

    It's commonly asked whether license headers are required. I'm not comfortable making an official recommendation either way, but the Apache license recommends it in their appendix on how to use the license.

    Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these from the Rust repo for a plain-text version.

    And don't forget to update the license metadata in your Cargo.toml to:

    license = "MIT/Apache-2.0"
    

    I'll be going through projects which agree to be relicensed and have approval by the necessary contributors and doing this changes, so feel free to leave the heavy lifting to me!

    Contributor checkoff

    To agree to relicensing, comment with :

    I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.
    

    Or, if you're a contributor, you can check the box in this repo next to your name. My scripts will pick this exact phrase up and check your checkbox, but I'll come through and manually review this issue later as well.

    • [ ] @bjz
    • [ ] @jpernst
    • [x] @samyatchmenoff
    • [ ] @MarkJr94
    • [ ] @benw
    • [ ] @kvark
    • [x] @suhr
    opened by emberian 3
  • Nightly fixes; remove feature gates

    Nightly fixes; remove feature gates

    This fixes the use of a few deprecated methods and removes all gated functionality in preparation for beta1 and crates.io.

    On a related note, I saw over on the cgmath board that you've got a lot on your plate. I'd be happy to assume maintenance of openal-rs if you'd rather focus on your other projects; just let me know.

    opened by jpernst 3
Owner
null
PortAudio bindings and wrappers for Rust.

rust-portaudio PortAudio bindings and wrappers for Rust. PortAudio is a free, cross-platform, open-source, audio I/O library. rust-portaudio is still

null 331 Dec 23, 2022
PortAudio bindings and wrappers for Rust.

rust-portaudio PortAudio bindings and wrappers for Rust. PortAudio is a free, cross-platform, open-source, audio I/O library. rust-portaudio is still

null 332 Dec 30, 2022
Rust bindings for the soloud audio engine library

soloud-rs A crossplatform Rust bindings for the soloud audio engine library. Supported formats: wav, mp3, ogg, flac. The library also comes with a spe

Mohammed Alyousef 38 Dec 8, 2022
minimp3 rust bindings + wrapper

minimp3 Rust bindings Usage example # Cargo.toml [dependencies] minimp3 = "0.5" use minimp3::{Decoder, Frame, Error}; use std::fs::File; fn main()

german gömez 52 Dec 2, 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
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 Rust environment for sound synthesis and algorithmic composition.

Sorceress A Rust environment for sound synthesis and algorithmic composition, powered by SuperCollider. Overview Sorceress is a Rust crate that provid

Wesley Merkel 82 Dec 26, 2022
Implements the free and open audio codec Opus in Rust.

opus-native Overview Implements the free and open audio codec Opus in Rust. Status This crate is under heavy development. Most functionality is not wo

Nils Hasenbanck 9 Nov 28, 2022
Auritia is a DAW coded in Rust and Vue in hopes of having cross platform compatability, while also providing enough features for anyone to use professionally

Steps Install WebView if you're not on Windows 11 Install Node deps npm i To run the dev server do npm run tauri dev Compiling Linux You will need to

Auritia 20 Aug 27, 2022
Loopers is graphical live looper, written in Rust, designed for ease of use and rock-solid stability

Loopers Loopers is a graphical live looper, written in Rust, designed for ease of use and rock-solid stability. It can be used as a practice tool, com

Micah Wylde 81 Dec 29, 2022
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 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
Rust task runner and build tool.

cargo-make Rust task runner and build tool. Overview Installation Binary Release Usage Simple Example Tasks, Dependencies and Aliases Commands, Script

Sagie Gur-Ari 1.8k Jan 7, 2023
ears is a simple library to play Sounds and Musics in Rust

ears 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 s

Jeremy Letang 56 Dec 1, 2022
DSP real time audio synthesis, effect algorithms and utilities for Rust

synfx-dsp synfx-dsp DSP real time audio synthesis, effect algorithms and utilities for Rust Most of the algorithms and implementations in this library

Weird Constructor 8 Nov 23, 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
Rust-crate with functions and helpers for working with music / audio, inspired by computer music languages.

music-math This crate contains common functions and helpers for working with music / audio in Rust. Most of these are inspired by similar functions fo

Mads Kjeldgaard 3 Apr 10, 2024
Program to check if stereo wav files have identical channels (faux-stereo) and convert them to mono.

zrtstr Command line application for checking WAV-files for identical channels, detecting faux-stereo files generated by some audio-editing software an

Kirill 22 Nov 6, 2022